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