From 46783e4b14fecdd130dec9c2848f3846c0f9ffee Mon Sep 17 00:00:00 2001 From: PedroTroller Date: Wed, 27 Apr 2022 10:38:18 +0200 Subject: [PATCH] feat: remove support of php 7.3, add test run for php 8.1 --- .circleci/config.yml | 42 ++++++++++++------- .php-cs-fixer.dist.php | 2 +- bin/Utils.php | 4 +- composer.json | 4 +- src/PedroTroller/CS/Fixer/AbstractFixer.php | 4 +- .../OrderedWithGetterAndSetterFirstFixer.php | 8 +--- .../Comment/CommentLineToPhpdocBlockFixer.php | 4 +- .../DeadCode/UselessCodeAfterReturnFixer.php | 2 +- src/PedroTroller/CS/Fixer/Fixers.php | 7 ++-- src/PedroTroller/CS/Fixer/Priority.php | 8 +--- src/PedroTroller/CS/Fixer/RuleSetFactory.php | 2 +- tests/Runner.php | 4 +- .../MethodArguments.php | 2 +- 13 files changed, 45 insertions(+), 48 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a38433d..e16fd37 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,11 +4,21 @@ version: 2.1 orbs: node: circleci/node@4.2.1 -composer_with_lowest_dependencies: &composer_with_lowest_dependencies +install_composer: &install_composer + run: | + apt-get update + apt-get -y install git zip + php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" + php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" + php composer-setup.php + php -r "unlink('composer-setup.php');" + mv composer.phar /usr/local/bin/composer + +composer_update_with_lowest_dependencies: &composer_update_with_lowest_dependencies run: | composer update --prefer-lowest --prefer-stable -composer: &composer +composer_update: &composer_update run: | composer update @@ -30,10 +40,11 @@ jobs: php-version: type: string docker: - - image: "circleci/php:<< parameters.php-version >>" + - image: "php:<< parameters.php-version >>" steps: - checkout - - <<: *composer + - <<: *install_composer + - <<: *composer_update - <<: *tests tests-with-future-mode: @@ -41,10 +52,11 @@ jobs: php-version: type: string docker: - - image: "circleci/php:<< parameters.php-version >>" + - image: "php:<< parameters.php-version >>" steps: - checkout - - <<: *composer + - <<: *install_composer + - <<: *composer_update - <<: *tests_with_future_mode tests-with-lowest-dependencies: @@ -52,10 +64,11 @@ jobs: php-version: type: string docker: - - image: "circleci/php:<< parameters.php-version >>" + - image: "php:<< parameters.php-version >>" steps: - checkout - - <<: *composer_with_lowest_dependencies + - <<: *install_composer + - <<: *composer_update_with_lowest_dependencies - <<: *tests documentation: @@ -63,10 +76,11 @@ jobs: php-version: type: string docker: - - image: "circleci/php:<< parameters.php-version >>" + - image: "php:<< parameters.php-version >>" steps: - checkout - - <<: *composer + - <<: *install_composer + - <<: *composer_update - run: bin/doc > README.new.md - run: cmp --silent README.md README.new.md || cmp README.md README.new.md || (echo "Documentation is outdated. Run 'bin/doc > README.md'" && exit 1) @@ -93,19 +107,19 @@ workflows: - documentation: matrix: parameters: - php-version: ["8.0"] + php-version: ["8.1"] - tests: matrix: parameters: - php-version: ["7.3", "7.4", "8.0"] + php-version: ["7.4", "8.0", "8.1"] - tests-with-future-mode: matrix: parameters: - php-version: ["7.3", "7.4", "8.0"] + php-version: ["7.4", "8.0", "8.1"] - tests-with-lowest-dependencies: matrix: parameters: - php-version: ["7.3", "7.4", "8.0"] + php-version: ["7.4", "8.0", "8.1"] - release-test - release: requires: diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index f5b453c..12b7c32 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -10,7 +10,7 @@ ->setRules( RuleSetFactory::create() ->phpCsFixer(true) - ->php(7.3, true) + ->php(7.4, true) ->pedrotroller(true) ->enable('ordered_imports') ->enable('ordered_interfaces') diff --git a/bin/Utils.php b/bin/Utils.php index 4a48063..d5dc6a2 100644 --- a/bin/Utils.php +++ b/bin/Utils.php @@ -15,9 +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(function ($value, $key) { - return '\''.$key.'\' => '.static::valueToString($value); - }, $array, array_keys($array))); + $string .= implode(', ', array_map(fn ($value, $key) => '\''.$key.'\' => '.static::valueToString($value), $array, array_keys($array))); } $string .= ' ]'; diff --git a/composer.json b/composer.json index dc059bc..9db60fd 100644 --- a/composer.json +++ b/composer.json @@ -3,8 +3,8 @@ "description": "PHP-CS-FIXER : my custom fixers", "license": "MIT", "require": { - "php": "^7.3 || ^8.0", - "friendsofphp/php-cs-fixer": "^3.0" + "php": "^7.4 || ^8.0", + "friendsofphp/php-cs-fixer": "^3.7" }, "require-dev": { "phpspec/phpspec": "^7.0", diff --git a/src/PedroTroller/CS/Fixer/AbstractFixer.php b/src/PedroTroller/CS/Fixer/AbstractFixer.php index 221d20b..549e599 100644 --- a/src/PedroTroller/CS/Fixer/AbstractFixer.php +++ b/src/PedroTroller/CS/Fixer/AbstractFixer.php @@ -45,9 +45,7 @@ public function getDefinition(): FixerDefinitionInterface return new FixerDefinition( $this->getDocumentation(), array_map( - function (array $configutation = null) { - return new CodeSample($this->getSampleCode(), $configutation); - }, + fn (array $configutation = null) => new CodeSample($this->getSampleCode(), $configutation), $this->getSampleConfigurations() ) ); diff --git a/src/PedroTroller/CS/Fixer/ClassNotation/OrderedWithGetterAndSetterFirstFixer.php b/src/PedroTroller/CS/Fixer/ClassNotation/OrderedWithGetterAndSetterFirstFixer.php index 9535b31..487f44e 100644 --- a/src/PedroTroller/CS/Fixer/ClassNotation/OrderedWithGetterAndSetterFirstFixer.php +++ b/src/PedroTroller/CS/Fixer/ClassNotation/OrderedWithGetterAndSetterFirstFixer.php @@ -164,12 +164,8 @@ private function getMethodsNames(array $elements): array private function getPropertiesNames(array $elements): array { - $properties = array_filter($elements, function ($element) { - return 'property' === $element['type']; - }); + $properties = array_filter($elements, fn ($element) => 'property' === $element['type']); - return array_map(function ($element) { - return ltrim($element['propertyName'], '$'); - }, $properties); + return array_map(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 e5b3a0a..8407552 100644 --- a/src/PedroTroller/CS/Fixer/Comment/CommentLineToPhpdocBlockFixer.php +++ b/src/PedroTroller/CS/Fixer/Comment/CommentLineToPhpdocBlockFixer.php @@ -148,9 +148,7 @@ private function formatComments(array $comments, string $indentation): string array_pop($comments); } - $comments = array_map(function ($comment) use ($indentation) { - return rtrim($indentation.' * '.ltrim($comment, ' /')); - }, $comments); + $comments = array_map(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 90e2a8b..d68461f 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, function ($value) { return null !== $value; }); + $possible = array_filter($possible, 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 b9e81e4..3f16380 100644 --- a/src/PedroTroller/CS/Fixer/Fixers.php +++ b/src/PedroTroller/CS/Fixer/Fixers.php @@ -4,6 +4,7 @@ namespace PedroTroller\CS\Fixer; +use Generator; use IteratorAggregate; use PhpCsFixer\Fixer\FixerInterface; use ReflectionClass; @@ -14,7 +15,7 @@ final class Fixers implements IteratorAggregate /** * {@inheritdoc} */ - public function getIterator(): \Generator + public function getIterator(): Generator { $finder = Finder::create() ->in(__DIR__) @@ -22,9 +23,7 @@ public function getIterator(): \Generator ; $files = array_map( - function ($file) { - return $file->getPathname(); - }, + 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 d6c160b..6d6d5ae 100644 --- a/src/PedroTroller/CS/Fixer/Priority.php +++ b/src/PedroTroller/CS/Fixer/Priority.php @@ -18,9 +18,7 @@ private function __construct() public static function before(...$classes) { $priorities = array_map( - function ($class) { - return (new $class())->getPriority(); - }, + fn ($class) => (new $class())->getPriority(), $classes ); @@ -35,9 +33,7 @@ function ($class) { public static function after(...$classes) { $priorities = array_map( - function ($class) { - return (new $class())->getPriority(); - }, + fn ($class) => (new $class())->getPriority(), $classes ); diff --git a/src/PedroTroller/CS/Fixer/RuleSetFactory.php b/src/PedroTroller/CS/Fixer/RuleSetFactory.php index f911104..5631a1f 100644 --- a/src/PedroTroller/CS/Fixer/RuleSetFactory.php +++ b/src/PedroTroller/CS/Fixer/RuleSetFactory.php @@ -264,7 +264,7 @@ private function migration($package, $version, $risky) return self::create(array_merge( $this->rules, - array_map(function () { return true; }, $rules) + array_map(fn () => true, $rules) )); } } diff --git a/tests/Runner.php b/tests/Runner.php index 9ceefed..24c9a85 100644 --- a/tests/Runner.php +++ b/tests/Runner.php @@ -40,9 +40,7 @@ function ($type, $message, $file, $line) use (&$deprecations): void { implode( "\n\n", array_map( - function ($message, array $files) { - return sprintf("%s\n%s", $message, implode("\n", $files)); - }, + 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 0bc0ae6..d379637 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(), - function ($element) { return 'method' === $element['type']; } + fn ($element) => 'method' === $element['type'] ); Assert::count($methods, 3);