Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added php-cs-fixer to workflow #1455

Merged
merged 2 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: PHP-CS-Fixer

on:
push:
pull_request:
workflow_call:
# Allow manually triggering the workflow.
workflow_dispatch:

jobs:
php-cs-fixer:
name: Validation
runs-on: [ubuntu-latest]

steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4

- name: Checkout code
uses: actions/checkout@v4

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --prefer-dist --no-progress --ignore-platform-req=ext-*

- name: PHP-CS-Fixer
run: php vendor/bin/php-cs-fixer fix --diff --dry-run
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ act.secrets

# phpDocumentor
/docs/

# php-cs-fixer cache
/.php-cs-fixer.cache
17 changes: 17 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

use PhpCsFixer\Config;
use PhpCsFixer\Finder;

$finder = (new Finder())
->in('.');

return (new Config())
->setRiskyAllowed(true)
->setFinder($finder)
->setRules([
'array_syntax' => ['syntax' => 'short'],
'modernize_types_casting' => true,
'logical_operators' => true,
'single_quote' => true,
]);
10 changes: 5 additions & 5 deletions build/bin/files.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
}
$basename = $basename ?: 'n98-magerun';

$urls = strtr($urls, array('%basename%' => $basename));
$urls = strtr($urls, ['%basename%' => $basename]);

