From 0685eb93a39bca7307214da0f004c0632cbe14b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Werner=20Krau=C3=9F?= Date: Tue, 19 Sep 2023 16:53:55 +0200 Subject: [PATCH] fix failing tests for rector 0.18.3 --- src/Rector/Misc/AddConfigPropertiesRector.php | 18 ++++++++++++------ .../{already_set.php.inc => nothingtodo.inc} | 4 ++-- 2 files changed, 14 insertions(+), 8 deletions(-) rename tests/Misc/AddConfigPropertiesRector/Fixture/{already_set.php.inc => nothingtodo.inc} (81%) diff --git a/src/Rector/Misc/AddConfigPropertiesRector.php b/src/Rector/Misc/AddConfigPropertiesRector.php index 5a7e967..d4fe6de 100644 --- a/src/Rector/Misc/AddConfigPropertiesRector.php +++ b/src/Rector/Misc/AddConfigPropertiesRector.php @@ -7,13 +7,13 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTextNode; use PHPStan\Type\ObjectType; use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger; +use Rector\Comments\NodeDocBlock\DocBlockUpdater; use Rector\Core\Contract\Rector\ConfigurableRectorInterface; use SilverStripe\Admin\LeftAndMain; use SilverStripe\Admin\ModelAdmin; use SilverStripe\Control\Controller; use SilverStripe\Core\Extensible; use SilverStripe\ORM\DataObject; -use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -22,6 +22,12 @@ class AddConfigPropertiesRector extends \Rector\Core\Rector\AbstractRector imple private PhpDocTypeChanger $phpDocTypeChanger; + /** + * @readonly + * @var \Rector\Comments\NodeDocBlock\DocBlockUpdater + */ + private $docBlockUpdater; + /** * @var array|mixed[] */ @@ -109,9 +115,10 @@ class AddConfigPropertiesRector extends \Rector\Core\Rector\AbstractRector imple ], ]; - public function __construct(PhpDocTypeChanger $phpDocTypeChanger) + public function __construct(PhpDocTypeChanger $phpDocTypeChanger, DocBlockUpdater $docBlockUpdater) { $this->phpDocTypeChanger = $phpDocTypeChanger; + $this->docBlockUpdater = $docBlockUpdater; } /** @@ -161,7 +168,7 @@ public function getNodeTypes(): array public function refactor(Node $node): ?Node { $config = $this->getConfig(); - $this->nodeIsChanged = false; + $this->nodeIsChanged = \false; foreach ($config as $className => $configProperties) { if (!$this->isObjectType($node, new ObjectType($className))) { @@ -195,10 +202,9 @@ private function checkConfigProperties(Node $node, array $configProperties): Nod } $phpDocInfo->addPhpDocTagNode(new PhpDocTextNode('@config')); + $this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($property); - if ($phpDocInfo->hasChanged()) { - $this->nodeIsChanged = true; - } + $this->nodeIsChanged = \true; } return $node; diff --git a/tests/Misc/AddConfigPropertiesRector/Fixture/already_set.php.inc b/tests/Misc/AddConfigPropertiesRector/Fixture/nothingtodo.inc similarity index 81% rename from tests/Misc/AddConfigPropertiesRector/Fixture/already_set.php.inc rename to tests/Misc/AddConfigPropertiesRector/Fixture/nothingtodo.inc index 25bfa64..89e3602 100644 --- a/tests/Misc/AddConfigPropertiesRector/Fixture/already_set.php.inc +++ b/tests/Misc/AddConfigPropertiesRector/Fixture/nothingtodo.inc @@ -2,7 +2,7 @@ namespace Netwerkstatt\SilverstripeRector\Tests\Misc\AddConfigPropertiesRector\Fixture; -class SomeGoodClass extends \SilverStripe\ORM\DataObject +class ClassWithAnnotations extends \SilverStripe\ORM\DataObject { /** * @config @@ -23,7 +23,7 @@ class SomeGoodClass extends \SilverStripe\ORM\DataObject namespace Netwerkstatt\SilverstripeRector\Tests\Misc\AddConfigPropertiesRector\Fixture; -class SomeGoodClass extends \SilverStripe\ORM\DataObject +class ClassWithAnnotations extends \SilverStripe\ORM\DataObject { /** * @config