diff --git a/rules/Php80/Rector/Class_/StringableForToStringRector.php b/rules/Php80/Rector/Class_/StringableForToStringRector.php index e3da2c31b1c4..74d04f4b2037 100644 --- a/rules/Php80/Rector/Class_/StringableForToStringRector.php +++ b/rules/Php80/Rector/Class_/StringableForToStringRector.php @@ -53,6 +53,10 @@ final class StringableForToStringRector extends AbstractRector implements MinPhp * @var string */ private const STRINGABLE = 'Stringable'; + /** + * @var bool + */ + private $hasChanged = \false; public function __construct(FamilyRelationsAnalyzer $familyRelationsAnalyzer, ReturnTypeInferer $returnTypeInferer, ClassAnalyzer $classAnalyzer, BetterNodeFinder $betterNodeFinder) { $this->familyRelationsAnalyzer = $familyRelationsAnalyzer; @@ -105,6 +109,7 @@ public function refactor(Node $node) : ?Node if (!$toStringClassMethod instanceof ClassMethod) { return null; } + $this->hasChanged = \false; // warning, classes that implements __toString() will return Stringable interface even if they don't implemen it // reflection cannot be used for real detection $classLikeAncestorNames = $this->familyRelationsAnalyzer->getClassLikeAncestorNames($node); @@ -116,10 +121,15 @@ public function refactor(Node $node) : ?Node if (!$isAncestorHasStringable) { // add interface $node->implements[] = new FullyQualified(self::STRINGABLE); + $this->hasChanged = \true; } // add return type if ($toStringClassMethod->returnType === null) { $toStringClassMethod->returnType = new Identifier('string'); + $this->hasChanged = \true; + } + if (!$this->hasChanged) { + return null; } return $node; } @@ -132,6 +142,7 @@ private function processNotStringType(ClassMethod $toStringClassMethod) : void if (!$hasReturn) { $emptyStringReturn = new Return_(new String_('')); $toStringClassMethod->stmts[] = $emptyStringReturn; + $this->hasChanged = \true; return; } $this->traverseNodesWithCallable((array) $toStringClassMethod->stmts, function (Node $subNode) { @@ -147,6 +158,7 @@ private function processNotStringType(ClassMethod $toStringClassMethod) : void return null; } $subNode->expr = new CastString_($subNode->expr); + $this->hasChanged = \true; return null; }); } diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index ca4ad7d622e6..464f7e1b027f 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = '319e9f0694be4026734c932a3b6b8c31debdb0f8'; + public const PACKAGE_VERSION = '6aed089476ea0167835fbbdb42d876cddb4c77d4'; /** * @api * @var string */ - public const RELEASE_DATE = '2023-10-05 07:57:38'; + public const RELEASE_DATE = '2023-10-05 08:18:12'; /** * @var int */