$urlHeaders = function ($url) {
return function ($name = null) use ($url) {
Expand All @@ -45,9 +45,9 @@

$box = function ($title) {
$len = strlen($title);
$buffer = str_repeat("=", $len + 4);
$buffer = str_repeat('=', $len + 4);
$buffer .= "\n= $title =\n";
$buffer .= str_repeat("=", $len + 4);
$buffer .= str_repeat('=', $len + 4);

return $buffer . "\n";
};
Expand All @@ -60,7 +60,7 @@

$main = function ($urls) use ($urlHeaders, $box, $bytes) {
foreach ($urls as $url) {
$title = sprintf("%s: %s", $url->channel, $url->url);
$title = sprintf('%s: %s', $url->channel, $url->url);
echo $box($title);

$headers = $urlHeaders($url->url);
Expand All @@ -71,7 +71,7 @@
echo "\n";
}

echo $box("Verify Phar-Files Versions");
echo $box('Verify Phar-Files Versions');

foreach ($urls as $url) {
$tempFile = '.magerun-phar.~dl-temp-' . md5($url->url);
Expand Down
4 changes: 2 additions & 2 deletions build/phar/_cli_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
$suhosin = ini_get('suhosin.executor.include.whitelist');
$suhosinBlacklist = ini_get('suhosin.executor.include.blacklist');
if (false === stripos($suhosin, 'phar') && (!$suhosinBlacklist || false !== stripos($suhosinBlacklist, 'phar'))) {
fwrite(STDERR, implode(PHP_EOL, array(
fwrite(STDERR, implode(PHP_EOL, [
'The suhosin.executor.include.whitelist setting is incorrect.',
'Add the following to the end of your `php.ini` or suhosin.ini (Example path [for Debian]: /etc/php5/cli/conf.d/suhosin.ini):',
' suhosin.executor.include.whitelist = phar '.$suhosin,
''
)));
]));
exit(1);
}
}
Expand Down
2 changes: 1 addition & 1 deletion build/phar/phar-timestamp.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
$timestamps->updateTimestamps($timestamp);
$timestamps->save($pharFilepath, Phar::SHA512);

echo "SHA1.....: ", sha1_file($pharFilepath), "\nMD5......: ", md5_file($pharFilepath), "\n";
echo 'SHA1.....: ', sha1_file($pharFilepath), "\nMD5......: ", md5_file($pharFilepath), "\n";

if (!unlink($tmp)) {
throw new RuntimeException('Error deleting tempfile %s', var_export($tmp, true));
Expand Down
30 changes: 15 additions & 15 deletions build/phar/tasks/PatchedPharPackageTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class PatchedPharPackageTask
/**
* @var array
*/
private $filesets = array();
private $filesets = [];

/**
* @var PharMetadata
Expand Down Expand Up @@ -167,13 +167,13 @@ private function getCompressionLabel()

switch ($compression) {
case Phar::GZ:
return "gzip";
return 'gzip';

case Phar::BZ2:
return "bzip2";
return 'bzip2';

default:
return sprintf("int(%d)", $compression);
return sprintf('int(%d)', $compression);
}
}

Expand Down Expand Up @@ -302,15 +302,15 @@ private function checkPreconditions()
}

if (is_null($this->destinationFile)) {
throw new BuildException("destfile attribute must be set!", $this->getLocation());
throw new BuildException('destfile attribute must be set!', $this->getLocation());
}

if ($this->destinationFile->exists() && $this->destinationFile->isDirectory()) {
throw new BuildException("destfile is a directory!", $this->getLocation());
throw new BuildException('destfile is a directory!', $this->getLocation());
}

if (!$this->destinationFile->canWrite()) {
throw new BuildException("Can not write to the specified destfile!", $this->getLocation());
throw new BuildException('Can not write to the specified destfile!', $this->getLocation());
}
if (!is_null($this->baseDirectory)) {
if (!$this->baseDirectory->exists()) {
Expand All @@ -323,12 +323,12 @@ private function checkPreconditions()

if (!extension_loaded('openssl')) {
throw new BuildException(
"PHP OpenSSL extension is required for OpenSSL signing of Phars!", $this->getLocation()
'PHP OpenSSL extension is required for OpenSSL signing of Phars!', $this->getLocation()
);
}

if (is_null($this->key)) {
throw new BuildException("key attribute must be set for OpenSSL signing!", $this->getLocation());
throw new BuildException('key attribute must be set for OpenSSL signing!', $this->getLocation());
}

if (!$this->key->exists()) {
Expand Down Expand Up @@ -436,7 +436,7 @@ private function compressEachFile(Phar $phar, $baseDirectory)
if (Phar::NONE != $this->compression) {
foreach ($sortedFiles as $file) {
$localName = substr($file, strlen($baseDirectory) + 1);
$this->log($localName . "... ", Project::MSG_VERBOSE);
$this->log($localName . '... ', Project::MSG_VERBOSE);
$phar->addFile($file, $localName);
$phar[$localName]->compress($this->compression);
}
Expand All @@ -461,7 +461,7 @@ private function compressAllFiles(Phar $phar, $baseDirectory)
foreach ($this->filesets as $fileset) {
/* @var $fileset IterableFileSet */
$dir = $fileset->getDir($this->project);
$msg = sprintf("Fileset %s ...", $dir);
$msg = sprintf('Fileset %s ...', $dir);
$this->log($msg, Project::MSG_VERBOSE);
$added = $phar->buildFromIterator($this->getSortedFilesFromFileSet($fileset), $baseDirectory);
$total += count($added);
Expand All @@ -473,14 +473,14 @@ private function compressAllFiles(Phar $phar, $baseDirectory)
return;
}

$msg = sprintf("Compressing %d files (compression: %s) ... ", $total, $this->getCompressionLabel());
$msg = sprintf('Compressing %d files (compression: %s) ... ', $total, $this->getCompressionLabel());
$this->log($msg, Project::MSG_VERBOSE);

// safeguard open files soft limit
if (function_exists('posix_getrlimit')) {
$rlimit = posix_getrlimit();
if ($rlimit['soft openfiles'] < ($total + 5)) {
$msg = sprintf("Limit of openfiles (%d) is too low.", $rlimit['soft openfiles']);
$msg = sprintf('Limit of openfiles (%d) is too low.', $rlimit['soft openfiles']);
$this->log($msg, Project::MSG_VERBOSE);
}
}
Expand All @@ -490,7 +490,7 @@ private function compressAllFiles(Phar $phar, $baseDirectory)
$phar->compressFiles($this->compression);
} catch (BadMethodCallException $e) {
if ($e->getMessage() === 'unable to create temporary file') {
$msg = sprintf("Info: Check openfiles limit it must be %d or higher", $total + 5);
$msg = sprintf('Info: Check openfiles limit it must be %d or higher', $total + 5);
throw new BadMethodCallException($msg, 0, $e);
}
throw $e;
Expand All @@ -507,7 +507,7 @@ private function getSortedFilesFromFileSet(IterableFileSet $fileset)
{
$files = iterator_to_array($fileset, true);
$keys = array_keys($files);
usort($files, array($this, 'sortFilesCallback'));
usort($files, [$this, 'sortFilesCallback']);
$array = array_combine($keys, $files);

return new ArrayIterator($array);
Expand Down
2 changes: 1 addition & 1 deletion res/dev/console_auto_prepend.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
WELCOME;
echo PHP_EOL . PHP_EOL . 'Initialized Magento (' . \Mage::getVersion() . ')' . PHP_EOL . PHP_EOL;
} else {
echo "FATAL: Magento could not be initialized." . PHP_EOL;
echo 'FATAL: Magento could not be initialized.' . PHP_EOL;
}
2 changes: 1 addition & 1 deletion src/N98/Magento/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ public function checkVarDir(OutputInterface $output)
'can cause serious problems.', 'Please refer to https://github.com/netz98/n98-magerun/wiki/File-system-permissions ' .
'for more information.', '']);
} else {
$output->writeln([sprintf('<warning>Folder %s found, but not used in n98-magerun</warning>', $tempVarDir), '', "This might cause serious problems. n98-magerun is using the configured var-folder " .
$output->writeln([sprintf('<warning>Folder %s found, but not used in n98-magerun</warning>', $tempVarDir), '', 'This might cause serious problems. n98-magerun is using the configured var-folder ' .
"<comment>$currentVarDir</comment>", 'Please refer to https://github.com/netz98/n98-magerun/wiki/File-system-permissions ' .
'for more information.', '']);

Expand Down
4 changes: 2 additions & 2 deletions src/N98/Magento/Application/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,13 @@ public function registerCustomAutoloaders(ClassLoader $autoloader)

foreach ($this->getArray('autoloaders') as $prefix => $paths) {
$paths = (array) $paths;
$this->debugWriteln(sprintf($mask, self::PSR_0, OutputFormatter::escape($prefix), implode(",", $paths)));
$this->debugWriteln(sprintf($mask, self::PSR_0, OutputFormatter::escape($prefix), implode(',', $paths)));
$autoloader->add($prefix, $paths);
}

foreach ($this->getArray('autoloaders_psr4') as $prefix => $paths) {
$paths = (array) $paths;
$this->debugWriteln(sprintf($mask, self::PSR_4, OutputFormatter::escape($prefix), implode(",", $paths)));
$this->debugWriteln(sprintf($mask, self::PSR_4, OutputFormatter::escape($prefix), implode(',', $paths)));
$autoloader->addPsr4($prefix, $paths);
}
}
Expand Down
28 changes: 14 additions & 14 deletions src/N98/Magento/Command/Category/Create/DummyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class DummyCommand extends AbstractMagentoCommand
{
public const DEFAULT_CATEGORY_NAME = "My Awesome Category";
public const DEFAULT_CATEGORY_NAME = 'My Awesome Category';
public const DEFAULT_CATEGORY_STATUS = 1; // enabled
public const DEFAULT_CATEGORY_ANCHOR = 1; // enabled
public const DEFAULT_STORE_ID = 1; // Default Store ID
Expand Down Expand Up @@ -55,7 +55,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->detectMagento($output, true);
$this->initMagento();

$output->writeln("<warning>This only create sample categories, do not use on production environment</warning>");
$output->writeln('<warning>This only create sample categories, do not use on production environment</warning>');

// Ask for Arguments
$_argument = $this->askForArguments($input, $output);
Expand All @@ -65,9 +65,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
*/
for ($i = 0; $i < $_argument['category-number']; $i++) {
if (!is_null($_argument['category-name-prefix'])) {
$name = $_argument['category-name-prefix'] . " " . $i;
$name = $_argument['category-name-prefix'] . ' ' . $i;
} else {
$name = self::DEFAULT_CATEGORY_NAME . " " . $i;
$name = self::DEFAULT_CATEGORY_NAME . ' ' . $i;
}

// Check if product exists
Expand Down Expand Up @@ -105,7 +105,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

// Create children Categories
for ($j = 0; $j < $_argument['children-categories-number']; $j++) {
$name_child = $name . " child " . $j;
$name_child = $name . ' child ' . $j;

/* @var Mage_Catalog_Model_Category $category */
$category = Mage::getModel('catalog/category');
Expand Down Expand Up @@ -151,20 +151,20 @@ private function askForArguments($input, $output)
$_store_ids = [];

foreach ($store_id as $item) {
$_store_ids[$item['store_id']] = $item['store_id'] . "|" . $item['code'];
$_store_ids[$item['store_id']] = $item['store_id'] . '|' . $item['code'];
}

$question = new ChoiceQuestion('Please select Store ID (default: 1)', $_store_ids, self::DEFAULT_STORE_ID);
$question->setErrorMessage('Store ID "%s" is invalid.');
$response = explode("|", $dialog->ask($input, $output, $question));
$response = explode('|', $dialog->ask($input, $output, $question));
$input->setArgument('store-id', $response[0]);
}
$output->writeln('<info>Store ID selected: ' . $input->getArgument('store-id') . "</info>");
$output->writeln('<info>Store ID selected: ' . $input->getArgument('store-id') . '</info>');
$_argument['store-id'] = $input->getArgument('store-id');

// Number of Categories
if (is_null($input->getArgument('category-number'))) {
$question = new Question("Please enter the number of categories to create (default 1): ", 1);
$question = new Question('Please enter the number of categories to create (default 1): ', 1);
$question->setValidator(function ($answer) {
$answer = (int) $answer;
if (!is_int($answer) || $answer <= 0) {
Expand All @@ -176,7 +176,7 @@ private function askForArguments($input, $output)
$input->setArgument('category-number', $dialog->ask($input, $output, $question));
}
$output->writeln(
'<info>Number of categories to create: ' . $input->getArgument('category-number') . "</info>"
'<info>Number of categories to create: ' . $input->getArgument('category-number') . '</info>'
);
$_argument['category-number'] = $input->getArgument('category-number');

Expand All @@ -189,7 +189,7 @@ private function askForArguments($input, $output)
$question->setValidator(function ($answer) {
$answer = (int) $answer;
if (!is_int($answer) || $answer < -1) {
throw new RuntimeException("Please enter an integer value or >= -1");
throw new RuntimeException('Please enter an integer value or >= -1');
}

return $answer;
Expand All @@ -202,7 +202,7 @@ private function askForArguments($input, $output)

$output->writeln(
'<info>Number of categories children to create: ' . $input->getArgument('children-categories-number') .
"</info>"
'</info>'
);
$_argument['children-categories-number'] = $input->getArgument('children-categories-number');

Expand All @@ -214,7 +214,7 @@ private function askForArguments($input, $output)
);
$input->setArgument('category-name-prefix', $dialog->ask($input, $output, $question));
}
$output->writeln('<info>CATEGORY NAME PREFIX: ' . $input->getArgument('category-name-prefix') . "</info>");
$output->writeln('<info>CATEGORY NAME PREFIX: ' . $input->getArgument('category-name-prefix') . '</info>');
$_argument['category-name-prefix'] = $input->getArgument('category-name-prefix');

return $_argument;
Expand All @@ -228,7 +228,7 @@ private function askForArguments($input, $output)
*/
private function setCategoryStoreId(Mage_Catalog_Model_Category $category, $storeId)
{
if (Mage::getVersion() === "1.5.1.0") {
if (Mage::getVersion() === '1.5.1.0') {
$category->setStoreId([0, $storeId]);
} else {
$category->setStoreId($storeId);
Expand Down
Loading
Loading