From 671af72bf31ba3d504c3efb47e19cbcbce96f6fa Mon Sep 17 00:00:00 2001 From: PedroTroller Date: Mon, 25 Sep 2023 12:07:28 +0200 Subject: [PATCH] chore: update coding-standards --- bin/Utils.php | 2 +- bin/doc | 12 ++++++------ composer.json | 2 +- .../OrderedWithGetterAndSetterFirstFixer.php | 4 ++-- .../Fixer/Comment/CommentLineToPhpdocBlockFixer.php | 2 +- .../Fixer/DeadCode/UselessCodeAfterReturnFixer.php | 2 +- src/PedroTroller/CS/Fixer/Fixers.php | 2 +- src/PedroTroller/CS/Fixer/Priority.php | 8 +++----- src/PedroTroller/CS/Fixer/RuleSetFactory.php | 10 +++++----- src/PedroTroller/CS/Fixer/TokenSignatures.php | 4 +--- tests/Runner.php | 4 ++-- tests/TokensAnalyzerIntegration/MethodArguments.php | 2 +- 12 files changed, 25 insertions(+), 29 deletions(-) diff --git a/bin/Utils.php b/bin/Utils.php index 871d946..913820e 100644 --- a/bin/Utils.php +++ b/bin/Utils.php @@ -15,7 +15,7 @@ public static function arrayToString(array $array = null) if (array_values($array) === $array) { $string .= implode(', ', array_map([self::class, 'valueToString'], $array)); } else { - $string .= implode(', ', array_map(fn ($value, $key) => '\''.$key.'\' => '.self::valueToString($value), $array, array_keys($array))); + $string .= implode(', ', array_map(static fn ($value, $key) => '\''.$key.'\' => '.self::valueToString($value), $array, array_keys($array))); } $string .= ' ]'; diff --git a/bin/doc b/bin/doc index 2a9eb34..09dd9df 100755 --- a/bin/doc +++ b/bin/doc @@ -14,7 +14,7 @@ include sprintf('%s/../vendor/autoload.php', __DIR__); include 'Utils.php'; -$fixers = array_map(function (AbstractFixer $fixer) { +$fixers = array_map(static function (AbstractFixer $fixer) { $samples = $fixer->getDefinition()->getCodeSamples(); return [ @@ -25,7 +25,7 @@ $fixers = array_map(function (AbstractFixer $fixer) { 'deprecated' => $fixer->isDeprecated(), 'replacement' => $fixer->getDeprecationReplacement(), 'options' => array_map( - function (FixerOptionInterface $option) { + static function (FixerOptionInterface $option) { return [ 'name' => $option->getName(), 'description' => $option->getDescription(), @@ -39,7 +39,7 @@ $fixers = array_map(function (AbstractFixer $fixer) { ? $fixer->getConfigurationDefinition()->getOptions() : [] ), - 'samples' => array_map(function (CodeSample $sample) use ($fixer) { + 'samples' => array_map(static function (CodeSample $sample) use ($fixer) { if ($fixer instanceof ConfigurableFixerInterface) { $fixer->configure($sample->getConfiguration()); } @@ -57,13 +57,13 @@ $fixers = array_map(function (AbstractFixer $fixer) { } while (strlen($line) < 80 + 1) { - $line = $line.' '; + $line .= ' '; } if (0 === $num) { - $line = $line.'// 80 chars'; + $line .= '// 80 chars'; } else { - $line = $line.'//'; + $line .= '//'; } $diff[$num] = $line; diff --git a/composer.json b/composer.json index af442f9..6815fc0 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "php": "^8.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.17", + "friendsofphp/php-cs-fixer": "^3.28", "phpspec/phpspec": "^7.0", "sebastian/diff": "^4.0", "twig/twig": "^3.3", diff --git a/src/PedroTroller/CS/Fixer/ClassNotation/OrderedWithGetterAndSetterFirstFixer.php b/src/PedroTroller/CS/Fixer/ClassNotation/OrderedWithGetterAndSetterFirstFixer.php index 487f44e..10552ea 100644 --- a/src/PedroTroller/CS/Fixer/ClassNotation/OrderedWithGetterAndSetterFirstFixer.php +++ b/src/PedroTroller/CS/Fixer/ClassNotation/OrderedWithGetterAndSetterFirstFixer.php @@ -164,8 +164,8 @@ private function getMethodsNames(array $elements): array private function getPropertiesNames(array $elements): array { - $properties = array_filter($elements, fn ($element) => 'property' === $element['type']); + $properties = array_filter($elements, static fn ($element) => 'property' === $element['type']); - return array_map(fn ($element) => ltrim($element['propertyName'], '$'), $properties); + return array_map(static fn ($element) => ltrim($element['propertyName'], '$'), $properties); } } diff --git a/src/PedroTroller/CS/Fixer/Comment/CommentLineToPhpdocBlockFixer.php b/src/PedroTroller/CS/Fixer/Comment/CommentLineToPhpdocBlockFixer.php index 8407552..5e0cf3a 100644 --- a/src/PedroTroller/CS/Fixer/Comment/CommentLineToPhpdocBlockFixer.php +++ b/src/PedroTroller/CS/Fixer/Comment/CommentLineToPhpdocBlockFixer.php @@ -148,7 +148,7 @@ private function formatComments(array $comments, string $indentation): string array_pop($comments); } - $comments = array_map(fn ($comment) => rtrim($indentation.' * '.ltrim($comment, ' /')), $comments); + $comments = array_map(static fn ($comment) => rtrim($indentation.' * '.ltrim($comment, ' /')), $comments); $comments = implode("\n", $comments); $comments = trim($comments, " \n"); diff --git a/src/PedroTroller/CS/Fixer/DeadCode/UselessCodeAfterReturnFixer.php b/src/PedroTroller/CS/Fixer/DeadCode/UselessCodeAfterReturnFixer.php index d68461f..4b6d20a 100644 --- a/src/PedroTroller/CS/Fixer/DeadCode/UselessCodeAfterReturnFixer.php +++ b/src/PedroTroller/CS/Fixer/DeadCode/UselessCodeAfterReturnFixer.php @@ -83,7 +83,7 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens): void $possible = array_merge($possible, array_keys($ends)); } - $possible = array_filter($possible, fn ($value) => null !== $value); + $possible = array_filter($possible, static fn ($value) => null !== $value); if (empty($possible)) { continue; diff --git a/src/PedroTroller/CS/Fixer/Fixers.php b/src/PedroTroller/CS/Fixer/Fixers.php index 3f16380..aeac81f 100644 --- a/src/PedroTroller/CS/Fixer/Fixers.php +++ b/src/PedroTroller/CS/Fixer/Fixers.php @@ -23,7 +23,7 @@ public function getIterator(): Generator ; $files = array_map( - fn ($file) => $file->getPathname(), + static fn ($file) => $file->getPathname(), iterator_to_array($finder) ); diff --git a/src/PedroTroller/CS/Fixer/Priority.php b/src/PedroTroller/CS/Fixer/Priority.php index 6d6d5ae..005fe98 100644 --- a/src/PedroTroller/CS/Fixer/Priority.php +++ b/src/PedroTroller/CS/Fixer/Priority.php @@ -6,9 +6,7 @@ final class Priority { - private function __construct() - { - } + private function __construct() {} /** * @param array $classes @@ -18,7 +16,7 @@ private function __construct() public static function before(...$classes) { $priorities = array_map( - fn ($class) => (new $class())->getPriority(), + static fn ($class) => (new $class())->getPriority(), $classes ); @@ -33,7 +31,7 @@ public static function before(...$classes) public static function after(...$classes) { $priorities = array_map( - fn ($class) => (new $class())->getPriority(), + static fn ($class) => (new $class())->getPriority(), $classes ); diff --git a/src/PedroTroller/CS/Fixer/RuleSetFactory.php b/src/PedroTroller/CS/Fixer/RuleSetFactory.php index 66b5f52..1145cc9 100644 --- a/src/PedroTroller/CS/Fixer/RuleSetFactory.php +++ b/src/PedroTroller/CS/Fixer/RuleSetFactory.php @@ -237,7 +237,7 @@ private function migration($package, $version, $risky) $rules = (new RuleSets())->getSetDefinitionNames(); $rules = array_combine($rules, $rules); - $rules = array_map(function ($name) { + $rules = array_map(static function ($name) { preg_match('/^@([A-Za-z]+)(\d+)Migration(:risky|)$/', $name, $matches); return $matches; @@ -245,19 +245,19 @@ private function migration($package, $version, $risky) $rules = array_filter($rules); - $rules = array_filter($rules, function ($versionAndRisky) use ($package) { + $rules = array_filter($rules, static function ($versionAndRisky) use ($package) { [$rule, $rulePackage, $ruleVersion, $ruleRisky] = $versionAndRisky; return strtoupper($package) === strtoupper($rulePackage); }); - $rules = array_filter($rules, function ($versionAndRisky) use ($version) { + $rules = array_filter($rules, static function ($versionAndRisky) use ($version) { [$rule, $rulePackage, $ruleVersion, $ruleRisky] = $versionAndRisky; return ((float) $ruleVersion / 10) <= $version; }); - $rules = array_filter($rules, function ($versionAndRisky) use ($risky) { + $rules = array_filter($rules, static function ($versionAndRisky) use ($risky) { [$rule, $rulePackage, $ruleVersion, $ruleRisky] = $versionAndRisky; if ($risky) { @@ -269,7 +269,7 @@ private function migration($package, $version, $risky) return self::create(array_merge( $this->rules, - array_map(fn () => true, $rules) + array_map(static fn () => true, $rules) )); } } diff --git a/src/PedroTroller/CS/Fixer/TokenSignatures.php b/src/PedroTroller/CS/Fixer/TokenSignatures.php index 06ad2b6..3e535d2 100644 --- a/src/PedroTroller/CS/Fixer/TokenSignatures.php +++ b/src/PedroTroller/CS/Fixer/TokenSignatures.php @@ -9,7 +9,5 @@ final class TokenSignatures public const TYPINT_OPTIONAL = 10022; public const TYPINT_DOUBLE_DOTS = 10025; - public function __construct() - { - } + public function __construct() {} } diff --git a/tests/Runner.php b/tests/Runner.php index 66f70ff..e8da806 100644 --- a/tests/Runner.php +++ b/tests/Runner.php @@ -18,7 +18,7 @@ public static function run(): void $deprecations = []; set_error_handler( - function ($type, $message, $file, $line) use (&$deprecations): void { + static function ($type, $message, $file, $line) use (&$deprecations): void { $deprecations[$message][] = sprintf('%s at line %d', $file, $line); $deprecations[$message] = array_unique($deprecations[$message]); @@ -40,7 +40,7 @@ function ($type, $message, $file, $line) use (&$deprecations): void { implode( "\n\n", array_map( - fn ($message, array $files) => sprintf("%s\n%s", $message, implode("\n", $files)), + static fn ($message, array $files) => sprintf("%s\n%s", $message, implode("\n", $files)), array_keys($deprecations), $deprecations ) diff --git a/tests/TokensAnalyzerIntegration/MethodArguments.php b/tests/TokensAnalyzerIntegration/MethodArguments.php index d379637..c307cbe 100644 --- a/tests/TokensAnalyzerIntegration/MethodArguments.php +++ b/tests/TokensAnalyzerIntegration/MethodArguments.php @@ -49,7 +49,7 @@ public function assertions(TokensAnalyzer $analyzer, Tokens $tokens): void { $methods = array_filter( $analyzer->getClassyElements(), - fn ($element) => 'method' === $element['type'] + static fn ($element) => 'method' === $element['type'] ); Assert::count($methods, 3);