From 54cb0ecba4f4132eb8fc7842870df30939dfa51a Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 28 Jan 2021 08:57:36 +0700 Subject: [PATCH 01/15] [Symfony 5.2][WIP] Add BuilderSetDataMapperRector --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index a1535eac633a..5078b76bcfce 100644 --- a/composer.json +++ b/composer.json @@ -65,6 +65,7 @@ "phpstan/phpstan-nette": "^0.12.12", "phpunit/phpunit": "^9.5", "sebastian/diff": "^4.0.4", + "symfony/form": "^5.2", "symplify/changelog-linker": "^9.0.34", "symplify/coding-standard": "^9.0.34", "symplify/easy-coding-standard": "^9.0.34", From 3c092e6659b4b7febf146b56a947e95416f47d93 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 28 Jan 2021 08:57:40 +0700 Subject: [PATCH 02/15] [Symfony 5.2][WIP] Add BuilderSetDataMapperRector --- .../MethodCall/BuilderSetDataMapperRector.php | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 rules/symfony5/src/Rector/MethodCall/BuilderSetDataMapperRector.php diff --git a/rules/symfony5/src/Rector/MethodCall/BuilderSetDataMapperRector.php b/rules/symfony5/src/Rector/MethodCall/BuilderSetDataMapperRector.php new file mode 100644 index 000000000000..afbfb2ada3c2 --- /dev/null +++ b/rules/symfony5/src/Rector/MethodCall/BuilderSetDataMapperRector.php @@ -0,0 +1,82 @@ +setDataMapper(new PropertyPathMapper()) to Builder->setDataMapper(new DataMapper(new PropertyPathAccessor()))', + [ + new CodeSample( + <<<'CODE_SAMPLE' +use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper; + +class SomeClass +{ + public function run(FormConfigBuilderInterface $builder) + { + $builder->setDataMapper(new PropertyPathMapper()); + } +} +CODE_SAMPLE + , + <<<'CODE_SAMPLE' +use Symfony\Component\Form\Extension\Core\DataAccessor\PropertyPathAccessor; +use Symfony\Component\Form\Extension\Core\DataMapper\DataMapper; + +class SomeClass +{ + public function run(FormConfigBuilderInterface $builder) + { + $builder->setDataMapper(new DataMapper(new PropertyPathAccessor())); + } +} +CODE_SAMPLE + ), + ]); + } + + /** + * @return string[] + */ + public function getNodeTypes(): array + { + return [MethodCall::class]; + } + + /** + * @param MethodCall $node + */ + public function refactor(Node $node): ?Node + { + if (! $this->isObjectType($node->var, self::REQUIRED_TYPE)) { + return null; + } + + if (! $this->isName($node->name, 'setDataMapper')) { + return null; + } + + return $node; + } +} From 8260ec32cc56d8be46b6cf697e42e55ab9c9d411 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 28 Jan 2021 08:59:42 +0700 Subject: [PATCH 03/15] [Symfony 5.2][WIP] Add BuilderSetDataMapperRector --- ...ataMapperRector.php => FormBuilderSetDataMapperRector.php} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename rules/symfony5/src/Rector/MethodCall/{BuilderSetDataMapperRector.php => FormBuilderSetDataMapperRector.php} (91%) diff --git a/rules/symfony5/src/Rector/MethodCall/BuilderSetDataMapperRector.php b/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php similarity index 91% rename from rules/symfony5/src/Rector/MethodCall/BuilderSetDataMapperRector.php rename to rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php index afbfb2ada3c2..373b8e94336f 100644 --- a/rules/symfony5/src/Rector/MethodCall/BuilderSetDataMapperRector.php +++ b/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php @@ -13,9 +13,9 @@ /** * @see https://github.com/symfony/symfony/commit/878effaf47cfb23f73c984d806eb8e9d9206cb5c - * @see \Rector\Symfony5\Tests\Rector\MethodCall\BuilderSetDataMapperRector\BuilderSetDataMapperRectorTest + * @see \Rector\Symfony5\Tests\Rector\MethodCall\FormBuilderSetDataMapperRector\FormBuilderSetDataMapperRectorTest */ -final class BuilderSetDataMapperRector extends AbstractRector +final class FormBuilderSetDataMapperRector extends AbstractRector { /** * @var class-string[] From 0089d856277684885c0c5845cb74d0fecd01eb01 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 28 Jan 2021 10:09:24 +0700 Subject: [PATCH 04/15] skip not form builder test --- .../FormBuilderSetDataMapperRector.php | 2 +- .../Fixture/skip_not_form_builder.php.inc | 12 +++++++ .../FormBuilderSetDataMapperRectorTest.php | 31 +++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 rules/symfony5/tests/Rector/MethodCall/FormBuilderSetDataMapperRector/Fixture/skip_not_form_builder.php.inc create mode 100644 rules/symfony5/tests/Rector/MethodCall/FormBuilderSetDataMapperRector/FormBuilderSetDataMapperRectorTest.php diff --git a/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php b/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php index 373b8e94336f..536c89642633 100644 --- a/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php +++ b/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php @@ -20,7 +20,7 @@ final class FormBuilderSetDataMapperRector extends AbstractRector /** * @var class-string[] */ - private const REQUIRED_TYPE = [FormConfigBuilderInterface::class]; + private const REQUIRED_TYPE = FormConfigBuilderInterface::class; public function getRuleDefinition(): RuleDefinition { diff --git a/rules/symfony5/tests/Rector/MethodCall/FormBuilderSetDataMapperRector/Fixture/skip_not_form_builder.php.inc b/rules/symfony5/tests/Rector/MethodCall/FormBuilderSetDataMapperRector/Fixture/skip_not_form_builder.php.inc new file mode 100644 index 000000000000..7bf425394f86 --- /dev/null +++ b/rules/symfony5/tests/Rector/MethodCall/FormBuilderSetDataMapperRector/Fixture/skip_not_form_builder.php.inc @@ -0,0 +1,12 @@ +format('Y-m-d'); + } +} diff --git a/rules/symfony5/tests/Rector/MethodCall/FormBuilderSetDataMapperRector/FormBuilderSetDataMapperRectorTest.php b/rules/symfony5/tests/Rector/MethodCall/FormBuilderSetDataMapperRector/FormBuilderSetDataMapperRectorTest.php new file mode 100644 index 000000000000..9264adf3b692 --- /dev/null +++ b/rules/symfony5/tests/Rector/MethodCall/FormBuilderSetDataMapperRector/FormBuilderSetDataMapperRectorTest.php @@ -0,0 +1,31 @@ +doTestFileInfo($fileInfo); + } + + public function provideData(): Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + protected function getRectorClass(): string + { + return FormBuilderSetDataMapperRector::class; + } +} From b6f34257b5167a3301820062154ea1d2b7b8bc99 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 28 Jan 2021 10:11:59 +0700 Subject: [PATCH 05/15] skip not set datamapper call --- composer.json | 1 - .../MethodCall/FormBuilderSetDataMapperRector.php | 2 ++ .../Fixture/skip_not_set_datamapper.php.inc | 13 +++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 rules/symfony5/tests/Rector/MethodCall/FormBuilderSetDataMapperRector/Fixture/skip_not_set_datamapper.php.inc diff --git a/composer.json b/composer.json index 5078b76bcfce..4388965acbaf 100644 --- a/composer.json +++ b/composer.json @@ -59,7 +59,6 @@ "friendsofphp/php-cs-fixer": "^2.17.3", "nette/application": "^3.0.7", "nette/di": "^3.0", - "nette/forms": "^3.0", "ocramius/package-versions": "^1.9", "php-parallel-lint/php-parallel-lint": "^1.2", "phpstan/phpstan-nette": "^0.12.12", diff --git a/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php b/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php index 536c89642633..3a7220caafd4 100644 --- a/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php +++ b/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php @@ -30,6 +30,7 @@ public function getRuleDefinition(): RuleDefinition new CodeSample( <<<'CODE_SAMPLE' use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper; +use Symfony\Component\Form\FormConfigBuilderInterface; class SomeClass { @@ -43,6 +44,7 @@ public function run(FormConfigBuilderInterface $builder) <<<'CODE_SAMPLE' use Symfony\Component\Form\Extension\Core\DataAccessor\PropertyPathAccessor; use Symfony\Component\Form\Extension\Core\DataMapper\DataMapper; +use Symfony\Component\Form\FormConfigBuilderInterface; class SomeClass { diff --git a/rules/symfony5/tests/Rector/MethodCall/FormBuilderSetDataMapperRector/Fixture/skip_not_set_datamapper.php.inc b/rules/symfony5/tests/Rector/MethodCall/FormBuilderSetDataMapperRector/Fixture/skip_not_set_datamapper.php.inc new file mode 100644 index 000000000000..abc59059fa9e --- /dev/null +++ b/rules/symfony5/tests/Rector/MethodCall/FormBuilderSetDataMapperRector/Fixture/skip_not_set_datamapper.php.inc @@ -0,0 +1,13 @@ +foo(); + } +} From 8b8d4ff70c0bbd821d02633c3caabb5b4737a9ea Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 28 Jan 2021 10:15:56 +0700 Subject: [PATCH 06/15] fixture to replace arg --- .../Fixture/fixture.php.inc | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 rules/symfony5/tests/Rector/MethodCall/FormBuilderSetDataMapperRector/Fixture/fixture.php.inc diff --git a/rules/symfony5/tests/Rector/MethodCall/FormBuilderSetDataMapperRector/Fixture/fixture.php.inc b/rules/symfony5/tests/Rector/MethodCall/FormBuilderSetDataMapperRector/Fixture/fixture.php.inc new file mode 100644 index 000000000000..c3b25b37704b --- /dev/null +++ b/rules/symfony5/tests/Rector/MethodCall/FormBuilderSetDataMapperRector/Fixture/fixture.php.inc @@ -0,0 +1,29 @@ +setDataMapper(new PropertyPathMapper()); + } +} +----- +setDataMapper(new \Symfony\Component\Form\Extension\Core\DataMapper\DataMapper(new \Symfony\Component\Form\Extension\Core\DataAccessor\PropertyPathAccessor())); + } +} \ No newline at end of file From 03921af20bb277a0ef75e295fceb31670cf71f19 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 28 Jan 2021 10:20:08 +0700 Subject: [PATCH 07/15] skip correct arg type --- .../MethodCall/FormBuilderSetDataMapperRector.php | 11 +++++++++++ .../Fixture/skip_correct_arg.php.inc | 14 ++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 rules/symfony5/tests/Rector/MethodCall/FormBuilderSetDataMapperRector/Fixture/skip_correct_arg.php.inc diff --git a/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php b/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php index 3a7220caafd4..ade3dc05f4c7 100644 --- a/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php +++ b/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php @@ -10,6 +10,7 @@ use Symfony\Component\Form\FormConfigBuilderInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; +use Symfony\Component\Form\Extension\Core\DataMapper\DataMapper; /** * @see https://github.com/symfony/symfony/commit/878effaf47cfb23f73c984d806eb8e9d9206cb5c @@ -22,6 +23,11 @@ final class FormBuilderSetDataMapperRector extends AbstractRector */ private const REQUIRED_TYPE = FormConfigBuilderInterface::class; + /** + * @var class-string[] + */ + private const ARG_CORRECT_TYPE = DataMapper::class; + public function getRuleDefinition(): RuleDefinition { return new RuleDefinition( @@ -79,6 +85,11 @@ public function refactor(Node $node): ?Node return null; } + $argValue = $node->args[0]->value; + if (! $this->isObjectType($argValue, self::ARG_CORRECT_TYPE)) { + return null; + } + return $node; } } diff --git a/rules/symfony5/tests/Rector/MethodCall/FormBuilderSetDataMapperRector/Fixture/skip_correct_arg.php.inc b/rules/symfony5/tests/Rector/MethodCall/FormBuilderSetDataMapperRector/Fixture/skip_correct_arg.php.inc new file mode 100644 index 000000000000..86148a7c2384 --- /dev/null +++ b/rules/symfony5/tests/Rector/MethodCall/FormBuilderSetDataMapperRector/Fixture/skip_correct_arg.php.inc @@ -0,0 +1,14 @@ +setDataMapper(new \Symfony\Component\Form\Extension\Core\DataMapper\DataMapper(new \Symfony\Component\Form\Extension\Core\DataAccessor\PropertyPathAccessor())); + } +} \ No newline at end of file From 051c3e4bd7f9fe8c1a4de7f9a44087c31af4545d Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 28 Jan 2021 10:35:23 +0700 Subject: [PATCH 08/15] try create new inside new --- .../MethodCall/FormBuilderSetDataMapperRector.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php b/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php index ade3dc05f4c7..490ddc205ca7 100644 --- a/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php +++ b/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php @@ -5,12 +5,16 @@ namespace Rector\Symfony5\Rector\MethodCall; use PhpParser\Node; +use PhpParser\Node\Arg; use PhpParser\Node\Expr\MethodCall; use Rector\Core\Rector\AbstractRector; use Symfony\Component\Form\FormConfigBuilderInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; use Symfony\Component\Form\Extension\Core\DataMapper\DataMapper; +use PhpParser\Node\Expr\New_; +use PhpParser\Node\Name\FullyQualified; +use Symfony\Component\Form\Extension\Core\DataAccessor\PropertyPathAccessor; /** * @see https://github.com/symfony/symfony/commit/878effaf47cfb23f73c984d806eb8e9d9206cb5c @@ -85,11 +89,18 @@ public function refactor(Node $node): ?Node return null; } - $argValue = $node->args[0]->value; - if (! $this->isObjectType($argValue, self::ARG_CORRECT_TYPE)) { + $argumentValue = $node->args[0]->value; + if (! $this->isObjectType($argumentValue, self::ARG_CORRECT_TYPE)) { return null; } + $dataMapperArgumentValue = new New_( + new FullyQualified(PropertyPathAccessor::class) + ); + + $newArgumentValue = new New_(new FullyQualified(DataMapper::class), [new Arg($dataMapperArgumentValue)]); + $node->args[0]->value = $newArgumentValue; + return $node; } } From 75a75a12737bfc42a2b42916718e04ac73783e35 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 28 Jan 2021 11:21:38 +0700 Subject: [PATCH 09/15] functional --- .../FormBuilderSetDataMapperRector.php | 21 ++++++++----------- .../Fixture/skip_correct_arg.php.inc | 3 ++- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php b/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php index 490ddc205ca7..93f1dd526330 100644 --- a/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php +++ b/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php @@ -7,14 +7,14 @@ use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\Expr\MethodCall; +use PhpParser\Node\Expr\New_; +use PhpParser\Node\Name\FullyQualified; use Rector\Core\Rector\AbstractRector; +use Symfony\Component\Form\Extension\Core\DataAccessor\PropertyPathAccessor; +use Symfony\Component\Form\Extension\Core\DataMapper\DataMapper; use Symfony\Component\Form\FormConfigBuilderInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; -use Symfony\Component\Form\Extension\Core\DataMapper\DataMapper; -use PhpParser\Node\Expr\New_; -use PhpParser\Node\Name\FullyQualified; -use Symfony\Component\Form\Extension\Core\DataAccessor\PropertyPathAccessor; /** * @see https://github.com/symfony/symfony/commit/878effaf47cfb23f73c984d806eb8e9d9206cb5c @@ -52,15 +52,14 @@ public function run(FormConfigBuilderInterface $builder) CODE_SAMPLE , <<<'CODE_SAMPLE' -use Symfony\Component\Form\Extension\Core\DataAccessor\PropertyPathAccessor; -use Symfony\Component\Form\Extension\Core\DataMapper\DataMapper; +use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper; use Symfony\Component\Form\FormConfigBuilderInterface; class SomeClass { public function run(FormConfigBuilderInterface $builder) { - $builder->setDataMapper(new DataMapper(new PropertyPathAccessor())); + $builder->setDataMapper(new \Symfony\Component\Form\Extension\Core\DataMapper\DataMapper(new \Symfony\Component\Form\Extension\Core\DataAccessor\PropertyPathAccessor())); } } CODE_SAMPLE @@ -90,15 +89,13 @@ public function refactor(Node $node): ?Node } $argumentValue = $node->args[0]->value; - if (! $this->isObjectType($argumentValue, self::ARG_CORRECT_TYPE)) { + if ($this->isObjectType($argumentValue, self::ARG_CORRECT_TYPE)) { return null; } - $dataMapperArgumentValue = new New_( - new FullyQualified(PropertyPathAccessor::class) - ); + $propertyPathAccessor = new New_(new FullyQualified(PropertyPathAccessor::class)); - $newArgumentValue = new New_(new FullyQualified(DataMapper::class), [new Arg($dataMapperArgumentValue)]); + $newArgumentValue = new New_(new FullyQualified(DataMapper::class), [new Arg($propertyPathAccessor)]); $node->args[0]->value = $newArgumentValue; return $node; diff --git a/rules/symfony5/tests/Rector/MethodCall/FormBuilderSetDataMapperRector/Fixture/skip_correct_arg.php.inc b/rules/symfony5/tests/Rector/MethodCall/FormBuilderSetDataMapperRector/Fixture/skip_correct_arg.php.inc index 86148a7c2384..55a8f673bfcb 100644 --- a/rules/symfony5/tests/Rector/MethodCall/FormBuilderSetDataMapperRector/Fixture/skip_correct_arg.php.inc +++ b/rules/symfony5/tests/Rector/MethodCall/FormBuilderSetDataMapperRector/Fixture/skip_correct_arg.php.inc @@ -9,6 +9,7 @@ class SkipCorrectArg { public function run(FormConfigBuilderInterface $builder) { - $builder->setDataMapper(new \Symfony\Component\Form\Extension\Core\DataMapper\DataMapper(new \Symfony\Component\Form\Extension\Core\DataAccessor\PropertyPathAccessor())); + $propertyPathAccessor = new \Symfony\Component\Form\Extension\Core\DataAccessor\PropertyPathAccessor(); + $builder->setDataMapper(new \Symfony\Component\Form\Extension\Core\DataMapper\DataMapper($propertyPathAccessor)); } } \ No newline at end of file From 6247c4096c5f77f81148b2658c7f8de6d65507f8 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 28 Jan 2021 11:23:27 +0700 Subject: [PATCH 10/15] fix --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4388965acbaf..a1535eac633a 100644 --- a/composer.json +++ b/composer.json @@ -59,12 +59,12 @@ "friendsofphp/php-cs-fixer": "^2.17.3", "nette/application": "^3.0.7", "nette/di": "^3.0", + "nette/forms": "^3.0", "ocramius/package-versions": "^1.9", "php-parallel-lint/php-parallel-lint": "^1.2", "phpstan/phpstan-nette": "^0.12.12", "phpunit/phpunit": "^9.5", "sebastian/diff": "^4.0.4", - "symfony/form": "^5.2", "symplify/changelog-linker": "^9.0.34", "symplify/coding-standard": "^9.0.34", "symplify/easy-coding-standard": "^9.0.34", From 44d79f9006c33cf1b28db3fb52cfaa173144234e Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 28 Jan 2021 11:26:25 +0700 Subject: [PATCH 11/15] register to symfony 52 set --- config/set/symfony52.php | 4 ++++ .../src/Rector/MethodCall/FormBuilderSetDataMapperRector.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/config/set/symfony52.php b/config/set/symfony52.php index 1cd4ccc1daba..3253542eb92c 100644 --- a/config/set/symfony52.php +++ b/config/set/symfony52.php @@ -7,6 +7,7 @@ use Rector\Renaming\ValueObject\MethodCallRename; use Rector\Renaming\ValueObject\RenameClassAndConstFetch; use Rector\Symfony5\Rector\MethodCall\DefinitionAliasSetPrivateToSetPublicRector; +use Rector\Symfony5\Rector\MethodCall\FormBuilderSetDataMapperRector; use Rector\Symfony5\Rector\MethodCall\ReflectionExtractorEnableMagicCallExtractorRector; use Rector\Symfony5\Rector\New_\PropertyAccessorCreationBooleanToFlagsRector; use Rector\Symfony5\Rector\New_\PropertyPathMapperToDataMapperRector; @@ -112,4 +113,7 @@ # https://github.com/symfony/symfony/blob/5.x/UPGRADE-5.2.md#dependencyinjection $services->set(DefinitionAliasSetPrivateToSetPublicRector::class); + + # https://github.com/symfony/symfony/blob/5.x/UPGRADE-5.2.md#form + $services->set(FormBuilderSetDataMapperRector::class); }; diff --git a/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php b/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php index 93f1dd526330..6c7903499c05 100644 --- a/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php +++ b/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php @@ -17,7 +17,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** - * @see https://github.com/symfony/symfony/commit/878effaf47cfb23f73c984d806eb8e9d9206cb5c + * @see https://github.com/symfony/symfony/blob/5.x/UPGRADE-5.2.md#form * @see \Rector\Symfony5\Tests\Rector\MethodCall\FormBuilderSetDataMapperRector\FormBuilderSetDataMapperRectorTest */ final class FormBuilderSetDataMapperRector extends AbstractRector From 9534d779fb4c5958de0f7056555b10affeac059b Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 28 Jan 2021 11:38:11 +0700 Subject: [PATCH 12/15] phpstan --- .../FormBuilderSetDataMapperRector.php | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php b/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php index 6c7903499c05..8ae4904e1a06 100644 --- a/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php +++ b/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php @@ -10,9 +10,6 @@ use PhpParser\Node\Expr\New_; use PhpParser\Node\Name\FullyQualified; use Rector\Core\Rector\AbstractRector; -use Symfony\Component\Form\Extension\Core\DataAccessor\PropertyPathAccessor; -use Symfony\Component\Form\Extension\Core\DataMapper\DataMapper; -use Symfony\Component\Form\FormConfigBuilderInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -23,14 +20,19 @@ final class FormBuilderSetDataMapperRector extends AbstractRector { /** - * @var class-string[] + * @var string[] */ - private const REQUIRED_TYPE = FormConfigBuilderInterface::class; + private const REQUIRED_TYPE = 'Symfony\Component\Form\FormConfigBuilderInterface'; /** - * @var class-string[] + * @var string[] */ - private const ARG_CORRECT_TYPE = DataMapper::class; + private const ARG_CORRECT_TYPE = 'Symfony\Component\Form\Extension\Core\DataMapper\DataMapper'; + + /** + * @var string[] + */ + private const ARG_MAPPER_TYPE = 'Symfony\Component\Form\Extension\Core\DataAccessor\PropertyPathAccessor'; public function getRuleDefinition(): RuleDefinition { @@ -93,9 +95,8 @@ public function refactor(Node $node): ?Node return null; } - $propertyPathAccessor = new New_(new FullyQualified(PropertyPathAccessor::class)); - - $newArgumentValue = new New_(new FullyQualified(DataMapper::class), [new Arg($propertyPathAccessor)]); + $propertyPathAccessor = new New_(new FullyQualified(self::ARG_MAPPER_TYPE)); + $newArgumentValue = new New_(new FullyQualified(self::ARG_CORRECT_TYPE), [new Arg($propertyPathAccessor)]); $node->args[0]->value = $newArgumentValue; return $node; From 82d7a611c64daea8811984d3c937559c1c325f32 Mon Sep 17 00:00:00 2001 From: rector-bot Date: Thu, 28 Jan 2021 07:55:07 +0000 Subject: [PATCH 13/15] [ci-review] Rector Rectify --- .../Rector/MethodCall/FormBuilderSetDataMapperRector.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php b/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php index 8ae4904e1a06..dc7f0dc996a8 100644 --- a/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php +++ b/rules/symfony5/src/Rector/MethodCall/FormBuilderSetDataMapperRector.php @@ -20,17 +20,17 @@ final class FormBuilderSetDataMapperRector extends AbstractRector { /** - * @var string[] + * @var string */ private const REQUIRED_TYPE = 'Symfony\Component\Form\FormConfigBuilderInterface'; /** - * @var string[] + * @var string */ private const ARG_CORRECT_TYPE = 'Symfony\Component\Form\Extension\Core\DataMapper\DataMapper'; /** - * @var string[] + * @var string */ private const ARG_MAPPER_TYPE = 'Symfony\Component\Form\Extension\Core\DataAccessor\PropertyPathAccessor'; From 6003afb82f8784aee7de0d0a10c2f6cb2e3875bd Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 28 Jan 2021 15:07:45 +0700 Subject: [PATCH 14/15] try using exact phpstan version 0.12.69 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a1535eac633a..f9c6cd79e070 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "nette/utils": "^3.2", "nikic/php-parser": "^4.10.4", "phpstan/phpdoc-parser": "^0.4.9", - "phpstan/phpstan": "^0.12.64", + "phpstan/phpstan": "0.12.69", "phpstan/phpstan-phpunit": "^0.12.17", "psr/simple-cache": "^1.0", "sebastian/diff": "^4.0", From 369e92c5cb2f863cfa7fec03b6dd325f1c903366 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 28 Jan 2021 18:40:11 +0700 Subject: [PATCH 15/15] fallback to last working phpstan, ref https://github.com/symplify/symplify/pull/2876/commits/6f39bb860f35fc8e79c888b70394f816c7749f46 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f9c6cd79e070..b115a92a1d7b 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "nette/utils": "^3.2", "nikic/php-parser": "^4.10.4", "phpstan/phpdoc-parser": "^0.4.9", - "phpstan/phpstan": "0.12.69", + "phpstan/phpstan": "^0.12.64, <0.12.70", "phpstan/phpstan-phpunit": "^0.12.17", "psr/simple-cache": "^1.0", "sebastian/diff": "^4.0",