Skip to content

Commit

Permalink
PER-CS2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sreichel committed Dec 12, 2024
1 parent 80d5f14 commit 0d36c26
Show file tree
Hide file tree
Showing 224 changed files with 754 additions and 722 deletions.
7 changes: 7 additions & 0 deletions .ddev/commands/web/php-cs-fixer
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

## Description: run PHP-CS-Fixer
## Usage: php-cs-fixer
## Example: ddev php-cs-fixer <path-to-files>

php vendor/bin/php-cs-fixer fix "$@"
35 changes: 25 additions & 10 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
<?php

use PhpCsFixer\Config;
use PhpCsFixer\Finder;
declare(strict_types=1);

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

return (new Config())
$config = new PhpCsFixer\Config();
return $config
->setRiskyAllowed(true)
->setFinder($finder)
->setRules([
'array_syntax' => ['syntax' => 'short'],
'modernize_types_casting' => true,
// see https://cs.symfony.com/doc/ruleSets/PER-CS2.0.html
'@PER-CS2.0' => true,
// RISKY: Use && and || logical operators instead of and or.
'logical_operators' => true,
// RISKY: Replaces intval, floatval, doubleval, strval and boolval function calls with according type casting operator.
'modernize_types_casting' => true,
// PHP84: Adds or removes ? before single type declarations or |null at the end of union types when parameters have a default null value.
'nullable_type_declaration_for_default_null_value' => true,
// Convert double quotes to single quotes for simple strings.
'single_quote' => true,
]);
// Arguments lists, array destructuring lists, arrays that are multi-line, match-lines and parameters lists must have a trailing comma.
// removed "match" and "parameters" for PHP7
// see https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/8308
'trailing_comma_in_multiline' => ['after_heredoc' => true, 'elements' => ['arguments', 'array_destructuring', 'arrays']],
])
->setFinder(
PhpCsFixer\Finder::create()
->in([
__DIR__,
])
->name('*.php')
->ignoreDotFiles(true)
->ignoreVCS(true)
);
4 changes: 2 additions & 2 deletions build/phar/_cli_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
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,
''
' suhosin.executor.include.whitelist = phar ' . $suhosin,
'',
]));
exit(1);
}
Expand Down
4 changes: 2 additions & 2 deletions build/phar/phar-timestamp.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
$threshold = 1343826993; # 2012-08-01T15:14:33Z
if ($timestamp < $threshold) {
throw new RuntimeException(
sprintf('Timestamp older than %d (%s).', $threshold, date(DATE_RFC3339, $threshold))
sprintf('Timestamp older than %d (%s).', $threshold, date(DATE_RFC3339, $threshold)),
);
}

Expand All @@ -43,7 +43,7 @@

if (!rename($pharFilepath, $tmp)) {
throw new RuntimeException(
sprintf('Failed to move phar %s to %s', var_export($pharFilepath, true), var_export($tmp, true))
sprintf('Failed to move phar %s to %s', var_export($pharFilepath, true), var_export($tmp, true)),
);
}

