From a88f3148d09c358b020a710d973148c1e719f338 Mon Sep 17 00:00:00 2001 From: Benoit Jouhaud Date: Sun, 18 Aug 2024 17:51:27 +0200 Subject: [PATCH] Replace squizlabs/php_codesniffer by symplify/easy-coding-standard --- .github/workflows/quality.yml | 8 +- .gitignore | 1 - composer.json | 4 +- ecs.php | 94 +++++++++++++++++++ phpcs.xml.dist | 17 ---- src/Adapter/ConstantAdapter.php | 8 +- src/Adapter/DateTimeAdapter.php | 6 +- src/Adapter/EnumAdapter.php | 2 +- src/Adapter/FactoryAdapter.php | 2 +- src/Adapter/JsonAdapter.php | 2 +- src/Adapter/NthAdapter.php | 4 +- src/Adapter/ScalarAdapter.php | 4 +- src/Adapter/UnescapeAdapter.php | 2 +- src/Evaluator.php | 2 +- src/EvaluatorBuilder.php | 24 ++--- src/Exception/UnexpectedTypeException.php | 2 +- .../DateTime/FormatArgumentGuesser.php | 6 +- .../Evaluator/ConstantEvaluator.php | 2 +- .../Evaluator/DateTimeEvaluator.php | 4 +- .../Evaluator/EnumEvaluator.php | 4 +- .../Evaluator/FactoryEvaluator.php | 10 +- .../FunctionExpressionMatcher.php | 2 +- src/Foundry/FactoryClassFactory.php | 2 +- tests/Application/config/bundles.php | 2 + tests/Behat/Context/EvaluatorContext.php | 4 +- .../Adapter/FactoryAdapterTest.php | 36 +++---- tests/Resources/Faker.php | 20 ++-- tests/Resources/UnsupportedValuesProvider.php | 4 +- tests/Unit/Adapter/ConstantAdapterTest.php | 14 +-- tests/Unit/Adapter/DateTimeAdapterTest.php | 48 +++++----- tests/Unit/Adapter/EnumAdapterTest.php | 28 +++--- tests/Unit/Builder/EvaluatorBuilderTest.php | 5 +- tests/Unit/EvaluatorTest.php | 4 +- .../Factory/AccessorArgumentGuesserTest.php | 6 +- .../Factory/AttributesArgumentGuesserTest.php | 2 +- .../FunctionExpressionMatcherTest.php | 8 +- .../Unit/Foundry/FactoryClassFactoryTest.php | 2 +- 37 files changed, 235 insertions(+), 160 deletions(-) create mode 100644 ecs.php delete mode 100644 phpcs.xml.dist diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index 0bcc5e1..05a05e2 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -5,8 +5,8 @@ on: branches: ['*'] jobs: - phpcs: - name: 'PHP CodeSniffer' + ecs: + name: 'Easy Coding Standard' runs-on: 'ubuntu-latest' strategy: @@ -26,8 +26,8 @@ jobs: - name: 'Install dependencies' run: 'composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist' - - name: 'Execute PHP CodeSniffer' - run: 'vendor/bin/phpcs' + - name: 'Execute Easy Coding Standard' + run: 'vendor/bin/ecs' phpstan: name: 'PHPStan' diff --git a/.gitignore b/.gitignore index 0342768..f3aff5f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ /docker/ /var/ /vendor/ -/.phpcs-cache /.phpunit.result.cache /composer.lock /Taskfile.yaml diff --git a/composer.json b/composer.json index ffd7c4d..4e0c4cc 100644 --- a/composer.json +++ b/composer.json @@ -25,14 +25,14 @@ "doctrine/orm": "^3.2.1", "phpstan/phpstan": "^1.11", "phpunit/phpunit": "^10.5|^11.3", - "squizlabs/php_codesniffer": "^3.10", "symfony/console": "^6.0|^7.0", "symfony/dotenv": "^6.0|^7.0", "symfony/framework-bundle": "^6.0|^7.0", "symfony/phpunit-bridge": "^6.0|^7.0", "symfony/runtime": "^6.0|^7.0", "symfony/var-dumper": "^6.0|^7.0", - "symfony/yaml": "^6.0|^7.0" + "symfony/yaml": "^6.0|^7.0", + "symplify/easy-coding-standard": "^12.3" }, "autoload": { "psr-4": { diff --git a/ecs.php b/ecs.php new file mode 100644 index 0000000..a4e5ded --- /dev/null +++ b/ecs.php @@ -0,0 +1,94 @@ +withPaths( + [ + __DIR__ . '/src', + __DIR__ . '/tests', + ], + ) + ->withPreparedSets( + psr12: true, + arrays: true, + comments: true, + docblocks: true, + namespaces: true, + phpunit: true, + strict: true, + ) + ->withConfiguredRule( + BlankLineBeforeStatementFixer::class, + [ + 'statements' => ['case', 'continue', 'declare', 'default', 'return', 'throw', 'try'], + ], + ) + ->withConfiguredRule( + CastSpacesFixer::class, + [ + 'space' => 'none', + ], + ) + ->withConfiguredRule( + ForbiddenFunctionsSniff::class, + [ + 'forbiddenFunctions' => ['dump' => null, 'dd' => null, 'var_dump' => null, 'die' => null], + ], + ) + ->withConfiguredRule( + LineLengthFixer::class, + [ + LineLengthFixer::INLINE_SHORT_LINES => false, + ], + ) + ->withConfiguredRule( + NativeFunctionInvocationFixer::class, + [ + 'scope' => 'namespaced', + 'include' => ['@all'], + ], + ) + ->withConfiguredRule( + NullableTypeDeclarationFixer::class, + [ + 'syntax' => 'union', + ], + ) + ->withConfiguredRule( + YodaStyleFixer::class, + [ + 'equal' => true, + 'identical' => true, + 'less_and_greater' => false, + ], + ) + ->withRules([ + FunctionDeclarationFixer::class, + ]) + ->withSkip( + [ + ArrayListItemNewlineFixer::class, + ArrayOpenerAndCloserNewlineFixer::class, + ExplicitStringVariableFixer::class, + StandaloneLineInMultilineArrayFixer::class, + StrictComparisonFixer::class => [ + 'src/Adapter/ScalarAdapter.php', + ], + ], + ) +; diff --git a/phpcs.xml.dist b/phpcs.xml.dist deleted file mode 100644 index f868c41..0000000 --- a/phpcs.xml.dist +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - src/ - tests/ - - diff --git a/src/Adapter/ConstantAdapter.php b/src/Adapter/ConstantAdapter.php index 440eff8..b028069 100644 --- a/src/Adapter/ConstantAdapter.php +++ b/src/Adapter/ConstantAdapter.php @@ -30,8 +30,8 @@ public function __invoke(mixed $value): mixed $evaluated = $this->expressionLanguage->evaluate($expression); // the evaluation did not end up with a transformation - preg_match('/constant\([\'"](?[^)]+)[\'"]\)/', $expression, $expressionMatches); - if (\is_string($evaluated) && $expressionMatches['value'] === addslashes($evaluated)) { + \preg_match('/constant\([\'"](?[^)]+)[\'"]\)/', $expression, $expressionMatches); + if (\is_string($evaluated) && $expressionMatches['value'] === \addslashes($evaluated)) { continue; } @@ -41,13 +41,13 @@ public function __invoke(mixed $value): mixed } if (!\is_scalar($evaluated) && !$evaluated instanceof \Stringable) { - $type = get_debug_type($evaluated); + $type = \get_debug_type($evaluated); throw new \RuntimeException("The evaluated constant of type \"$type\" could not be cast to string."); } // the expression is included in a larger string - $value = str_replace("<$expression>", (string) $evaluated, $value); + $value = \str_replace("<$expression>", (string)$evaluated, $value); } return $value; diff --git a/src/Adapter/DateTimeAdapter.php b/src/Adapter/DateTimeAdapter.php index 9581925..8b52228 100644 --- a/src/Adapter/DateTimeAdapter.php +++ b/src/Adapter/DateTimeAdapter.php @@ -43,10 +43,10 @@ public function __invoke(mixed $value): mixed // surround named parameters arguments by double quotes // so that the named parameter part is not interpreted by the expression language // ex. 'format: "Y-m-d"' will be transformed to '"format: \"Y-m-d\""' - $quotedExpression = preg_replace_callback( + $quotedExpression = \preg_replace_callback( '/(format|intl): ?[^,)]+/', static function (array $matches): string { - $value = addslashes($matches[0] ?? ''); + $value = \addslashes($matches[0] ?? ''); return "\"$value\""; }, @@ -62,7 +62,7 @@ static function (array $matches): string { \assert(\is_string($evaluated)); - $value = str_replace("<$expression>", $evaluated, $value); + $value = \str_replace("<$expression>", $evaluated, $value); } return $value; diff --git a/src/Adapter/EnumAdapter.php b/src/Adapter/EnumAdapter.php index b7a70ce..239d86e 100644 --- a/src/Adapter/EnumAdapter.php +++ b/src/Adapter/EnumAdapter.php @@ -59,7 +59,7 @@ public function __invoke(mixed $value): mixed \assert(\is_int($evaluated) || \is_string($evaluated)); - $value = str_replace("<$expression>", (string)$evaluated, $value); + $value = \str_replace("<$expression>", (string)$evaluated, $value); } return match (\is_numeric($value)) { diff --git a/src/Adapter/FactoryAdapter.php b/src/Adapter/FactoryAdapter.php index 3bed4c4..d72df23 100644 --- a/src/Adapter/FactoryAdapter.php +++ b/src/Adapter/FactoryAdapter.php @@ -44,7 +44,7 @@ public function __invoke(mixed $value): mixed throw new \RuntimeException(); } - $value = str_replace("<$expression>", (string) $evaluated, $value); + $value = \str_replace("<$expression>", (string)$evaluated, $value); } return $value; diff --git a/src/Adapter/JsonAdapter.php b/src/Adapter/JsonAdapter.php index cbe570d..e9781c1 100644 --- a/src/Adapter/JsonAdapter.php +++ b/src/Adapter/JsonAdapter.php @@ -12,7 +12,7 @@ public function __invoke(mixed $value): mixed return $value; } - $data = json_decode($value, true); + $data = \json_decode($value, true); if (\is_array($data)) { return $data; } diff --git a/src/Adapter/NthAdapter.php b/src/Adapter/NthAdapter.php index 844fcbc..c369dcd 100644 --- a/src/Adapter/NthAdapter.php +++ b/src/Adapter/NthAdapter.php @@ -12,11 +12,11 @@ public function __invoke(mixed $value): mixed return $value; } - preg_match('/^(?\d+)(st|nd|rd|th)$/', $value, $matches); + \preg_match('/^(?\d+)(st|nd|rd|th)$/', $value, $matches); if ('' === ($matches['count'] ?? '')) { return $value; } - return (int) $matches['count']; + return (int)$matches['count']; } } diff --git a/src/Adapter/ScalarAdapter.php b/src/Adapter/ScalarAdapter.php index b759fd9..9f56a79 100644 --- a/src/Adapter/ScalarAdapter.php +++ b/src/Adapter/ScalarAdapter.php @@ -16,8 +16,8 @@ public function __invoke(mixed $value): mixed 'null' === $value => null, 'true' === $value => true, 'false' === $value => false, - (int) $value == $value => (int) $value, - (float) $value == $value => (float) $value, + (int)$value == $value => (int)$value, + (float)$value == $value => (float)$value, default => $value, }; } diff --git a/src/Adapter/UnescapeAdapter.php b/src/Adapter/UnescapeAdapter.php index fdd7877..69da333 100644 --- a/src/Adapter/UnescapeAdapter.php +++ b/src/Adapter/UnescapeAdapter.php @@ -12,6 +12,6 @@ public function __invoke(mixed $value): mixed return $value; } - return stripslashes($value); + return \stripslashes($value); } } diff --git a/src/Evaluator.php b/src/Evaluator.php index dd47ae1..2682b52 100644 --- a/src/Evaluator.php +++ b/src/Evaluator.php @@ -38,7 +38,7 @@ public static function evaluate(mixed $value, EvaluatorBuilder $builder = new Ev */ public static function evaluateMany(array $values, EvaluatorBuilder $builder = new EvaluatorBuilder()): array { - return array_map( + return \array_map( static fn (mixed $value): mixed => self::evaluate($value, $builder), $values, ); diff --git a/src/EvaluatorBuilder.php b/src/EvaluatorBuilder.php index 72f466a..b5f861a 100644 --- a/src/EvaluatorBuilder.php +++ b/src/EvaluatorBuilder.php @@ -36,28 +36,28 @@ public function __construct() $this->inflector = InflectorFactory::create()->build(); $this->registerAdapterFactory( ConstantAdapter::class, - static fn(ExpressionLanguage $expressionLanguage): AdapterInterface + static fn (ExpressionLanguage $expressionLanguage): AdapterInterface => new ConstantAdapter($expressionLanguage), ); $this->registerAdapterFactory( DateTimeAdapter::class, - static fn(ExpressionLanguage $expressionLanguage): AdapterInterface + static fn (ExpressionLanguage $expressionLanguage): AdapterInterface => new DateTimeAdapter($expressionLanguage), ); $this->registerAdapterFactory( EnumAdapter::class, - static fn(ExpressionLanguage $expressionLanguage): AdapterInterface + static fn (ExpressionLanguage $expressionLanguage): AdapterInterface => new EnumAdapter($expressionLanguage), ); $this->registerAdapterFactory( FactoryAdapter::class, - static fn(ExpressionLanguage $expressionLanguage): AdapterInterface + static fn (ExpressionLanguage $expressionLanguage): AdapterInterface => new FactoryAdapter($expressionLanguage), ); - $this->registerAdapterFactory(JsonAdapter::class, static fn(): AdapterInterface => new JsonAdapter()); - $this->registerAdapterFactory(NthAdapter::class, static fn(): AdapterInterface => new NthAdapter()); - $this->registerAdapterFactory(ScalarAdapter::class, static fn(): AdapterInterface => new ScalarAdapter()); - $this->registerAdapterFactory(UnescapeAdapter::class, static fn(): AdapterInterface => new UnescapeAdapter()); + $this->registerAdapterFactory(JsonAdapter::class, static fn (): AdapterInterface => new JsonAdapter()); + $this->registerAdapterFactory(NthAdapter::class, static fn (): AdapterInterface => new NthAdapter()); + $this->registerAdapterFactory(ScalarAdapter::class, static fn (): AdapterInterface => new ScalarAdapter()); + $this->registerAdapterFactory(UnescapeAdapter::class, static fn (): AdapterInterface => new UnescapeAdapter()); } /** @@ -67,7 +67,7 @@ public function __construct() */ public function registerAdapter(AdapterInterface $adapter): self { - $this->adapterFactories[$adapter::class] = static fn(): AdapterInterface => $adapter; + $this->adapterFactories[$adapter::class] = static fn (): AdapterInterface => $adapter; return $this; } @@ -122,9 +122,9 @@ public function build(): Evaluator ); return new Evaluator( - array_values( - array_map( - static fn(\Closure $factory): AdapterInterface => $factory($expressionLanguage), + \array_values( + \array_map( + static fn (\Closure $factory): AdapterInterface => $factory($expressionLanguage), $this->adapterFactories, ), ), diff --git a/src/Exception/UnexpectedTypeException.php b/src/Exception/UnexpectedTypeException.php index 131fa5f..4d26df8 100644 --- a/src/Exception/UnexpectedTypeException.php +++ b/src/Exception/UnexpectedTypeException.php @@ -8,7 +8,7 @@ final class UnexpectedTypeException extends \RuntimeException { public function __construct(mixed $value, string $expectedType) { - $actualType = get_debug_type($value); + $actualType = \get_debug_type($value); parent::__construct("Expected argument of type \"$expectedType\", \"$actualType\" given."); } diff --git a/src/ExpressionLanguage/ArgumentGuesser/DateTime/FormatArgumentGuesser.php b/src/ExpressionLanguage/ArgumentGuesser/DateTime/FormatArgumentGuesser.php index 40d52b2..6305d73 100644 --- a/src/ExpressionLanguage/ArgumentGuesser/DateTime/FormatArgumentGuesser.php +++ b/src/ExpressionLanguage/ArgumentGuesser/DateTime/FormatArgumentGuesser.php @@ -41,17 +41,15 @@ public function __invoke(string|array|null $time = null, string|array|null $form } /** - * @param string $argument - * * @return IntlFormats|string */ private function format(string $argument): array|string { - $argument = trim(str_replace(['format:', 'intl:'], '', $argument), ' "\''); + $argument = \trim(\str_replace(['format:', 'intl:'], '', $argument), ' "\''); try { /** @var IntlFormats $formats */ - $formats = json_decode($argument, true, JSON_THROW_ON_ERROR); + $formats = \json_decode($argument, true, JSON_THROW_ON_ERROR); if (\is_array($formats)) { return $formats; } diff --git a/src/ExpressionLanguage/Evaluator/ConstantEvaluator.php b/src/ExpressionLanguage/Evaluator/ConstantEvaluator.php index a7204ca..8ba3874 100644 --- a/src/ExpressionLanguage/Evaluator/ConstantEvaluator.php +++ b/src/ExpressionLanguage/Evaluator/ConstantEvaluator.php @@ -12,7 +12,7 @@ final class ConstantEvaluator public function __invoke(array $arguments, string $value): mixed { try { - return constant($value); + return \constant($value); } catch (\Throwable) { } diff --git a/src/ExpressionLanguage/Evaluator/DateTimeEvaluator.php b/src/ExpressionLanguage/Evaluator/DateTimeEvaluator.php index 396ccde..dd45b18 100644 --- a/src/ExpressionLanguage/Evaluator/DateTimeEvaluator.php +++ b/src/ExpressionLanguage/Evaluator/DateTimeEvaluator.php @@ -52,13 +52,13 @@ public function __invoke(array $arguments, string|array|null $time = null, strin private function intl(\DateTimeInterface $datetime, array $formats): string { $date = $formats['date'] ?? 'NONE'; - $date = constant("\IntlDateFormatter::$date"); + $date = \constant("\IntlDateFormatter::$date"); if (!\is_int($date)) { throw new \RuntimeException('The intl date format should be a valid \IntlDateFormatter format'); } $time = $formats['time'] ?? 'NONE'; - $time = constant("\IntlDateFormatter::$time"); + $time = \constant("\IntlDateFormatter::$time"); if (!\is_int($time)) { throw new \RuntimeException('The intl time format should be a valid \IntlDateFormatter format'); } diff --git a/src/ExpressionLanguage/Evaluator/EnumEvaluator.php b/src/ExpressionLanguage/Evaluator/EnumEvaluator.php index ee1d300..ac5487a 100644 --- a/src/ExpressionLanguage/Evaluator/EnumEvaluator.php +++ b/src/ExpressionLanguage/Evaluator/EnumEvaluator.php @@ -12,13 +12,13 @@ final class EnumEvaluator public function __invoke(array $arguments, string $enumClass, string $property = null): mixed { try { - $enum = constant($enumClass); + $enum = \constant($enumClass); } catch (\Throwable) { throw new \RuntimeException("\"$enumClass\" is not a valid enum."); } if (!$enum instanceof \UnitEnum) { - $debugType = get_debug_type($enum); + $debugType = \get_debug_type($enum); throw new \RuntimeException("\"$debugType\" is not a valid enum."); } diff --git a/src/ExpressionLanguage/Evaluator/FactoryEvaluator.php b/src/ExpressionLanguage/Evaluator/FactoryEvaluator.php index fdcb663..43fcc93 100644 --- a/src/ExpressionLanguage/Evaluator/FactoryEvaluator.php +++ b/src/ExpressionLanguage/Evaluator/FactoryEvaluator.php @@ -66,10 +66,10 @@ public function __invoke( } $value = match (true) { - \is_numeric($min) && \is_array($attributes) => call_user_func($callable, $min, $attributes), - \is_numeric($min) && !\is_array($attributes) => call_user_func($callable, $min), - !\is_numeric($min) && \is_array($attributes) => call_user_func($callable, $attributes), - default => call_user_func($callable), + \is_numeric($min) && \is_array($attributes) => \call_user_func($callable, $min, $attributes), + \is_numeric($min) && !\is_array($attributes) => \call_user_func($callable, $min), + !\is_numeric($min) && \is_array($attributes) => \call_user_func($callable, $attributes), + default => \call_user_func($callable), }; if (null !== $accessor) { @@ -84,7 +84,7 @@ public function __invoke( switch (true) { case \is_array($value): - $value = new ArrayCollection(array_map(static fn (Proxy $proxy): object => $proxy->_real(), $value)); + $value = new ArrayCollection(\array_map(static fn (Proxy $proxy): object => $proxy->_real(), $value)); break; case $value instanceof Proxy: diff --git a/src/ExpressionLanguage/ExpressionMatcher/FunctionExpressionMatcher.php b/src/ExpressionLanguage/ExpressionMatcher/FunctionExpressionMatcher.php index ae9009e..61a8570 100644 --- a/src/ExpressionLanguage/ExpressionMatcher/FunctionExpressionMatcher.php +++ b/src/ExpressionLanguage/ExpressionMatcher/FunctionExpressionMatcher.php @@ -11,7 +11,7 @@ final class FunctionExpressionMatcher */ public function __invoke(string $name, string $text): array { - preg_match_all("/<(?$name\(.*\))>/U", $text, $matches); + \preg_match_all("/<(?$name\(.*\))>/U", $text, $matches); return $matches['expression']; } diff --git a/src/Foundry/FactoryClassFactory.php b/src/Foundry/FactoryClassFactory.php index 9d96235..a4d4a4e 100644 --- a/src/Foundry/FactoryClassFactory.php +++ b/src/Foundry/FactoryClassFactory.php @@ -22,7 +22,7 @@ public function __construct(string $namespace, private readonly Inflector $infle public function fromName(string $name): string { - $name = implode('\\', array_map($this->inflector->classify(...), explode('/', $name))); + $name = \implode('\\', \array_map($this->inflector->classify(...), \explode('/', $name))); $factoryClass = "$this->namespace{$name}Factory"; if (!\is_a($factoryClass, PersistentProxyObjectFactory::class, true)) { diff --git a/tests/Application/config/bundles.php b/tests/Application/config/bundles.php index 885590d..9dd7b67 100644 --- a/tests/Application/config/bundles.php +++ b/tests/Application/config/bundles.php @@ -1,5 +1,7 @@ ['test' => true], Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['test' => true], diff --git a/tests/Behat/Context/EvaluatorContext.php b/tests/Behat/Context/EvaluatorContext.php index c813a52..5b9e2df 100644 --- a/tests/Behat/Context/EvaluatorContext.php +++ b/tests/Behat/Context/EvaluatorContext.php @@ -22,7 +22,7 @@ final class EvaluatorContext implements Context #[Given('the local storage contains:')] public function set(TableNode $table): void { - $this->localStorage = Evaluator::evaluateMany(array_keys($table->getRowsHash())); + $this->localStorage = Evaluator::evaluateMany(\array_keys($table->getRowsHash())); } #[When('I format the datetime entries of the local storage with :format')] @@ -41,7 +41,7 @@ public function formatDateTimes(string $format): void public function assertLocalStorageContains(TableNode $table): void { TestCase::assertSame( - Evaluator::evaluateMany(array_keys($table->getRowsHash())), + Evaluator::evaluateMany(\array_keys($table->getRowsHash())), $this->localStorage, ); } diff --git a/tests/Integration/Adapter/FactoryAdapterTest.php b/tests/Integration/Adapter/FactoryAdapterTest.php index a4417f5..109a6f5 100644 --- a/tests/Integration/Adapter/FactoryAdapterTest.php +++ b/tests/Integration/Adapter/FactoryAdapterTest.php @@ -25,7 +25,7 @@ final class FactoryAdapterTest extends KernelTestCase public function testInvokingTheAdapter(mixed $expected, mixed $value): void { if ($expected instanceof \Throwable) { - $this->expectException(get_class($expected)); + $this->expectException(\get_class($expected)); if ('' !== $expected->getMessage()) { $this->expectExceptionMessage($expected->getMessage()); @@ -49,7 +49,7 @@ public function testInvokingTheAdapter(mixed $expected, mixed $value): void // ModelFactory::randomSet() does not return sorted entities if ($value instanceof ArrayCollection) { $data = $value->toArray(); - usort($data, static fn (User $left, User $right): int => $left->getId() <=> $right->getId()); + \usort($data, static fn (User $left, User $right): int => $left->getId() <=> $right->getId()); $value = new ArrayCollection($data); } @@ -63,21 +63,21 @@ public function testInvokingTheAdapter(mixed $expected, mixed $value): void public static function values(): iterable { yield 'a string containing only a factory expression with a factory name and an array of attributes' - . ' should find and return the relevant object proxy' => [ + . ' should find and return the relevant object proxy' => [ static fn () => UserFactory::find(['firstname' => 'John'])->_disableAutoRefresh(), '', ]; yield 'a string containing only a factory expression' - . ' with a factory name, an array of attributes and an accessor' - . ' should find and return the relevant object proxy\'s accessible property' => [ + . ' with a factory name, an array of attributes and an accessor' + . ' should find and return the relevant object proxy\'s accessible property' => [ 'John', '', ]; yield 'a string containing only a factory expression' - . ' with a factory name, a search method and an array of attributes' - . ' should find and return the relevant object proxy(s)' => [ + . ' with a factory name, a search method and an array of attributes' + . ' should find and return the relevant object proxy(s)' => [ static fn () => new ArrayCollection( - array_map( + \array_map( static fn (Proxy $proxy): object => $proxy->_real(), UserFactory::findBy(['lastname' => 'Doe']), ), @@ -85,14 +85,14 @@ public static function values(): iterable '', ]; yield 'a string containing only a factory expression with a factory name and a non search method' - . ' should return the relevant result' => [ + . ' should return the relevant result' => [ 2, '', ]; yield 'a string containing a factory expression with a factory name, the "randomSet" function' - . ' and an integer as third parameter should return the relevant object proxy(s)' => [ + . ' and an integer as third parameter should return the relevant object proxy(s)' => [ static fn () => new ArrayCollection( - array_map( + \array_map( static fn (Proxy $proxy): object => $proxy->_real(), UserFactory::all(), ), @@ -100,10 +100,10 @@ public static function values(): iterable '', ]; yield 'a string containing a factory expression with a factory name, the "randomSet" function,' - . ' an integer as third parameter and an array of attributes' - . ' should return the relevant object proxy(s)' => [ + . ' an integer as third parameter and an array of attributes' + . ' should return the relevant object proxy(s)' => [ static fn () => new ArrayCollection( - array_map( + \array_map( static fn (Proxy $proxy): object => $proxy->_real(), UserFactory::findBy(['firstname' => 'John']), ), @@ -111,12 +111,12 @@ public static function values(): iterable '', ]; yield 'a string containing a factory expression' - . ' should return the string after evaluating the factory expression' => [ + . ' should return the string after evaluating the factory expression' => [ 'The value John comes from a string', 'The value comes from a string', ]; yield 'a string containing many factory expressions' - . ' should return the string after evaluating the factory expressions' => [ + . ' should return the string after evaluating the factory expressions' => [ 'The values John and 2 come from a string', 'The values ' . ' and come from a string', @@ -135,12 +135,12 @@ public static function values(): iterable '', ]; yield 'a string containing a factory expression with a search method but no attributes' - . ' should throw an exception' => [ + . ' should throw an exception' => [ new \LogicException(), '', ]; yield 'a string containing a factory expression with a method, attributes and an accessor' - . ' should throw an exception' => [ + . ' should throw an exception' => [ new UnexpectedTypeException([], Proxy::class), '', ]; diff --git a/tests/Resources/Faker.php b/tests/Resources/Faker.php index aaace2f..17868af 100644 --- a/tests/Resources/Faker.php +++ b/tests/Resources/Faker.php @@ -14,21 +14,21 @@ final class Faker public static function scalars(array $excludedTypes = []): array { $booleans = [true, false]; - $floats = range(-5.5, 5.5); - $ints = range(-5, 5); + $floats = \range(-5.5, 5.5); + $ints = \range(-5, 5); $strings = ['foo', 'bar', 'Lorem Ipsum']; /** @var list $values */ $values = [ - $booleans[array_rand($booleans)], - $floats[array_rand($floats)], - $ints[array_rand($ints)], - $strings[array_rand($strings)], + $booleans[\array_rand($booleans)], + $floats[\array_rand($floats)], + $ints[\array_rand($ints)], + $strings[\array_rand($strings)], ]; - return array_filter( + return \array_filter( $values, - static fn (bool|float|int|string $value): bool => !\in_array(get_debug_type($value), $excludedTypes, true), + static fn (bool|float|int|string $value): bool => !\in_array(\get_debug_type($value), $excludedTypes, true), ); } @@ -46,14 +46,14 @@ public static function nonScalars(array $excludedTypes = []): array new \stdClass(), ]; - return array_filter( + return \array_filter( $values, static function (array|null|object $value) use ($excludedTypes): bool { if (\is_object($value) && \in_array('object', $excludedTypes, true)) { return false; } - return !\in_array(get_debug_type($value), $excludedTypes, true); + return !\in_array(\get_debug_type($value), $excludedTypes, true); }, ); } diff --git a/tests/Resources/UnsupportedValuesProvider.php b/tests/Resources/UnsupportedValuesProvider.php index 04e5136..b88cfd0 100644 --- a/tests/Resources/UnsupportedValuesProvider.php +++ b/tests/Resources/UnsupportedValuesProvider.php @@ -45,7 +45,7 @@ private static function createUnsupportedValueScenarioName(mixed $value): string { $debugType = match (true) { \is_object($value) => 'object', - default => get_debug_type($value), + default => \get_debug_type($value), }; $prefix = match ($debugType) { @@ -59,6 +59,6 @@ private static function createUnsupportedValueScenarioName(mixed $value): string default => '', }; - return trim("$prefix $debugType $suffix") . ' should return the original value unchanged'; + return \trim("$prefix $debugType $suffix") . ' should return the original value unchanged'; } } diff --git a/tests/Unit/Adapter/ConstantAdapterTest.php b/tests/Unit/Adapter/ConstantAdapterTest.php index 721d7c7..d05fd8e 100644 --- a/tests/Unit/Adapter/ConstantAdapterTest.php +++ b/tests/Unit/Adapter/ConstantAdapterTest.php @@ -20,7 +20,7 @@ final class ConstantAdapterTest extends TestCase public function testInvokingTheAdapter(mixed $expected, mixed $value): void { if ($expected instanceof \Throwable) { - $this->expectException(get_class($expected)); + $this->expectException(\get_class($expected)); if ('' !== $expected->getMessage()) { $this->expectExceptionMessage($expected->getMessage()); @@ -47,7 +47,7 @@ public static function values(): iterable '', ]; yield 'a string containing only a non existing PHP constant' - . ' should return the original expression unchanged' => [ + . ' should return the original expression unchanged' => [ '', '', ]; @@ -56,27 +56,27 @@ public static function values(): iterable '', ]; yield 'a string containing only a class constant from a non existing class' - . ' should return the original expression unchanged' => [ + . ' should return the original expression unchanged' => [ '', '', ]; yield 'a string containing only a non existing class constant' - . ' should return the original expression unchanged' => [ + . ' should return the original expression unchanged' => [ '', '', ]; yield 'a string containing only a valid constant but without the constant function' - . ' should return the original expression unchanged' => [ + . ' should return the original expression unchanged' => [ 'Presta\\\\BehatEvaluator\\\\Tests\\\\Resources\\\\ConstantHolder::STRING', 'Presta\\\\BehatEvaluator\\\\Tests\\\\Resources\\\\ConstantHolder::STRING', ]; yield 'a string containing a constant expression' - . ' should return the string after evaluating the constant expression' => [ + . ' should return the string after evaluating the constant expression' => [ 'the value ' . ARRAY_FILTER_USE_KEY . ' comes from a constant', 'the value comes from a constant', ]; yield 'a string containing many constant expressions' - . ' should return the string after evaluating the constant expressions' => [ + . ' should return the string after evaluating the constant expressions' => [ 'the values ' . ARRAY_FILTER_USE_KEY . ' and ' . ARRAY_FILTER_USE_BOTH . ' come from constants', 'the values and come from constants', ]; diff --git a/tests/Unit/Adapter/DateTimeAdapterTest.php b/tests/Unit/Adapter/DateTimeAdapterTest.php index cf35c52..4bdec3f 100644 --- a/tests/Unit/Adapter/DateTimeAdapterTest.php +++ b/tests/Unit/Adapter/DateTimeAdapterTest.php @@ -27,16 +27,16 @@ public function testInvokingTheAdapter(mixed $expected, mixed $value): void // create a new object to ignore the seconds and milliseconds to prevent comparison issues if ($expected instanceof \DateTimeInterface) { $expected = \DateTime::createFromInterface($expected)->setTime( - (int) $expected->format('H'), - (int) $expected->format('i'), + (int)$expected->format('H'), + (int)$expected->format('i'), ); } // create a new object to ignore the seconds and milliseconds to prevent comparison issues if ($value instanceof \DateTimeInterface) { $value = \DateTime::createFromInterface($value)->setTime( - (int) $value->format('H'), - (int) $value->format('i'), + (int)$value->format('H'), + (int)$value->format('i'), ); } @@ -50,70 +50,70 @@ public static function values(): iterable { foreach (['datetime' => '\DateTime', 'datetime_immutable' => '\DateTimeImmutable'] as $name => $className) { yield "a string containing only a $name expression with no parameters" - . " should return a $className object set to the current time" => [ + . " should return a $className object set to the current time" => [ new $className(), "<$name()>", ]; yield "a string containing only a $name expression with a \"time\" parameter" - . " should return a $className object set to the given time" => [ + . " should return a $className object set to the given time" => [ new $className('2023-01-01 00:00:00'), "<$name(\"2023-01-01 00:00:00\")>", ]; yield "a string containing only a $name expression with a \"time\" parameter and a \"format\" parameter" - . ' should return the given datetime string formatted with the given format' => [ + . ' should return the given datetime string formatted with the given format' => [ '01/01/2023', "<$name(\"2023-01-01\", \"d/m/Y\")>", ]; yield "a string containing only a $name expression with a \"time\" parameter" - . ' and a named parameter "format"' - . ' should return the given datetime string formatted with the given format' => [ + . ' and a named parameter "format"' + . ' should return the given datetime string formatted with the given format' => [ '01/01/2023', "<$name(\"2023-01-01\", format: \"d/m/Y\")>", ]; yield "a string containing only a $name expression with no \"time\" parameter" - . ' but a named parameter "format"' - . ' should return the current datetime string formatted with the given format' => [ - date('d/m/Y'), + . ' but a named parameter "format"' + . ' should return the current datetime string formatted with the given format' => [ + \date('d/m/Y'), "<$name(format: \"d/m/Y\")>", ]; yield "a string containing only a $name expression with no \"time\" parameter" - . ' but a named parameter "intl"' - . ' should return the current datetime string formatted with the given intl format' => [ - date('d/m/Y'), + . ' but a named parameter "intl"' + . ' should return the current datetime string formatted with the given intl format' => [ + \date('d/m/Y'), "<$name(intl: {\"date\": \"SHORT\"})>", ]; yield "a string containing only a $name expression with a \"time\" parameter" - . ' and an "intl" parameter specifying only the date format' - . ' should return the given datetime string formatted with the given intl date format' => [ + . ' and an "intl" parameter specifying only the date format' + . ' should return the given datetime string formatted with the given intl date format' => [ '1 janv. 2023', "<$name(\"2023-01-01\", {\"date\": \"MEDIUM\"})>", ]; yield "a string containing only a $name expression with a \"time\" parameter" - . ' and a named parameter "intl" specifying only the time format' - . ' should return the given datetime string formatted with the given intl time format' => [ + . ' and a named parameter "intl" specifying only the time format' + . ' should return the given datetime string formatted with the given intl time format' => [ '08:00', "<$name(\"2023-01-01 08:00:00\", intl: {\"time\": \"SHORT\"})>", ]; yield "a string containing only a $name expression with a \"time\" parameter" - . ' and an "intl" parameter specifying a date and a time format' - . ' should return the given datetime string formatted with the given intl date and time formats' => [ + . ' and an "intl" parameter specifying a date and a time format' + . ' should return the given datetime string formatted with the given intl date and time formats' => [ '1 janvier 2023 à 08:00:00', "<$name(\"2023-01-01 08:00:00\", {\"date\": \"LONG\", \"time\": \"MEDIUM\"})>", ]; yield "a string containing a $name expression escaped with single quotes" - . " should return the string after evaluating the $name expression" => [ + . " should return the string after evaluating the $name expression" => [ 'the value 1 janv. 2023 is escaped with single quotes', "the value <$name('2023-01-01 00:00:00', {'date': 'MEDIUM'})> is escaped with single quotes", ]; yield "a string containing a $name expression" - . " should return the string after evaluating the $name expression" => [ + . " should return the string after evaluating the $name expression" => [ 'the value 01/01/2023 comes from a string', "the value <$name(\"2023-01-01\", \"d/m/Y\")> comes from a string", ]; } yield 'a string containing many datetime and datetime_immutable expressions' - . ' should return the string after evaluating the datetime and datetime_immutable expressions' => [ + . ' should return the string after evaluating the datetime and datetime_immutable expressions' => [ 'the values 01/01/2023 and 08:00 come from a string', 'the values and come from a string', ]; diff --git a/tests/Unit/Adapter/EnumAdapterTest.php b/tests/Unit/Adapter/EnumAdapterTest.php index 7e20796..d85ea6e 100644 --- a/tests/Unit/Adapter/EnumAdapterTest.php +++ b/tests/Unit/Adapter/EnumAdapterTest.php @@ -22,7 +22,7 @@ final class EnumAdapterTest extends TestCase public function testInvokingTheAdapter(mixed $expected, mixed $value): void { if ($expected instanceof \Throwable) { - $this->expectException(get_class($expected)); + $this->expectException(\get_class($expected)); if ('' !== $expected->getMessage()) { $this->expectExceptionMessage($expected->getMessage()); @@ -61,27 +61,27 @@ public static function values(): iterable '', ]; yield 'a string containing only an int backed enum and requesting it\'s value' - . ' should return the enum\'s value' => [ + . ' should return the enum\'s value' => [ PriorityEnum::High->value, '', ]; yield 'a string containing only a string backed enum and requesting it\'s value' - . ' should return the enum\'s value' => [ + . ' should return the enum\'s value' => [ StatusEnum::Todo->value, '', ]; yield 'a string containing only a unit enum and requesting it\'s name' - . ' should throw a runtime exception' => [ + . ' should throw a runtime exception' => [ new \RuntimeException('You can not get the "name" of a UnitEnum.'), '', ]; yield 'a string containing only an int backed enum and requesting it\'s name' - . ' should return the enum\'s name' => [ + . ' should return the enum\'s name' => [ PriorityEnum::High->name, '', ]; yield 'a string containing only a string backed enum and requesting it\'s name' - . ' should return the enum\'s name' => [ + . ' should return the enum\'s name' => [ StatusEnum::Todo->name, '', ]; @@ -106,7 +106,7 @@ public static function values(): iterable '', ]; yield 'a string containing only a valid enum but without the enum function' - . ' should return the original expression unchanged' => [ + . ' should return the original expression unchanged' => [ 'Presta\\\\BehatEvaluator\\\\Tests\\\\Resources\\\\FooBarEnum::Foo', 'Presta\\\\BehatEvaluator\\\\Tests\\\\Resources\\\\FooBarEnum::Foo', ]; @@ -116,37 +116,37 @@ public static function values(): iterable . ' comes from an enum', ]; yield 'a string containing an int backed enum expression' - . ' should return the string after evaluating the enum expression' => [ + . ' should return the string after evaluating the enum expression' => [ 'the value ' . PriorityEnum::Default->value . ' comes from an enum', 'the value ' . ' comes from an enum', ]; yield 'a string containing a string backed enum expression' - . ' should return the string after evaluating the enum expression' => [ + . ' should return the string after evaluating the enum expression' => [ 'the value ' . StatusEnum::Doing->value . ' comes from an enum', 'the value ' . ' comes from an enum', ]; yield 'a string containing a unit enum expression and requesting it\'s value' - . ' should throw a runtime exception' => [ + . ' should throw a runtime exception' => [ new \RuntimeException('You can not get the "value" of a UnitEnum.'), 'the value ' . ' comes from an enum', ]; yield 'a string containing an int backed enum expression and requesting it\'s value' - . ' should return the string after evaluating the enum expression' => [ + . ' should return the string after evaluating the enum expression' => [ 'the value ' . PriorityEnum::Default->value . ' comes from an enum', 'the value ' . ' comes from an enum', ]; yield 'a string containing a string backed enum expression and requesting it\'s value' - . ' should return the string after evaluating the enum expression' => [ + . ' should return the string after evaluating the enum expression' => [ 'the value ' . StatusEnum::Doing->value . ' comes from an enum', 'the value ' . ' comes from an enum', ]; yield 'a string containing many enum expressions' - . ' should return the string after evaluating the enum expressions' => [ + . ' should return the string after evaluating the enum expressions' => [ 'the values ' . PriorityEnum::Low->value . ' and ' . StatusEnum::Done->value . ' come from enums', 'the values ' . ' and ' @@ -154,7 +154,7 @@ public static function values(): iterable ]; yield from self::unsupportedValues(['string']); yield 'a string containing only a string backed enum and requesting a non existing property' - . ' should throw a runtime exception' => [ + . ' should throw a runtime exception' => [ new \RuntimeException('You can not get the "invalid" property of an enum.'), '', ]; diff --git a/tests/Unit/Builder/EvaluatorBuilderTest.php b/tests/Unit/Builder/EvaluatorBuilderTest.php index fb616e9..fb06dbf 100644 --- a/tests/Unit/Builder/EvaluatorBuilderTest.php +++ b/tests/Unit/Builder/EvaluatorBuilderTest.php @@ -18,8 +18,7 @@ public function testSettingOptions(): void $factoryNamespace = 'Presta\\BehatEvaluator\\Tests\\Application\\Foundry\\Factory\\'; $inflector = InflectorFactory::create()->build(); - $adapter = new class ($culture, $factoryNamespace, $inflector) implements AdapterInterface - { + $adapter = new class($culture, $factoryNamespace, $inflector) implements AdapterInterface { public function __construct( private readonly string $culture, private readonly string $factoryNamespace, @@ -44,7 +43,7 @@ public function __invoke(mixed $value): array $builder->withCulture($culture); $builder->withFactoryNamespace($factoryNamespace); $builder->withInflector($inflector); - $builder->registerAdapterFactory($adapter::class, static fn(): AdapterInterface => $adapter); + $builder->registerAdapterFactory($adapter::class, static fn (): AdapterInterface => $adapter); $evaluate = $builder->build(); diff --git a/tests/Unit/EvaluatorTest.php b/tests/Unit/EvaluatorTest.php index 3bb7d0f..d242576 100644 --- a/tests/Unit/EvaluatorTest.php +++ b/tests/Unit/EvaluatorTest.php @@ -15,7 +15,7 @@ final class EvaluatorTest extends TestCase public function testInvokingTheEvaluator(mixed $expected, mixed $value): void { $adapters = [ - new class implements AdapterInterface { + new class() implements AdapterInterface { public function __invoke(mixed $value): mixed { if ('123' === $value) { @@ -25,7 +25,7 @@ public function __invoke(mixed $value): mixed return $value; } }, - new class implements AdapterInterface { + new class() implements AdapterInterface { public function __invoke(mixed $value): mixed { if (123 === $value) { diff --git a/tests/Unit/ExpressionLanguage/ArgumentGuesser/Factory/AccessorArgumentGuesserTest.php b/tests/Unit/ExpressionLanguage/ArgumentGuesser/Factory/AccessorArgumentGuesserTest.php index 044b84e..f197d7d 100644 --- a/tests/Unit/ExpressionLanguage/ArgumentGuesser/Factory/AccessorArgumentGuesserTest.php +++ b/tests/Unit/ExpressionLanguage/ArgumentGuesser/Factory/AccessorArgumentGuesserTest.php @@ -53,7 +53,7 @@ public static function arguments(): iterable null, ]; yield 'a non null method, an array of attributes and a string as 3rd argument' - . ' should return the 3rd argument' => [ + . ' should return the 3rd argument' => [ 'lastname', 'find', [], @@ -61,7 +61,7 @@ public static function arguments(): iterable null, ]; yield 'a non null method, an numeric value as 2nd argument and a string as 3rd argument' - . ' should return the 3rd argument' => [ + . ' should return the 3rd argument' => [ 'lastname', 'find', '1', @@ -69,7 +69,7 @@ public static function arguments(): iterable null, ]; yield 'a non null method, an numeric value as 2nd argument, an array of attributes and a string as 4th argument' - . ' should return the 4th argument' => [ + . ' should return the 4th argument' => [ 'lastname', 'find', '1', diff --git a/tests/Unit/ExpressionLanguage/ArgumentGuesser/Factory/AttributesArgumentGuesserTest.php b/tests/Unit/ExpressionLanguage/ArgumentGuesser/Factory/AttributesArgumentGuesserTest.php index 69e1a78..29fed5e 100644 --- a/tests/Unit/ExpressionLanguage/ArgumentGuesser/Factory/AttributesArgumentGuesserTest.php +++ b/tests/Unit/ExpressionLanguage/ArgumentGuesser/Factory/AttributesArgumentGuesserTest.php @@ -54,7 +54,7 @@ public static function arguments(): iterable null, ]; yield 'a non null method, a numeric value as 2nd argument and an array as 3rd argument' - . ' should return the 3rd argument' => [ + . ' should return the 3rd argument' => [ [], 'randomSet', '2', diff --git a/tests/Unit/ExpressionLanguage/ExpressionMatcher/FunctionExpressionMatcherTest.php b/tests/Unit/ExpressionLanguage/ExpressionMatcher/FunctionExpressionMatcherTest.php index 942eb1c..c6884a9 100644 --- a/tests/Unit/ExpressionLanguage/ExpressionMatcher/FunctionExpressionMatcherTest.php +++ b/tests/Unit/ExpressionLanguage/ExpressionMatcher/FunctionExpressionMatcherTest.php @@ -51,13 +51,13 @@ public static function strings(): iterable "The expression <$simpleFunction> is inside a string", ]; yield 'a function expression containing arguments inside a larger string' - . ' should return the function and it\'s arguments' => [ + . ' should return the function and it\'s arguments' => [ [$functionWithArguments], 'foobar', "The expression <$functionWithArguments> is inside a string", ]; yield 'a function expression containing delimiters inside a larger string' - . ' should return the function including the delimiters' => [ + . ' should return the function including the delimiters' => [ [$functionWithDelimiters], 'foobar', "The expression <$functionWithDelimiters> is inside a string", @@ -66,10 +66,10 @@ public static function strings(): iterable [$simpleFunction, $functionWithArguments, $functionWithDelimiters], 'foobar', "The expressions <$simpleFunction>, <$functionWithArguments> and <$functionWithDelimiters>" - . 'are inside a string', + . ' are inside a string', ]; yield 'a simple function expression and a name being a pattern' - . ' should return the simple function whose name matches the pattern' => [ + . ' should return the simple function whose name matches the pattern' => [ ['foo()'], 'foo(_bar)?', '', diff --git a/tests/Unit/Foundry/FactoryClassFactoryTest.php b/tests/Unit/Foundry/FactoryClassFactoryTest.php index 20382e4..2757941 100644 --- a/tests/Unit/Foundry/FactoryClassFactoryTest.php +++ b/tests/Unit/Foundry/FactoryClassFactoryTest.php @@ -15,7 +15,7 @@ final class FactoryClassFactoryTest extends TestCase public function testCreatingAFactoryClass(\Throwable|string $expected, string $name, string $namespace): void { if ($expected instanceof \Throwable) { - $this->expectException(get_class($expected)); + $this->expectException(\get_class($expected)); if ('' !== $expected->getMessage()) { $this->expectExceptionMessage($expected->getMessage());