From ae39c1da77ca1407effbba5a32acf9a02bb2f318 Mon Sep 17 00:00:00 2001 From: PedroTroller Date: Fri, 2 Aug 2024 10:52:16 +0200 Subject: [PATCH] refactor: apply new coding standards --- .circleci/config.yml | 18 +++++++++++---- .php-cs-fixer.dist.php | 8 ++++--- bin/Utils.php | 2 +- bin/doc | 5 +++- composer.json | 23 +++++++++++-------- src/PedroTroller/CS/Fixer/AbstractFixer.php | 2 +- src/PedroTroller/CS/Fixer/RuleSetFactory.php | 4 ++-- .../MethodArguments.php | 2 +- 8 files changed, 41 insertions(+), 23 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f85604b..6e46a7b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -106,19 +106,29 @@ workflows: - documentation: matrix: parameters: - php-version: ["8.2"] + php-version: + - "8.3" - tests: matrix: parameters: - php-version: ["8.0", "8.1", "8.2"] + php-version: + - "8.1" + - "8.2" + - "8.3" - tests-with-future-mode: matrix: parameters: - php-version: ["8.0", "8.1", "8.2"] + php-version: + - "8.1" + - "8.2" + - "8.3" - tests-with-lowest-dependencies: matrix: parameters: - php-version: ["8.0", "8.1", "8.2"] + php-version: + - "8.1" + - "8.2" + - "8.3" - release-test - release: requires: diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index fdb4fa6..c1ab6a4 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -4,14 +4,16 @@ use PedroTroller\CS\Fixer\Fixers; use PedroTroller\CS\Fixer\RuleSetFactory; +use PhpCsFixer\Config; +use PhpCsFixer\Finder; -return (new PhpCsFixer\Config()) +return (new Config()) ->setRiskyAllowed(true) ->setRules( RuleSetFactory::create() ->per(2, true) ->phpCsFixer(true) - ->php(8.0, true) + ->php(8.1, true) ->pedrotroller(true) ->enable('align_multiline_comment') ->enable('array_indentation') @@ -34,7 +36,7 @@ ->setUsingCache(false) ->registerCustomFixers(new Fixers()) ->setFinder( - PhpCsFixer\Finder::create() + Finder::create() ->in(__DIR__) ->append([__FILE__, __DIR__.'/bin/doc']) ) diff --git a/bin/Utils.php b/bin/Utils.php index 913820e..b21abba 100644 --- a/bin/Utils.php +++ b/bin/Utils.php @@ -4,7 +4,7 @@ final class Utils { - public static function arrayToString(array $array = null) + public static function arrayToString(?array $array = null) { if (null === $array) { return; diff --git a/bin/doc b/bin/doc index 09dd9df..08fa01f 100755 --- a/bin/doc +++ b/bin/doc @@ -1,7 +1,10 @@ #!/usr/bin/env php 3.59.2" + }, + "minimum-stability": "dev", + "prefer-stable": true, "autoload": { "psr-4": { "PedroTroller\\CS\\Fixer\\": "src/PedroTroller/CS/Fixer" @@ -31,19 +36,17 @@ "dev-master": "3.x-dev" } }, - "minimum-stability": "dev", - "prefer-stable": true, "scripts": { - "tests": [ - "tests\\Runner::run", - "tests\\Orchestra::run", - "phpspec run -fpretty" + "lint": [ + "@php-cs-fixer" ], "php-cs-fixer": [ "php-cs-fixer fix --dry-run -vvv --diff" ], - "lint": [ - "@php-cs-fixer" + "tests": [ + "tests\\Runner::run", + "tests\\Orchestra::run", + "phpspec run -fpretty" ] } } diff --git a/src/PedroTroller/CS/Fixer/AbstractFixer.php b/src/PedroTroller/CS/Fixer/AbstractFixer.php index 549e599..d2d8b74 100644 --- a/src/PedroTroller/CS/Fixer/AbstractFixer.php +++ b/src/PedroTroller/CS/Fixer/AbstractFixer.php @@ -45,7 +45,7 @@ public function getDefinition(): FixerDefinitionInterface return new FixerDefinition( $this->getDocumentation(), array_map( - fn (array $configutation = null) => new CodeSample($this->getSampleCode(), $configutation), + fn (?array $configutation = null) => new CodeSample($this->getSampleCode(), $configutation), $this->getSampleConfigurations() ) ); diff --git a/src/PedroTroller/CS/Fixer/RuleSetFactory.php b/src/PedroTroller/CS/Fixer/RuleSetFactory.php index 6e75b76..dc2d0d9 100644 --- a/src/PedroTroller/CS/Fixer/RuleSetFactory.php +++ b/src/PedroTroller/CS/Fixer/RuleSetFactory.php @@ -55,7 +55,7 @@ public static function create(array $rules = []): self ); } - public function per(int|float $version = null, bool $risky = false): self + public function per(null|float|int $version = null, bool $risky = false): self { $candidates = null !== $version ? ['@PER-CS'.number_format($version, 1, '.', '')] @@ -198,7 +198,7 @@ public function pedrotroller(bool $risky = false): self )); } - public function enable(string $name, array $config = null): self + public function enable(string $name, ?array $config = null): self { return self::create(array_merge( $this->rules, diff --git a/tests/TokensAnalyzerIntegration/MethodArguments.php b/tests/TokensAnalyzerIntegration/MethodArguments.php index c307cbe..872a4a4 100644 --- a/tests/TokensAnalyzerIntegration/MethodArguments.php +++ b/tests/TokensAnalyzerIntegration/MethodArguments.php @@ -67,7 +67,7 @@ public function assertions(TokensAnalyzer $analyzer, Tokens $tokens): void $arguments, [ ($theFunction + 5) => [ - 'type' => 'Domain\\Model\\User', + 'type' => 'Domain\Model\User', 'name' => '$user', 'nullable' => false, 'asDefault' => false,