Expand Down
17 changes: 9 additions & 8 deletions build/phar/tasks/PatchedPharPackageTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
* @since 2.4.0
* @see PharPackageTask
*/
class PatchedPharPackageTask
extends MatchingTask
class PatchedPharPackageTask extends MatchingTask
{
/**
* @var PhingFile
Expand Down Expand Up @@ -270,7 +269,7 @@ public function main()
try {
$this->log(
'Building package: ' . $this->destinationFile->__toString(),
Project::MSG_INFO
Project::MSG_INFO,
);

$baseDirectory = realpath($this->baseDirectory->getPath());
Expand All @@ -285,7 +284,7 @@ public function main()
throw new BuildException(
'Problem creating package: ' . $e->getMessage(),
$e,
$this->getLocation()
$this->getLocation(),
);
}
}
Expand All @@ -297,7 +296,7 @@ private function checkPreconditions()
{
if (!extension_loaded('phar')) {
throw new BuildException(
"PharPackageTask require either PHP 5.3 or better or the PECL's Phar extension"
"PharPackageTask require either PHP 5.3 or better or the PECL's Phar extension",
);
}

Expand All @@ -315,15 +314,17 @@ private function checkPreconditions()
if (!is_null($this->baseDirectory)) {
if (!$this->baseDirectory->exists()) {
throw new BuildException(
"basedir '" . (string) $this->baseDirectory . "' does not exist!", $this->getLocation()
"basedir '" . (string) $this->baseDirectory . "' does not exist!",
$this->getLocation(),
);
}
}
if ($this->signatureAlgorithm == Phar::OPENSSL) {

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(),
);
}

Expand Down Expand Up @@ -429,7 +430,7 @@ private function compressEachFile(Phar $phar, $baseDirectory)
foreach ($this->filesets as $fileset) {
$this->log(
'Adding specified files in ' . $fileset->getDir($this->project) . ' to package',
Project::MSG_VERBOSE
Project::MSG_VERBOSE,
);

$sortedFiles = $this->getSortedFilesFromFileSet($fileset);
Expand Down
16 changes: 16 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,21 @@
"php": "7.4.0"
},
"sort-packages": true
},
"scripts": {
"php-cs-fixer:test": "vendor/bin/php-cs-fixer fix --dry-run --diff",
"php-cs-fixer:fix": "vendor/bin/php-cs-fixer fix",
"phpstan": "XDEBUG_MODE=off php vendor/bin/phpstan analyze",
"phpstan:baseline": "XDEBUG_MODE=off php vendor/bin/phpstan analyze -b .phpstan.dist.baseline.neon",
"rector:test": "vendor/bin/rector process --config .rector.php --dry-run",
"rector:fix": "vendor/bin/rector --config .rector.php process"
},
"scripts-descriptions": {
"php-cs-fixer:test": "Run php-cs-fixer",
"php-cs-fixer:fix": "Run php-cs-fixer and fix issues",
"phpstan": "Run phpstan",
"phpstan:baseline": "Run phpstan and update baseline",
"rector:test": "Run rector",
"rector:fix": "Run rector and fix issues"
}
}
14 changes: 7 additions & 7 deletions src/N98/Magento/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ protected function getDefaultInputDefinition(): InputDefinition
'--root-dir',
'',
InputOption::VALUE_OPTIONAL,
'Force magento root dir. No auto detection'
'Force magento root dir. No auto detection',
);
$inputDefinition->addOption($rootDirOption);

Expand All @@ -148,7 +148,7 @@ protected function getDefaultInputDefinition(): InputDefinition
'--skip-config',
'',
InputOption::VALUE_NONE,
'Do not load any custom config.'
'Do not load any custom config.',
);
$inputDefinition->addOption($skipExternalConfig);

Expand All @@ -159,7 +159,7 @@ protected function getDefaultInputDefinition(): InputDefinition
'--skip-root-check',
'',
InputOption::VALUE_NONE,
'Do not check if n98-magerun runs as root'
'Do not check if n98-magerun runs as root',
);
$inputDefinition->addOption($skipExternalConfig);

Expand All @@ -170,7 +170,7 @@ protected function getDefaultInputDefinition(): InputDefinition
'--developer-mode',
'',
InputOption::VALUE_NONE,
'Instantiate Magento in Developer Mode'
'Instantiate Magento in Developer Mode',
);
$inputDefinition->addOption($rootDirOption);

Expand Down Expand Up @@ -231,7 +231,7 @@ protected function registerHelpers(): void
foreach ($config['helpers'] as $helperName => $helperClass) {
if (!class_exists($helperClass)) {
throw new RuntimeException(
sprintf('Nonexistent helper class: "%s", check helpers configuration', $helperClass)
sprintf('Nonexistent helper class: "%s", check helpers configuration', $helperClass),
);
}

Expand Down Expand Up @@ -524,7 +524,7 @@ public function run(?InputInterface $input = null, ?OutputInterface $output = nu
return $return;
}

private function init(array $initConfig = [], ?InputInterface $input = null, ?OutputInterface $output = null): void
public function init(array $initConfig = [], ?InputInterface $input = null, ?OutputInterface $output = null): void
{
if ($this->_isInitialized) {
return;
Expand Down Expand Up @@ -596,7 +596,7 @@ protected function _checkSkipConfigOption(InputInterface $input): bool
{
trigger_error(
__METHOD__ . ' removed, use $input->hasParameterOption(\'--skip-config\') instead',
E_USER_DEPRECATED
E_USER_DEPRECATED,
);

return $input->hasParameterOption('--skip-config');
Expand Down
20 changes: 10 additions & 10 deletions src/N98/Magento/Application/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Config

private OutputInterface $output;

public function __construct(array $initConfig = [], bool $isPharMode = false, OutputInterface $output = null)
public function __construct(array $initConfig = [], bool $isPharMode = false, ?OutputInterface $output = null)
{
$this->initConfig = $initConfig;
$this->isPharMode = (bool) $isPharMode;
Expand All @@ -71,7 +71,7 @@ public function checkConfigCommandAlias(InputInterface $input)

$aliasCommandParams = array_slice(
BinaryString::trimExplodeEmpty(' ', $alias[$aliasCommandName]),
1
1,
);
if ([] === $aliasCommandParams) {
continue;
Expand All @@ -82,7 +82,7 @@ public function checkConfigCommandAlias(InputInterface $input)
$newArgv = array_merge(
array_slice($oldArgv, 0, 2),
$aliasCommandParams,
array_slice($oldArgv, 2)
array_slice($oldArgv, 2),
);
$input = new ArgvInput($newArgv);
}
Expand Down Expand Up @@ -123,20 +123,20 @@ public function registerCustomCommands(Application $application): void
$this->output->writeln(
sprintf(
'<error>Can not add nonexistent command class "%s" as command to the application</error>',
$commandClass
)
$commandClass,
),
);
$this->debugWriteln(
'Please check the configuration files contain the correct class-name. If the ' .
'class-name is correct, check autoloader configurations.'
'class-name is correct, check autoloader configurations.',
);
} else {
$this->debugWriteln(
sprintf(
'<debug>Add command </debug> <info>%s</info> -> <comment>%s</comment>',
$command->getName(),
get_class($command)
)
get_class($command),
),
);
$application->add($command);
}
Expand All @@ -151,7 +151,7 @@ private function newCommand($className, ?string $commandName): ?Command
{
if (!is_string($className) && !is_object($className)) {
throw new InvalidArgumentException(
sprintf('Command classname must be string, %s given', gettype($className))
sprintf('Command classname must be string, %s given', gettype($className)),
);
}

Expand All @@ -162,7 +162,7 @@ private function newCommand($className, ?string $commandName): ?Command
if (false === is_subclass_of($className, self::COMMAND_CLASS, true)) {
$className = is_object($className) ? get_class($className) : $className;
throw new InvalidArgumentException(
sprintf('Class "%s" is not a Command (subclass of "%s")', $className, self::COMMAND_CLASS)
sprintf('Class "%s" is not a Command (subclass of "%s")', $className, self::COMMAND_CLASS),
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/N98/Magento/Application/ConfigurationLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private function traversePluginFoldersForConfigFile(string $magentoRootFolder, $
/**
* Check if there is a user config file. ~/.n98-magerun.yaml
*/
public function loadUserConfig(array $config, string $magentoRootFolder = null): array
public function loadUserConfig(array $config, ?string $magentoRootFolder = null): array
{
if (is_null($this->_userConfig)) {
$this->_userConfig = [];
Expand Down
Loading

0 comments on commit 0d36c26

Please sign in to comment.