decouple replaceColonWithEqualInSymfonyAndDoctrine()

This commit is contained in:
TomasVotruba 2020-06-16 09:54:52 +02:00
parent 5664b58aee
commit 1777d3a444

View File

@ -15,7 +15,6 @@ use Rector\BetterPhpDocParser\Contract\PhpDocNode\TagAwareNodeInterface;
use Rector\BetterPhpDocParser\PhpDocNode\Sensio\SensioRouteTagValueNode;
use Rector\BetterPhpDocParser\PhpDocNode\Symfony\SymfonyRouteTagValueNode;
use Rector\BetterPhpDocParser\Utils\ArrayItemStaticHelper;
use Symfony\Component\Routing\Annotation\Route;
abstract class AbstractTagValueNode implements AttributeAwareNodeInterface, PhpDocTagValueNode
{
@ -151,11 +150,7 @@ abstract class AbstractTagValueNode implements AttributeAwareNodeInterface, PhpD
// cleanup json encoded extra slashes
$json = Strings::replace($json, '#\\\\\\\\#', '\\');
// replace ":" with "=" for @Route
if ($this instanceof SymfonyRouteTagValueNode || $this instanceof DoctrineTagNodeInterface || $this instanceof SensioRouteTagValueNode) {
// @see https://regex101.com/r/XfKi4A/1/
$json = Strings::replace($json, '#(\"|\w)\:(\"|\w)#', '$1=$2');
}
$json = $this->replaceColonWithEqualInSymfonyAndDoctrine($json);
$keyPart = $this->createKeyPart($key);
@ -406,4 +401,24 @@ abstract class AbstractTagValueNode implements AttributeAwareNodeInterface, PhpD
return $this->hasOpeningBracket && $this->hasClosingBracket;
}
/**
* Before:
* (options={"key": "value"})
*
* After:
* (options={"key"="value"})
*
* @see https://github.com/rectorphp/rector/issues/3225
* @see https://github.com/rectorphp/rector/pull/3241
*/
private function replaceColonWithEqualInSymfonyAndDoctrine(string $json): string
{
if (! $this instanceof SymfonyRouteTagValueNode && ! $this instanceof DoctrineTagNodeInterface && ! $this instanceof SensioRouteTagValueNode) {
return $json;
}
// @see https://regex101.com/r/XfKi4A/1/
return Strings::replace($json, '#(\"|\w)\:(\"|\w)#', '$1=$2');
}
}