> */ public function getNodeTypes() : array { return [\PhpParser\Node\Scalar\String_::class]; } /** * @param String_ $node */ public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node { $kind = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::KIND); if (!\in_array($kind, [\PhpParser\Node\Scalar\String_::KIND_HEREDOC, \PhpParser\Node\Scalar\String_::KIND_NOWDOC], \true)) { return null; } // the doc label is not in the string → ok /** @var string $docLabel */ $docLabel = $node->getAttribute(self::ATTRIBUTE_DOC_LABEL); if (!\RectorPrefix20210528\Nette\Utils\Strings::contains($node->value, $docLabel)) { return null; } $node->setAttribute(self::ATTRIBUTE_DOC_LABEL, $this->uniquateDocLabel($node->value, $docLabel)); // invoke redraw $node->setAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::ORIGINAL_NODE, null); return $node; } private function uniquateDocLabel(string $value, string $docLabel) : string { $docLabel .= self::WRAP_SUFFIX; $docLabelCounterTemplate = $docLabel . '_%d'; $i = 0; while (\RectorPrefix20210528\Nette\Utils\Strings::contains($value, $docLabel)) { $docLabel = \sprintf($docLabelCounterTemplate, ++$i); } return $docLabel; } }