From 2cd8ac26f7e81c136e714e20b59008528aa36618 Mon Sep 17 00:00:00 2001 From: Pierre PLAZANET Date: Thu, 15 Jun 2023 16:38:50 +0200 Subject: [PATCH] next release (#181) * add return annotation To get rid of this warning: Method "ArrayAccess::offsetGet()" might add "mixed" as a native return type declaration in the future. Do the same in implementation "Knp\DictionaryBundle\Dictionary\Traceable" now to avoid errors or add an explicit @return annotation to suppress this message. 1x in ImportYamlTest::testLoadYamlConfig with data set "oberon" from App\Tests\Service * docs: remove $ so gitclip works (#186) * Use dependency injection (#188) getting the dictionary through DI is a better practice that getting it from the container. * Allow Symfony 6.3 * refactor: remove support of php 7.4 * Add Symfony 6.2 to matrix (#183) * chore: drop support of Symfony 6.1 & 6.2 * tests: remove beberlei/assert and replace it by webmozart/assert (already in indirect dependencies) (#185) * fix: add missing Symfony 6.3 supported version constant * refactor: ad type to Dictionary ArrayAccess methods * ci: remove Symfony CLI security check (#194) * refactor: fix cs issues * ci: remove Symfony CLI security check * test: add tests for Symfony 6.3 and php 8.2 --------- Co-authored-by: Tac Tacelosky --- .circleci/config.yml | 38 ++++----- .php-cs-fixer.dist.php | 2 +- composer.json | 25 +++--- rector.php | 31 +++++++ .../Compiler/DictionaryBuildingPassSpec.php | 78 +++++++++-------- .../Dictionary/TraceableSpec.php | 83 ++++++++++--------- .../Templating/Extension/DictionarySpec.php | 10 +-- .../DictionaryBundle/Dictionary/Combined.php | 2 +- .../Dictionary/Factory/Combined.php | 5 +- .../Dictionary/Factory/Extended.php | 8 +- .../Dictionary/Factory/Invokable.php | 5 +- .../Dictionary/Factory/Iterator.php | 5 +- .../Dictionary/Factory/KeyValue.php | 5 +- .../Dictionary/Factory/Value.php | 5 +- .../Dictionary/Factory/ValueAsKey.php | 5 +- .../DictionaryBundle/Dictionary/Invokable.php | 23 ++--- .../DictionaryBundle/Dictionary/Simple.php | 24 ++---- .../DictionaryBundle/Dictionary/Traceable.php | 24 ++---- .../DictionaryBundle/Dictionary/Wrapper.php | 18 ++-- .../Faker/Provider/Dictionary.php | 6 +- .../Form/Type/DictionaryType.php | 5 +- .../Symfony/SupportedVersion.php | 16 ++++ .../Templating/Extension/Dictionary.php | 8 +- .../Constraints/DictionaryValidator.php | 13 +-- .../SymfonyCompatibilityTrait.php | 10 +-- src/Knp/DictionaryBundle/ValueTransformer.php | 9 +- .../ValueTransformer/Aggregate.php | 4 +- .../ValueTransformer/Constant.php | 4 +- 28 files changed, 217 insertions(+), 254 deletions(-) create mode 100644 rector.php create mode 100644 src/Knp/DictionaryBundle/Symfony/SupportedVersion.php diff --git a/.circleci/config.yml b/.circleci/config.yml index 13820f29..78739fbe 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -24,9 +24,8 @@ jobs: steps: - checkout - run: | - echo 'deb [trusted=yes] https://repo.symfony.com/apt/ /' | tee /etc/apt/sources.list.d/symfony-cli.list apt-get update - apt-get -y install git zip jq symfony-cli + apt-get -y install git zip jq - run: | php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php composer-setup.php @@ -43,19 +42,18 @@ jobs: mv composer.new.json composer.json cat composer.json - run: composer update << parameters.composer-options >> --ignore-platform-req=ext-intl - - run: symfony security:check - run: vendor/bin/phpstan analyse --no-progress --memory-limit=-1 - run: vendor/bin/phpspec run -v --config=phpspec.no-coverage.yml - run: bin/lint-twig src/ - - run: vendor/bin/php-cs-fixer fix --diff --dry-run -vvv + - run: PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --diff --dry-run -vvv workflows: version: 2 workflow: jobs: - test: - name: php7.4 - php: "7.4" + name: php8.0 + php: "8.0" matrix: parameters: symfony: @@ -64,36 +62,28 @@ workflows: - "--prefer-stable --prefer-lowest" - "--prefer-stable" - test: - name: php8.0 - php: "8.0" + name: php8.1 + php: "8.1" + minimum-stability: 'dev' # Remove on Symfony 6.4 release matrix: parameters: symfony: - "5.4" - - "6.0" + - "6.2" + - "6.3" composer-options: - "--prefer-stable --prefer-lowest" - "--prefer-stable" - test: - name: php8.1 - php: "8.1" + name: php8.2 + php: "8.2" + minimum-stability: 'dev' # Remove on Symfony 6.4 release matrix: parameters: symfony: - "5.4" - - "6.0" - - "6.1" + - "6.2" + - "6.3" composer-options: - "--prefer-stable --prefer-lowest" - "--prefer-stable" - # - test: - # name: php8.1-dev - # php: "8.1" - # minimum-stability: "dev" - # matrix: - # parameters: - # symfony: - # - "6.2" - # composer-options: - # - "--prefer-stable --prefer-lowest" - # - "--prefer-stable" diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index f24d441a..96e46e57 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -15,7 +15,7 @@ $config->setRules( PedroTroller\CS\Fixer\RuleSetFactory::create() ->phpCsFixer(true) - ->php(7.4, true) + ->php(8.0, true) ->pedrotroller(true) ->enable('align_multiline_comment') ->enable('array_indentation') diff --git a/composer.json b/composer.json index 5e6acd81..57f8b907 100644 --- a/composer.json +++ b/composer.json @@ -17,26 +17,27 @@ } ], "require": { - "php": ">=7.4", - "symfony/config": "^5.4 || ^6.0", - "symfony/dependency-injection": "^5.4 || ^6.0", - "symfony/form": "^5.4 || ^6.0", - "symfony/http-foundation": "^5.4 || ^6.0", - "symfony/http-kernel": "^5.4 || ^6.0", - "symfony/validator": "^5.4 || ^6.0", + "php": ">=8.0", + "symfony/config": "^5.4 || ^6.2@dev", + "symfony/dependency-injection": "^5.4 || ^6.2@dev", + "symfony/form": "^5.4 || ^6.2@dev", + "symfony/http-foundation": "^5.4 || ^6.2@dev", + "symfony/http-kernel": "^5.4 || ^6.2@dev", + "symfony/validator": "^5.4 || ^6.2@dev", "twig/twig": "^2.15.3 || ^3.4.3" }, "require-dev": { - "beberlei/assert": "^3.3", - "fakerphp/faker": "^1.19", + "fakerphp/faker": "^1.20", "friends-of-phpspec/phpspec-code-coverage": "^6.1", "friendsofphp/php-cs-fixer": "^3.13", "pedrotroller/php-cs-custom-fixer": "^2.28", "phpspec/phpspec": "^7.2", "phpspec/prophecy": "^1.15", "phpstan/phpstan": "^1.9", - "symfony/twig-bridge": "^5.4 || ^6.0", - "symfony/var-dumper": "^5.4 || ^6.0" + "rector/rector": "^0.14.7", + "symfony/twig-bridge": "^5.4 || ^6.2@dev", + "symfony/var-dumper": "^5.4 || ^6.2@dev", + "webmozart/assert": "^1.11" }, "minimum-stability": "stable", "autoload": { @@ -58,7 +59,7 @@ }, "extra": { "branch-alias": { - "dev-master": "3.2.x-dev" + "dev-master": "3.4.x-dev" } } } diff --git a/rector.php b/rector.php new file mode 100644 index 00000000..15405a8b --- /dev/null +++ b/rector.php @@ -0,0 +1,31 @@ +paths( + [ + __DIR__.'/src', + ] + ) + ; + + $rectorConfig + ->phpVersion( + PhpVersion::PHP_80 + ) + ; + + $rectorConfig + ->sets( + [ + LevelSetList::UP_TO_PHP_80, + ] + ) + ; +}; diff --git a/spec/Knp/DictionaryBundle/DependencyInjection/Compiler/DictionaryBuildingPassSpec.php b/spec/Knp/DictionaryBundle/DependencyInjection/Compiler/DictionaryBuildingPassSpec.php index 8e8f9af8..87b7f700 100644 --- a/spec/Knp/DictionaryBundle/DependencyInjection/Compiler/DictionaryBuildingPassSpec.php +++ b/spec/Knp/DictionaryBundle/DependencyInjection/Compiler/DictionaryBuildingPassSpec.php @@ -4,7 +4,6 @@ namespace spec\Knp\DictionaryBundle\DependencyInjection\Compiler; -use Assert\Assert; use Knp\DictionaryBundle\DependencyInjection\Compiler\DictionaryBuildingPass; use Knp\DictionaryBundle\DependencyInjection\Compiler\DictionaryRegistrationPass; use Knp\DictionaryBundle\Dictionary; @@ -12,6 +11,7 @@ use PhpSpec\ObjectBehavior; use Prophecy\Argument; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Webmozart\Assert\Assert; final class DictionaryBuildingPassSpec extends ObjectBehavior { @@ -35,23 +35,29 @@ function it_builds_a_value_as_key_dictionary_from_the_config(ContainerBuilder $c $container->setDefinition( 'knp_dictionary.dictionary.dico1', Argument::that(function ($definition): bool { - Assert::that($definition->getClass())->eq(Dictionary::class); + Assert::eq($definition->getClass(), Dictionary::class); $factory = $definition->getFactory(); - Assert::that($factory[0]->__toString())->eq(Aggregate::class); + Assert::eq((string) $factory[0], Aggregate::class); - Assert::that($factory[1])->eq('create'); + Assert::eq($factory[1], 'create'); - Assert::that($definition->getArguments())->eq([ - 'dico1', + Assert::eq( + $definition->getArguments(), [ - 'type' => Dictionary::VALUE_AS_KEY, - 'content' => ['foo', 'bar', 'baz'], - ], - ]); - - Assert::that($definition->getTags())->eq([DictionaryRegistrationPass::TAG_DICTIONARY => [[]]]); + 'dico1', + [ + 'type' => Dictionary::VALUE_AS_KEY, + 'content' => ['foo', 'bar', 'baz'], + ], + ] + ); + + Assert::eq( + $definition->getTags(), + [DictionaryRegistrationPass::TAG_DICTIONARY => [[]]] + ); return true; }) @@ -75,23 +81,26 @@ function it_builds_a_value_dictionary_from_the_config(ContainerBuilder $containe $container->setDefinition( 'knp_dictionary.dictionary.dico1', Argument::that(function ($definition): bool { - Assert::that($definition->getClass())->eq(Dictionary::class); + Assert::eq($definition->getClass(), Dictionary::class); $factory = $definition->getFactory(); - Assert::that($factory[0]->__toString())->eq(Aggregate::class); + Assert::eq((string) $factory[0], Aggregate::class); - Assert::that($factory[1])->eq('create'); + Assert::eq($factory[1], 'create'); - Assert::that($definition->getArguments())->eq([ - 'dico1', + Assert::eq( + $definition->getArguments(), [ - 'type' => Dictionary::VALUE, - 'content' => [2 => 'foo', 10 => 'bar', 100 => 'baz'], - ], - ]); + 'dico1', + [ + 'type' => Dictionary::VALUE, + 'content' => [2 => 'foo', 10 => 'bar', 100 => 'baz'], + ], + ] + ); - Assert::that($definition->getTags(), [DictionaryRegistrationPass::TAG_DICTIONARY => [[]]]); + Assert::eq($definition->getTags(), [DictionaryRegistrationPass::TAG_DICTIONARY => [[]]]); return true; }) @@ -115,23 +124,26 @@ function it_builds_a_key_value_dictionary_from_the_config(ContainerBuilder $cont $container->setDefinition( 'knp_dictionary.dictionary.dico1', Argument::that(function ($definition): bool { - Assert::that($definition->getClass())->eq(Dictionary::class); + Assert::eq($definition->getClass(), Dictionary::class); $factory = $definition->getFactory(); - Assert::that($factory[0]->__toString())->eq(Aggregate::class); + Assert::eq((string) $factory[0], Aggregate::class); - Assert::that($factory[1])->eq('create'); + Assert::eq($factory[1], 'create'); - Assert::that($definition->getArguments())->eq([ - 'dico1', + Assert::eq( + $definition->getArguments(), [ - 'type' => Dictionary::KEY_VALUE, - 'content' => [2 => 'foo', 10 => 'bar', 100 => 'baz'], - ], - ]); - - Assert::that($definition->getTags())->eq([DictionaryRegistrationPass::TAG_DICTIONARY => [[]]]); + 'dico1', + [ + 'type' => Dictionary::KEY_VALUE, + 'content' => [2 => 'foo', 10 => 'bar', 100 => 'baz'], + ], + ] + ); + + Assert::eq($definition->getTags(), [DictionaryRegistrationPass::TAG_DICTIONARY => [[]]]); return true; }) diff --git a/spec/Knp/DictionaryBundle/Dictionary/TraceableSpec.php b/spec/Knp/DictionaryBundle/Dictionary/TraceableSpec.php index d1f82f4a..a619643c 100644 --- a/spec/Knp/DictionaryBundle/Dictionary/TraceableSpec.php +++ b/spec/Knp/DictionaryBundle/Dictionary/TraceableSpec.php @@ -4,12 +4,12 @@ namespace spec\Knp\DictionaryBundle\Dictionary; -use Assert\Assert; use Knp\DictionaryBundle\DataCollector\DictionaryDataCollector; use Knp\DictionaryBundle\Dictionary; use Knp\DictionaryBundle\Dictionary\Simple; use Knp\DictionaryBundle\Dictionary\Traceable; use PhpSpec\ObjectBehavior; +use Webmozart\Assert\Assert; final class TraceableSpec extends ObjectBehavior { @@ -42,21 +42,22 @@ function it_is_a_dictionary() function it_has_a_name() { - Assert::that(iterator_to_array($this->collector->getDictionaries()))->noContent(); + Assert::isEmpty(iterator_to_array($this->collector->getDictionaries())); $this->getName()->shouldReturn('name'); - Assert::that(iterator_to_array($this->collector->getDictionaries()))->noContent(); + Assert::isEmpty(iterator_to_array($this->collector->getDictionaries())); } function it_traces_keys() { - Assert::that(iterator_to_array($this->collector->getDictionaries()))->noContent(); + Assert::isEmpty(iterator_to_array($this->collector->getDictionaries())); $this->getKeys()->shouldReturn(['foo', 'baz']); - Assert::that(iterator_to_array($this->collector->getDictionaries())) - ->eq([ + Assert::eq( + iterator_to_array($this->collector->getDictionaries()), + [ 'name' => [ [ 'key' => 'foo', @@ -67,18 +68,19 @@ function it_traces_keys() 'value' => null, ], ], - ]) - ; + ] + ); } function it_traces_values() { - Assert::that(iterator_to_array($this->collector->getDictionaries()))->noContent(); + Assert::isEmpty(iterator_to_array($this->collector->getDictionaries())); $this->getValues()->shouldReturn(['foo' => 'bar', 'baz' => null]); - Assert::that(iterator_to_array($this->collector->getDictionaries())) - ->eq([ + Assert::eq( + iterator_to_array($this->collector->getDictionaries()), + [ 'name' => [ [ 'key' => 'foo', @@ -89,18 +91,19 @@ function it_traces_values() 'value' => null, ], ], - ]) - ; + ], + ); } function it_traces_values_get() { - Assert::that(iterator_to_array($this->collector->getDictionaries()))->noContent(); + Assert::isEmpty(iterator_to_array($this->collector->getDictionaries())); $this['foo']->shouldReturn('bar'); - Assert::that(iterator_to_array($this->collector->getDictionaries())) - ->eq([ + Assert::eq( + iterator_to_array($this->collector->getDictionaries()), + [ 'name' => [ [ 'key' => 'foo', @@ -111,18 +114,19 @@ function it_traces_values_get() 'value' => null, ], ], - ]) - ; + ] + ); } function it_traces_value_set() { - Assert::that(iterator_to_array($this->collector->getDictionaries()))->noContent(); + Assert::isEmpty(iterator_to_array($this->collector->getDictionaries())); $this['yo'] = 'lo'; - Assert::that(iterator_to_array($this->collector->getDictionaries())) - ->eq([ + Assert::eq( + iterator_to_array($this->collector->getDictionaries()), + [ 'name' => [ [ 'key' => 'foo', @@ -137,36 +141,38 @@ function it_traces_value_set() 'value' => 'lo', ], ], - ]) - ; + ] + ); } function it_traces_value_unset() { - Assert::that(iterator_to_array($this->collector->getDictionaries()))->noContent(); + Assert::isEmpty(iterator_to_array($this->collector->getDictionaries())); unset($this['foo']); - Assert::that(iterator_to_array($this->collector->getDictionaries())) - ->eq([ + Assert::eq( + iterator_to_array($this->collector->getDictionaries()), + [ 'name' => [ [ 'key' => 'baz', 'value' => null, ], ], - ]) - ; + ] + ); } function it_traces_key_exists() { - Assert::that(iterator_to_array($this->collector->getDictionaries()))->noContent(); + Assert::isEmpty(iterator_to_array($this->collector->getDictionaries())); $this->shouldHaveKey('baz'); - Assert::that(iterator_to_array($this->collector->getDictionaries())) - ->eq([ + Assert::eq( + iterator_to_array($this->collector->getDictionaries()), + [ 'name' => [ [ 'key' => 'foo', @@ -177,21 +183,22 @@ function it_traces_key_exists() 'value' => null, ], ], - ]) - ; + ] + ); } function it_trace_iteration() { - Assert::that(iterator_to_array($this->collector->getDictionaries()))->noContent(); + Assert::isEmpty(iterator_to_array($this->collector->getDictionaries())); $this->shouldIterateLike([ 'foo' => 'bar', 'baz' => null, ]); - Assert::that(iterator_to_array($this->collector->getDictionaries())) - ->eq([ + Assert::eq( + iterator_to_array($this->collector->getDictionaries()), + [ 'name' => [ [ 'key' => 'foo', @@ -202,8 +209,8 @@ function it_trace_iteration() 'value' => null, ], ], - ]) - ; + ] + ); } function it_delegates_the_count_to_the_other_dictionary() diff --git a/spec/Knp/DictionaryBundle/Templating/Extension/DictionarySpec.php b/spec/Knp/DictionaryBundle/Templating/Extension/DictionarySpec.php index c5dd2953..5c670f90 100644 --- a/spec/Knp/DictionaryBundle/Templating/Extension/DictionarySpec.php +++ b/spec/Knp/DictionaryBundle/Templating/Extension/DictionarySpec.php @@ -4,11 +4,11 @@ namespace spec\Knp\DictionaryBundle\Templating\Extension; -use Assert\Assert; use Knp\DictionaryBundle\Dictionary; use Knp\DictionaryBundle\Dictionary\Collection; use Knp\DictionaryBundle\Templating\Extension; use PhpSpec\ObjectBehavior; +use Webmozart\Assert\Assert; final class DictionarySpec extends ObjectBehavior { @@ -42,8 +42,8 @@ function it_returns_a_dictionary_by_its_name($dico1, $dico2) $functions = $this->getFunctions(); $callable = current($functions->getWrappedObject())->getCallable(); - Assert::that($callable('test'))->eq($dico1->getWrappedObject()); - Assert::that($callable('other'))->eq($dico2->getWrappedObject()); + Assert::eq($callable('test'), $dico1->getWrappedObject()); + Assert::eq($callable('other'), $dico2->getWrappedObject()); } function it_returns_a_value_from_a_dictionary() @@ -51,7 +51,7 @@ function it_returns_a_value_from_a_dictionary() $filters = $this->getFilters(); $callable = current($filters->getWrappedObject())->getCallable(); - Assert::that($callable('foo', 'test'))->eq('bar'); - Assert::that($callable('foo', 'other'))->eq(false); + Assert::eq($callable('foo', 'test'), 'bar'); + Assert::eq($callable('foo', 'other'), false); } } diff --git a/src/Knp/DictionaryBundle/Dictionary/Combined.php b/src/Knp/DictionaryBundle/Dictionary/Combined.php index 331a47ec..149c3329 100644 --- a/src/Knp/DictionaryBundle/Dictionary/Combined.php +++ b/src/Knp/DictionaryBundle/Dictionary/Combined.php @@ -40,7 +40,7 @@ public function __construct(string $name, Dictionary ...$dictionaries) private function merge(array $array1, array $array2): array { if ($array1 === array_values($array1) && $array2 === array_values($array2)) { - return array_merge($array1, $array2); + return [...$array1, ...$array2]; } $data = []; diff --git a/src/Knp/DictionaryBundle/Dictionary/Factory/Combined.php b/src/Knp/DictionaryBundle/Dictionary/Factory/Combined.php index c4cb4531..535cd71c 100644 --- a/src/Knp/DictionaryBundle/Dictionary/Factory/Combined.php +++ b/src/Knp/DictionaryBundle/Dictionary/Factory/Combined.php @@ -16,11 +16,8 @@ final class Combined implements Factory */ private const TYPE = 'combined'; - private Dictionary\Collection $dictionaries; - - public function __construct(Collection $dictionaries) + public function __construct(private Collection $dictionaries) { - $this->dictionaries = $dictionaries; } public function create(string $name, array $config): Dictionary diff --git a/src/Knp/DictionaryBundle/Dictionary/Factory/Extended.php b/src/Knp/DictionaryBundle/Dictionary/Factory/Extended.php index ef96aed5..6221eef1 100644 --- a/src/Knp/DictionaryBundle/Dictionary/Factory/Extended.php +++ b/src/Knp/DictionaryBundle/Dictionary/Factory/Extended.php @@ -12,14 +12,8 @@ final class Extended implements Factory { - private Dictionary\Factory $factory; - - private Dictionary\Collection $dictionaries; - - public function __construct(Factory $factory, Collection $dictionaries) + public function __construct(private Factory $factory, private Collection $dictionaries) { - $this->factory = $factory; - $this->dictionaries = $dictionaries; } public function create(string $name, array $config): Dictionary diff --git a/src/Knp/DictionaryBundle/Dictionary/Factory/Invokable.php b/src/Knp/DictionaryBundle/Dictionary/Factory/Invokable.php index 59427287..5cb3ab3a 100644 --- a/src/Knp/DictionaryBundle/Dictionary/Factory/Invokable.php +++ b/src/Knp/DictionaryBundle/Dictionary/Factory/Invokable.php @@ -11,11 +11,8 @@ final class Invokable implements Factory { - private ContainerInterface $container; - - public function __construct(ContainerInterface $container) + public function __construct(private ContainerInterface $container) { - $this->container = $container; } /** diff --git a/src/Knp/DictionaryBundle/Dictionary/Factory/Iterator.php b/src/Knp/DictionaryBundle/Dictionary/Factory/Iterator.php index 5cdf167a..85f580ae 100644 --- a/src/Knp/DictionaryBundle/Dictionary/Factory/Iterator.php +++ b/src/Knp/DictionaryBundle/Dictionary/Factory/Iterator.php @@ -12,11 +12,8 @@ final class Iterator implements Factory { - private ContainerInterface $container; - - public function __construct(ContainerInterface $container) + public function __construct(private ContainerInterface $container) { - $this->container = $container; } /** diff --git a/src/Knp/DictionaryBundle/Dictionary/Factory/KeyValue.php b/src/Knp/DictionaryBundle/Dictionary/Factory/KeyValue.php index 4e658644..f0e18404 100644 --- a/src/Knp/DictionaryBundle/Dictionary/Factory/KeyValue.php +++ b/src/Knp/DictionaryBundle/Dictionary/Factory/KeyValue.php @@ -12,11 +12,8 @@ final class KeyValue implements Factory { - private ValueTransformer $transformer; - - public function __construct(ValueTransformer $transformer) + public function __construct(private ValueTransformer $transformer) { - $this->transformer = $transformer; } /** diff --git a/src/Knp/DictionaryBundle/Dictionary/Factory/Value.php b/src/Knp/DictionaryBundle/Dictionary/Factory/Value.php index 732782c9..04bf95b9 100644 --- a/src/Knp/DictionaryBundle/Dictionary/Factory/Value.php +++ b/src/Knp/DictionaryBundle/Dictionary/Factory/Value.php @@ -12,11 +12,8 @@ final class Value implements Factory { - private ValueTransformer $transformer; - - public function __construct(ValueTransformer $transformer) + public function __construct(private ValueTransformer $transformer) { - $this->transformer = $transformer; } /** diff --git a/src/Knp/DictionaryBundle/Dictionary/Factory/ValueAsKey.php b/src/Knp/DictionaryBundle/Dictionary/Factory/ValueAsKey.php index df37dc4b..0b0faf71 100644 --- a/src/Knp/DictionaryBundle/Dictionary/Factory/ValueAsKey.php +++ b/src/Knp/DictionaryBundle/Dictionary/Factory/ValueAsKey.php @@ -12,11 +12,8 @@ final class ValueAsKey implements Factory { - private ValueTransformer $transformer; - - public function __construct(ValueTransformer $transformer) + public function __construct(private ValueTransformer $transformer) { - $this->transformer = $transformer; } /** diff --git a/src/Knp/DictionaryBundle/Dictionary/Invokable.php b/src/Knp/DictionaryBundle/Dictionary/Invokable.php index bb7d9827..b178fddb 100644 --- a/src/Knp/DictionaryBundle/Dictionary/Invokable.php +++ b/src/Knp/DictionaryBundle/Dictionary/Invokable.php @@ -16,8 +16,6 @@ */ final class Invokable implements Dictionary { - private string $name; - private bool $invoked = false; /** @@ -30,24 +28,12 @@ final class Invokable implements Dictionary */ private $callable; - /** - * @var array - */ - private array $callableArgs = []; - /** * @param mixed[] $callableArgs */ - public function __construct(string $name, callable $callable, array $callableArgs = []) - { - $this->name = $name; - $this->callable = $callable; - $this->callableArgs = $callableArgs; - } - - public function getName(): string + public function __construct(private string $name, callable $callable, private array $callableArgs = []) { - return $this->name; + $this->callable = $callable; } public function getValues(): array @@ -57,6 +43,11 @@ public function getValues(): array return $this->values; } + public function getName(): string + { + return $this->name; + } + public function getKeys(): array { $this->invoke(); diff --git a/src/Knp/DictionaryBundle/Dictionary/Simple.php b/src/Knp/DictionaryBundle/Dictionary/Simple.php index 49c1414c..b4a73dd9 100644 --- a/src/Knp/DictionaryBundle/Dictionary/Simple.php +++ b/src/Knp/DictionaryBundle/Dictionary/Simple.php @@ -6,7 +6,6 @@ use Generator; use Knp\DictionaryBundle\Dictionary; -use ReturnTypeWillChange; /** * @template E @@ -15,20 +14,11 @@ */ final class Simple implements Dictionary { - private string $name; - - /** - * @var array - */ - private array $values = []; - /** * @param array $values */ - public function __construct(string $name, array $values) + public function __construct(private string $name, private array $values) { - $this->name = $name; - $this->values = $values; } public function getName(): string @@ -46,30 +36,26 @@ public function getKeys(): array return array_keys($this->values); } - public function offsetExists($offset): bool + public function offsetExists(mixed $offset): bool { return \array_key_exists($offset, $this->values); } - #[ReturnTypeWillChange] - public function offsetGet($offset) + public function offsetGet(mixed $offset): mixed { return $this->values[$offset]; } - public function offsetSet($offset, $value): void + public function offsetSet(mixed $offset, mixed $value): void { $this->values[$offset] = $value; } - public function offsetUnset($offset): void + public function offsetUnset(mixed $offset): void { unset($this->values[$offset]); } - /** - * @return Generator - */ public function getIterator(): Generator { yield from $this->values; diff --git a/src/Knp/DictionaryBundle/Dictionary/Traceable.php b/src/Knp/DictionaryBundle/Dictionary/Traceable.php index ca073197..dbda961d 100644 --- a/src/Knp/DictionaryBundle/Dictionary/Traceable.php +++ b/src/Knp/DictionaryBundle/Dictionary/Traceable.php @@ -6,7 +6,6 @@ use Knp\DictionaryBundle\DataCollector\DictionaryDataCollector; use Knp\DictionaryBundle\Dictionary; -use ReturnTypeWillChange; /** * @template E of mixed @@ -15,23 +14,11 @@ */ final class Traceable implements Dictionary { - /** - * @var Dictionary - */ - private Dictionary $dictionary; - - /** - * @var DictionaryDataCollector - */ - private DictionaryDataCollector $collector; - /** * @param Dictionary $dictionary */ - public function __construct(Dictionary $dictionary, DictionaryDataCollector $collector) + public function __construct(private Dictionary $dictionary, private DictionaryDataCollector $collector) { - $this->dictionary = $dictionary; - $this->collector = $collector; } public function getName(): string @@ -53,29 +40,28 @@ public function getKeys(): array return $this->dictionary->getKeys(); } - public function offsetExists($offset): bool + public function offsetExists(mixed $offset): bool { $this->markAsUsed(); return $this->dictionary->offsetExists($offset); } - #[ReturnTypeWillChange] - public function offsetGet($offset) + public function offsetGet(mixed $offset): mixed { $this->markAsUsed(); return $this->dictionary->offsetGet($offset); } - public function offsetSet($offset, $value): void + public function offsetSet(mixed $offset, mixed $value): void { $this->dictionary->offsetSet($offset, $value); $this->markAsUsed(); } - public function offsetUnset($offset): void + public function offsetUnset(mixed $offset): void { $this->dictionary->offsetUnset($offset); diff --git a/src/Knp/DictionaryBundle/Dictionary/Wrapper.php b/src/Knp/DictionaryBundle/Dictionary/Wrapper.php index 0d2f0f0f..cea0c359 100644 --- a/src/Knp/DictionaryBundle/Dictionary/Wrapper.php +++ b/src/Knp/DictionaryBundle/Dictionary/Wrapper.php @@ -5,7 +5,6 @@ namespace Knp\DictionaryBundle\Dictionary; use Knp\DictionaryBundle\Dictionary; -use ReturnTypeWillChange; /** * @template E @@ -14,17 +13,11 @@ */ abstract class Wrapper implements Dictionary { - /** - * @var Dictionary - */ - private Dictionary $wrapped; - /** * @param Dictionary $wrapped */ - public function __construct(Dictionary $wrapped) + public function __construct(private Dictionary $wrapped) { - $this->wrapped = $wrapped; } public function getName(): string @@ -42,23 +35,22 @@ public function getKeys(): array return $this->wrapped->getKeys(); } - public function offsetExists($offset): bool + public function offsetExists(mixed $offset): bool { return $this->wrapped->offsetExists($offset); } - #[ReturnTypeWillChange] - public function offsetGet($offset) + public function offsetGet(mixed $offset): mixed { return $this->wrapped->offsetGet($offset); } - public function offsetSet($offset, $value): void + public function offsetSet(mixed $offset, mixed $value): void { $this->wrapped->offsetSet($offset, $value); } - public function offsetUnset($offset): void + public function offsetUnset(mixed $offset): void { $this->wrapped->offsetUnset($offset); } diff --git a/src/Knp/DictionaryBundle/Faker/Provider/Dictionary.php b/src/Knp/DictionaryBundle/Faker/Provider/Dictionary.php index 68286b10..4c1b9db5 100644 --- a/src/Knp/DictionaryBundle/Faker/Provider/Dictionary.php +++ b/src/Knp/DictionaryBundle/Faker/Provider/Dictionary.php @@ -10,12 +10,8 @@ final class Dictionary extends Base { - private Collection $dictionaries; - - public function __construct(Collection $dictionaries, Generator $generator = null) + public function __construct(private Collection $dictionaries, Generator $generator = null) { - $this->dictionaries = $dictionaries; - if (null === $generator) { $generator = new Generator(); $generator->addProvider($this); diff --git a/src/Knp/DictionaryBundle/Form/Type/DictionaryType.php b/src/Knp/DictionaryBundle/Form/Type/DictionaryType.php index af49babe..3f73a6bf 100644 --- a/src/Knp/DictionaryBundle/Form/Type/DictionaryType.php +++ b/src/Knp/DictionaryBundle/Form/Type/DictionaryType.php @@ -12,11 +12,8 @@ final class DictionaryType extends AbstractType { - private Collection $dictionaries; - - public function __construct(Collection $dictionaries) + public function __construct(private Collection $dictionaries) { - $this->dictionaries = $dictionaries; } public function configureOptions(OptionsResolver $resolver): void diff --git a/src/Knp/DictionaryBundle/Symfony/SupportedVersion.php b/src/Knp/DictionaryBundle/Symfony/SupportedVersion.php new file mode 100644 index 00000000..14b488a4 --- /dev/null +++ b/src/Knp/DictionaryBundle/Symfony/SupportedVersion.php @@ -0,0 +1,16 @@ +dictionaries = $dictionaries; } /** diff --git a/src/Knp/DictionaryBundle/Validator/Constraints/DictionaryValidator.php b/src/Knp/DictionaryBundle/Validator/Constraints/DictionaryValidator.php index 55b34422..027f6e14 100644 --- a/src/Knp/DictionaryBundle/Validator/Constraints/DictionaryValidator.php +++ b/src/Knp/DictionaryBundle/Validator/Constraints/DictionaryValidator.php @@ -12,17 +12,11 @@ final class DictionaryValidator extends ConstraintValidator { use DictionaryValidator\SymfonyCompatibilityTrait; - private Collection $dictionaries; - - public function __construct(Collection $dictionaries) + public function __construct(private Collection $dictionaries) { - $this->dictionaries = $dictionaries; } - /** - * @param mixed $var - */ - private function varToString($var): string + private function varToString(mixed $var): string { if (null === $var) { return 'null'; @@ -39,8 +33,7 @@ private function varToString($var): string if (\is_float($var)) { return 0.0 === $var ? '0.0' - : (string) $var - ; + : (string) $var; } if (\is_object($var) && method_exists($var, '__toString')) { diff --git a/src/Knp/DictionaryBundle/Validator/Constraints/DictionaryValidator/SymfonyCompatibilityTrait.php b/src/Knp/DictionaryBundle/Validator/Constraints/DictionaryValidator/SymfonyCompatibilityTrait.php index bb9f50f9..5febe2f9 100644 --- a/src/Knp/DictionaryBundle/Validator/Constraints/DictionaryValidator/SymfonyCompatibilityTrait.php +++ b/src/Knp/DictionaryBundle/Validator/Constraints/DictionaryValidator/SymfonyCompatibilityTrait.php @@ -6,6 +6,7 @@ use Composer\InstalledVersions; use Exception; +use Knp\DictionaryBundle\Symfony; use Knp\DictionaryBundle\Validator\Constraints\Dictionary; use Symfony\Component\Form\Exception\UnexpectedTypeException; use Symfony\Component\Validator\Constraint; @@ -14,9 +15,7 @@ default: throw new Exception('knplabs/dictionary-bundle is not compatible with the current version of symfony/validator: '.$version); - case '6.2': - case '6.1': - case '6.0': + case Symfony\SupportedVersion::v5_4: trait SymfonyCompatibilityTrait { public function validate(mixed $value, Constraint $constraint): void @@ -46,10 +45,11 @@ public function validate(mixed $value, Constraint $constraint): void break; - case '5.4': + case Symfony\SupportedVersion::v6_2: + case Symfony\SupportedVersion::v6_3: trait SymfonyCompatibilityTrait { - public function validate($value, Constraint $constraint): void + public function validate(mixed $value, Constraint $constraint): void { if (!$constraint instanceof Dictionary) { throw new UnexpectedTypeException($constraint, Dictionary::class); diff --git a/src/Knp/DictionaryBundle/ValueTransformer.php b/src/Knp/DictionaryBundle/ValueTransformer.php index 9b5674a5..10a0106b 100644 --- a/src/Knp/DictionaryBundle/ValueTransformer.php +++ b/src/Knp/DictionaryBundle/ValueTransformer.php @@ -6,15 +6,10 @@ interface ValueTransformer { - /** - * @param mixed $value - */ - public function supports($value): bool; + public function supports(mixed $value): bool; /** - * @param mixed $value - * * @return mixed */ - public function transform($value); + public function transform(mixed $value); } diff --git a/src/Knp/DictionaryBundle/ValueTransformer/Aggregate.php b/src/Knp/DictionaryBundle/ValueTransformer/Aggregate.php index 32b9379f..a13fbfb1 100644 --- a/src/Knp/DictionaryBundle/ValueTransformer/Aggregate.php +++ b/src/Knp/DictionaryBundle/ValueTransformer/Aggregate.php @@ -18,7 +18,7 @@ public function addTransformer(ValueTransformer $transformer): void $this->transformers[] = $transformer; } - public function supports($value): bool + public function supports(mixed $value): bool { foreach ($this->transformers as $transformer) { if ($transformer->supports($value)) { @@ -29,7 +29,7 @@ public function supports($value): bool return false; } - public function transform($value) + public function transform(mixed $value) { foreach ($this->transformers as $transformer) { if ($transformer->supports($value)) { diff --git a/src/Knp/DictionaryBundle/ValueTransformer/Constant.php b/src/Knp/DictionaryBundle/ValueTransformer/Constant.php index 029631f9..7a009738 100644 --- a/src/Knp/DictionaryBundle/ValueTransformer/Constant.php +++ b/src/Knp/DictionaryBundle/ValueTransformer/Constant.php @@ -12,7 +12,7 @@ final class Constant implements ValueTransformer { private const PATTERN = '/^(?P.*)::(?P.*)$/'; - public function supports($value): bool + public function supports(mixed $value): bool { if (!\is_string($value)) { return false; @@ -35,7 +35,7 @@ public function supports($value): bool return \array_key_exists($matches['constant'], $constants); } - public function transform($value) + public function transform(mixed $value) { if (null === $matches = $this->extract($value)) { throw new Exception("Unable to resolve constant {$value}.");