Updated Rector to commit 897cdda68d73ed5fcc1c768219207ff54c8459cb

897cdda68d Apply coding standard (#4047)
This commit is contained in:
Tomas Votruba 2023-06-02 10:03:55 +00:00
parent 3dc5be2274
commit 9eed15ece9
27 changed files with 159 additions and 83 deletions

View File

@ -3,7 +3,6 @@
declare (strict_types=1);
namespace Rector\BetterPhpDocParser\PhpDoc;
use PhpParser\Node\Scalar\String_;
use PHPStan\PhpDocParser\Ast\NodeAttributes;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
use Stringable;

View File

@ -117,12 +117,12 @@ abstract class AbstractValuesAwareNode implements PhpDocTagValueNode
}
return $itemContents;
}
private function isValueKeyEquals(ArrayItemNode $value, string $desiredKey) : bool
private function isValueKeyEquals(ArrayItemNode $arrayItemNode, string $desiredKey) : bool
{
if ($value->key instanceof StringNode) {
return $value->key->value === $desiredKey;
if ($arrayItemNode->key instanceof StringNode) {
return $arrayItemNode->key->value === $desiredKey;
}
return $value->key === $desiredKey;
return $arrayItemNode->key === $desiredKey;
}
/**
* @param mixed $value

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '92ff716761e19c7f30bd68065af7eeefac0480de';
public const PACKAGE_VERSION = '897cdda68d73ed5fcc1c768219207ff54c8459cb';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-06-02 10:38:22';
public const RELEASE_DATE = '2023-06-02 11:00:00';
/**
* @var int
*/

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInitcf48d20d0276ea83626472d23bf244a0::getLoader();
return ComposerAutoloaderInit1d9bd30edaf60f0968a6ac6add7989f5::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitcf48d20d0276ea83626472d23bf244a0
class ComposerAutoloaderInit1d9bd30edaf60f0968a6ac6add7989f5
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInitcf48d20d0276ea83626472d23bf244a0
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitcf48d20d0276ea83626472d23bf244a0', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit1d9bd30edaf60f0968a6ac6add7989f5', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInitcf48d20d0276ea83626472d23bf244a0', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit1d9bd30edaf60f0968a6ac6add7989f5', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitcf48d20d0276ea83626472d23bf244a0::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit1d9bd30edaf60f0968a6ac6add7989f5::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInitcf48d20d0276ea83626472d23bf244a0::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInit1d9bd30edaf60f0968a6ac6add7989f5::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInitcf48d20d0276ea83626472d23bf244a0
class ComposerStaticInit1d9bd30edaf60f0968a6ac6add7989f5
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -3068,9 +3068,9 @@ class ComposerStaticInitcf48d20d0276ea83626472d23bf244a0
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitcf48d20d0276ea83626472d23bf244a0::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitcf48d20d0276ea83626472d23bf244a0::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitcf48d20d0276ea83626472d23bf244a0::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit1d9bd30edaf60f0968a6ac6add7989f5::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit1d9bd30edaf60f0968a6ac6add7989f5::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit1d9bd30edaf60f0968a6ac6add7989f5::$classMap;
}, null, ClassLoader::class);
}

View File

@ -1856,12 +1856,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-doctrine.git",
"reference": "7f0656f46f812aa55b6975ceed0ec1db2642387d"
"reference": "3b10c4bb9df3fb0e5b9dcf15b77ad92c9aa03621"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/7f0656f46f812aa55b6975ceed0ec1db2642387d",
"reference": "7f0656f46f812aa55b6975ceed0ec1db2642387d",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/3b10c4bb9df3fb0e5b9dcf15b77ad92c9aa03621",
"reference": "3b10c4bb9df3fb0e5b9dcf15b77ad92c9aa03621",
"shasum": ""
},
"require": {
@ -1883,10 +1883,10 @@
"symplify\/phpstan-rules": "^11.1",
"symplify\/rule-doc-generator": "^11.1",
"symplify\/vendor-patches": "^11.1",
"tomasvotruba\/type-coverage": "^0.2.0",
"tomasvotruba\/unused-public": "^0.1.10"
"tomasvotruba\/type-coverage": "^0.2",
"tomasvotruba\/unused-public": "^0.1"
},
"time": "2023-05-29T19:29:27+00:00",
"time": "2023-06-02T09:48:50+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {
@ -2060,12 +2060,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
"reference": "13f7cc4888f1e318766ceb2212a1dc0a31012b41"
"reference": "5c0d61c8c0563057f01cf88998465e480d536747"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/13f7cc4888f1e318766ceb2212a1dc0a31012b41",
"reference": "13f7cc4888f1e318766ceb2212a1dc0a31012b41",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/5c0d61c8c0563057f01cf88998465e480d536747",
"reference": "5c0d61c8c0563057f01cf88998465e480d536747",
"shasum": ""
},
"require": {
@ -2085,17 +2085,17 @@
"symfony\/security-core": "^6.2",
"symfony\/security-http": "^6.1",
"symfony\/validator": "^6.2",
"symplify\/easy-ci": "^11.1",
"symplify\/easy-ci": "^11.2",
"symplify\/easy-coding-standard": "^11.2",
"symplify\/phpstan-extensions": "^11.1",
"symplify\/phpstan-rules": "^11.2",
"symplify\/rule-doc-generator": "^11.2",
"symplify\/vendor-patches": "^11.2",
"tomasvotruba\/cognitive-complexity": "^0.0.5",
"tomasvotruba\/type-coverage": "^0.0.9",
"tomasvotruba\/unused-public": "^0.0.34"
"tomasvotruba\/cognitive-complexity": "^0.1",
"tomasvotruba\/type-coverage": "^0.2",
"tomasvotruba\/unused-public": "^0.1"
},
"time": "2023-06-01T16:05:52+00:00",
"time": "2023-06-02T09:45:32+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
*/
final class GeneratedConfig
{
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 7f0656f'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 7e64cfd'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main b980109'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 13f7cc4'));
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 3b10c4b'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 7e64cfd'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main b980109'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 5c0d61c'));
private function __construct()
{
}

View File

@ -22,8 +22,8 @@
"symplify\/vendor-patches": "^11.1",
"rector\/rector-generator": "^0.6",
"symplify\/easy-ci": "^11.2",
"tomasvotruba\/unused-public": "^0.1.10",
"tomasvotruba\/type-coverage": "^0.2.0"
"tomasvotruba\/unused-public": "^0.1",
"tomasvotruba\/type-coverage": "^0.2"
},
"autoload": {
"psr-4": {

View File

@ -3,13 +3,13 @@
declare (strict_types=1);
namespace Rector\Doctrine\NodeFactory;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Property;
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
use Rector\BetterPhpDocParser\PhpDoc\SpacelessPhpDocTagNode;
use Rector\BetterPhpDocParser\PhpDoc\StringNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Core\PhpParser\Node\NodeFactory;
final class EntityIdNodeFactory
@ -45,8 +45,8 @@ final class EntityIdNodeFactory
// add @ORM\Id
$phpDocTagNodes = [];
$phpDocTagNodes[] = new SpacelessPhpDocTagNode('@ORM\\Id', new DoctrineAnnotationTagValueNode(new IdentifierTypeNode('Doctrine\\ORM\\Mapping\\Id'), null, []));
$phpDocTagNodes[] = new SpacelessPhpDocTagNode('@ORM\\Column', new DoctrineAnnotationTagValueNode(new IdentifierTypeNode('Doctrine\\ORM\\Mapping\\Column'), null, [new ArrayItemNode('integer', 'type', String_::KIND_DOUBLE_QUOTED)]));
$phpDocTagNodes[] = new SpacelessPhpDocTagNode('@ORM\\GeneratedValue', new DoctrineAnnotationTagValueNode(new IdentifierTypeNode('Doctrine\\ORM\\Mapping\\GeneratedValue'), null, [new ArrayItemNode('AUTO', 'strategy', String_::KIND_DOUBLE_QUOTED)]));
$phpDocTagNodes[] = new SpacelessPhpDocTagNode('@ORM\\Column', new DoctrineAnnotationTagValueNode(new IdentifierTypeNode('Doctrine\\ORM\\Mapping\\Column'), null, [new ArrayItemNode(new StringNode('integer'), 'type')]));
$phpDocTagNodes[] = new SpacelessPhpDocTagNode('@ORM\\GeneratedValue', new DoctrineAnnotationTagValueNode(new IdentifierTypeNode('Doctrine\\ORM\\Mapping\\GeneratedValue'), null, [new ArrayItemNode(new StringNode('AUTO'), 'strategy')]));
foreach ($phpDocTagNodes as $phpDocTagNode) {
$phpDocInfo->addPhpDocTagNode($phpDocTagNode);
}

View File

@ -15,6 +15,7 @@ use PHPStan\Type\StringType;
use PHPStan\Type\Type;
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
use Rector\BetterPhpDocParser\PhpDoc\StringNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Doctrine\NodeAnalyzer\AttributeFinder;
@ -116,10 +117,14 @@ final class ColumnPropertyTypeResolver
if (!$typeArrayItemNode instanceof ArrayItemNode) {
return new MixedType();
}
if (!\is_string($typeArrayItemNode->value)) {
$typeValue = $typeArrayItemNode->value;
if ($typeValue instanceof StringNode) {
$typeValue = $typeValue->value;
}
if (!\is_string($typeValue)) {
return null;
}
return $this->createPHPStanTypeFromDoctrineStringType($typeArrayItemNode->value, $isNullable);
return $this->createPHPStanTypeFromDoctrineStringType($typeValue, $isNullable);
}
private function createPHPStanTypeFromDoctrineStringType(string $type, bool $isNullable) : Type
{

View File

@ -8,6 +8,7 @@ use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprIntegerNode;
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprTrueNode;
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
use Rector\BetterPhpDocParser\PhpDoc\StringNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\ValueObject\PhpDocAttributeKey;
final class DoctrineItemDefaultValueManipulator
@ -47,6 +48,9 @@ final class DoctrineItemDefaultValueManipulator
if (\is_int($defaultValue) && $currentValue instanceof ConstExprIntegerNode) {
$currentValue = (int) $currentValue->value;
}
if (\is_string($defaultValue) && $currentValue instanceof StringNode) {
$currentValue = $currentValue->value;
}
return $currentValue === $defaultValue;
}
}

View File

@ -9,6 +9,7 @@ use PHPStan\Type\Generic\GenericObjectType;
use PHPStan\Type\Type;
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
use Rector\BetterPhpDocParser\PhpDoc\StringNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Core\PhpParser\Node\Value\ValueResolver;
use Rector\Doctrine\NodeAnalyzer\AttributeFinder;
@ -70,10 +71,14 @@ final class ToManyRelationPropertyTypeResolver
if (!$targetEntityArrayItemNode instanceof ArrayItemNode) {
return null;
}
if (!\is_string($targetEntityArrayItemNode->value)) {
$targetEntityClass = $targetEntityArrayItemNode->value;
if ($targetEntityClass instanceof StringNode) {
$targetEntityClass = $targetEntityClass->value;
}
if (!\is_string($targetEntityClass)) {
return null;
}
return $this->resolveTypeFromTargetEntity($targetEntityArrayItemNode->value, $property);
return $this->resolveTypeFromTargetEntity($targetEntityClass, $property);
}
/**
* @param \PhpParser\Node\Expr|string $targetEntity

View File

@ -13,6 +13,7 @@ use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
use Rector\BetterPhpDocParser\PhpDoc\StringNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\BetterPhpDocParser\PhpDocParser\ClassAnnotationMatcher;
@ -85,6 +86,9 @@ final class ToOneRelationPropertyTypeResolver
return new MixedType();
}
$targetEntityClass = $targetEntityArrayItemNode->value;
if ($targetEntityClass instanceof StringNode) {
$targetEntityClass = $targetEntityClass->value;
}
if (!\is_string($targetEntityClass)) {
return new MixedType();
}

View File

@ -10,6 +10,7 @@ use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Property;
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
use Rector\BetterPhpDocParser\PhpDoc\StringNode;
use Rector\BetterPhpDocParser\ValueObject\PhpDoc\DoctrineAnnotation\CurlyListNode;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\MethodName;
@ -123,7 +124,11 @@ CODE_SAMPLE
if (!$typeArrayItemNode instanceof ArrayItemNode) {
return;
}
if ($typeArrayItemNode->value !== 'datetime') {
$typeValue = $typeArrayItemNode->value;
if ($typeValue instanceof StringNode) {
$typeValue = $typeValue->value;
}
if ($typeValue !== 'datetime') {
return;
}
$node = $this->constructorAssignPropertyAnalyzer->resolveConstructorAssign($property);

View File

@ -12,6 +12,7 @@ use PHPStan\Type\IntegerType;
use PHPStan\Type\StringType;
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
use Rector\BetterPhpDocParser\PhpDoc\StringNode;
use Rector\Core\Rector\AbstractRector;
use Rector\NodeTypeResolver\PhpDoc\NodeAnalyzer\DocBlockClassRenamer;
use Rector\NodeTypeResolver\ValueObject\OldToNewType;
@ -88,7 +89,11 @@ CODE_SAMPLE
if (!$typeArrayItemNode instanceof ArrayItemNode) {
return null;
}
if ($typeArrayItemNode->value !== 'bigint') {
$typeValue = $typeArrayItemNode->value;
if ($typeValue instanceof StringNode) {
$typeValue = $typeValue->value;
}
if ($typeValue !== 'bigint') {
return null;
}
$varTagValueNode = $phpDocInfo->getVarTagValueNode();

View File

@ -13,6 +13,7 @@ use PhpParser\Node\Stmt\Property;
use PhpParser\Node\Stmt\PropertyProperty;
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
use Rector\BetterPhpDocParser\PhpDoc\StringNode;
use Rector\Core\Exception\NotImplementedYetException;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
@ -81,6 +82,9 @@ CODE_SAMPLE
return null;
}
$typeValue = $typeArrayItemNode->value;
if ($typeValue instanceof StringNode) {
$typeValue = $typeValue->value;
}
if (!\is_string($typeValue)) {
return null;
}

View File

@ -14,6 +14,7 @@ use PhpParser\Node\Identifier;
use PhpParser\Node\Stmt\Property;
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
use Rector\BetterPhpDocParser\PhpDoc\StringNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\Core\Rector\AbstractRector;
use Rector\Doctrine\NodeAnalyzer\AttributeFinder;
@ -151,24 +152,25 @@ CODE_SAMPLE
if (!$targetEntityArrayItemNode instanceof ArrayItemNode) {
return null;
}
$targetEntity = $targetEntityArrayItemNode->value;
if (!\is_string($targetEntity)) {
$targetEntityClass = $targetEntityArrayItemNode->value;
if ($targetEntityClass instanceof StringNode) {
$targetEntityClass = $targetEntityClass->value;
}
if (!\is_string($targetEntityClass)) {
return null;
}
// resolve to FQN
$tagFullyQualifiedName = $this->doctrineClassAnnotationMatcher->resolveExpectingDoctrineFQCN($targetEntity, $property);
$tagFullyQualifiedName = $this->doctrineClassAnnotationMatcher->resolveExpectingDoctrineFQCN($targetEntityClass, $property);
if ($tagFullyQualifiedName === null) {
return null;
}
if ($tagFullyQualifiedName === $targetEntity) {
if ($tagFullyQualifiedName === $targetEntityClass) {
return null;
}
$currentArrayItemNode = $doctrineAnnotationTagValueNode->getValue($key);
if (!$currentArrayItemNode instanceof ArrayItemNode) {
return null;
}
// no quotes needed, it's a constants
$currentArrayItemNode->kindValueQuoted = null;
$currentArrayItemNode->value = '\\' . \ltrim($tagFullyQualifiedName, '\\') . '::class';
$currentArrayItemNode->setAttribute('orig_node', null);
return $property;

View File

@ -11,6 +11,7 @@ use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\PhpDocParser\Ast\Type\UnionTypeNode;
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
use Rector\BetterPhpDocParser\PhpDoc\StringNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Doctrine\PhpDoc\ShortClassExpander;
use Rector\StaticTypeMapper\Naming\NameScopeFactory;
@ -66,10 +67,14 @@ final class CollectionTypeResolver
if (!$targetEntityArrayItemNode instanceof ArrayItemNode) {
return null;
}
if (!\is_string($targetEntityArrayItemNode->value)) {
$targetEntityClass = $targetEntityArrayItemNode->value;
if ($targetEntityClass instanceof StringNode) {
$targetEntityClass = $targetEntityClass->value;
}
if (!\is_string($targetEntityClass)) {
return null;
}
$fullyQualifiedTargetEntity = $this->shortClassExpander->resolveFqnTargetEntity($targetEntityArrayItemNode->value, $property);
$fullyQualifiedTargetEntity = $this->shortClassExpander->resolveFqnTargetEntity($targetEntityClass, $property);
return new FullyQualifiedObjectType($fullyQualifiedTargetEntity);
}
}

View File

@ -20,15 +20,15 @@
"symfony\/security-core": "^6.2",
"symfony\/security-http": "^6.1",
"symfony\/validator": "^6.2",
"symplify\/easy-ci": "^11.1",
"symplify\/easy-ci": "^11.2",
"symplify\/easy-coding-standard": "^11.2",
"symplify\/phpstan-extensions": "^11.1",
"symplify\/phpstan-rules": "^11.2",
"symplify\/rule-doc-generator": "^11.2",
"symplify\/vendor-patches": "^11.2",
"tomasvotruba\/cognitive-complexity": "^0.0.5",
"tomasvotruba\/type-coverage": "^0.0.9",
"tomasvotruba\/unused-public": "^0.0.34"
"tomasvotruba\/cognitive-complexity": "^0.1",
"tomasvotruba\/type-coverage": "^0.2",
"tomasvotruba\/unused-public": "^0.1"
},
"autoload": {
"psr-4": {

View File

@ -13,6 +13,7 @@ use PHPStan\Type\StringType;
use PHPStan\Type\Type;
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
use Rector\BetterPhpDocParser\PhpDoc\StringNode;
use Rector\BetterPhpDocParser\ValueObject\PhpDoc\DoctrineAnnotation\CurlyListNode;
use Rector\Doctrine\NodeAnalyzer\AttrinationFinder;
use Rector\NodeNameResolver\NodeNameResolver;
@ -90,14 +91,20 @@ final class RouteRequiredParamNameToTypesResolver
return [];
}
foreach ($requirementsArrayItemNode->value->getValuesWithSilentKey() as $nestedArrayItemNode) {
if (!\is_string($nestedArrayItemNode->value)) {
continue;
$paramRegex = $nestedArrayItemNode->value;
if ($paramRegex instanceof StringNode) {
$paramRegex = $paramRegex->value;
}
if (!\is_string($nestedArrayItemNode->key)) {
if (!\is_string($paramRegex)) {
continue;
}
$paramName = $nestedArrayItemNode->key;
$paramRegex = $nestedArrayItemNode->value;
if ($paramName instanceof StringNode) {
$paramName = $paramName->value;
}
if (!\is_string($paramName)) {
continue;
}
$paramsToRegexes[$paramName] = $paramRegex;
}
return $paramsToRegexes;

View File

@ -3,6 +3,7 @@
declare (strict_types=1);
namespace Rector\Symfony\NodeFactory\Annotations;
use Rector\BetterPhpDocParser\PhpDoc\StringNode;
use Rector\BetterPhpDocParser\PhpDocParser\StaticDoctrineAnnotationParser\ArrayParser;
use Rector\BetterPhpDocParser\ValueObject\PhpDoc\DoctrineAnnotation\CurlyListNode;
final class StringValueQuoteWrapper
@ -17,13 +18,13 @@ final class StringValueQuoteWrapper
$this->arrayParser = $arrayParser;
}
/**
* @return mixed|CurlyListNode|string
* @return mixed|CurlyListNode|StringNode
* @param mixed $value
*/
public function wrap($value, ?string $key)
{
if (\is_string($value)) {
return '"' . $value . '"';
return new StringNode($value);
}
if (\is_array($value)) {
return $this->wrapArray($value, $key);
@ -41,7 +42,7 @@ final class StringValueQuoteWrapper
if (\is_numeric($nestedValue)) {
continue;
}
$value[$nestedKey] = '"' . $nestedValue . '"';
$value[$nestedKey] = new StringNode($nestedValue);
}
}
$arrayItemNodes = $this->arrayParser->createArrayFromValues($value);

View File

@ -16,6 +16,7 @@ use PhpParser\Node\Stmt\Return_;
use PHPStan\Type\ArrayType;
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
use Rector\BetterPhpDocParser\PhpDoc\StringNode;
use Rector\BetterPhpDocParser\ValueObject\PhpDoc\DoctrineAnnotation\CurlyListNode;
use Rector\Core\PhpParser\Node\NodeFactory;
use Rector\NodeNameResolver\NodeNameResolver;
@ -114,7 +115,11 @@ final class ThisRenderFactory
{
$arrayItems = [];
foreach ($arrayItemNodes as $arrayItemNode) {
$arrayItems[] = new ArrayItem(new Variable($arrayItemNode->value), new String_($arrayItemNode->value));
$arrayItemNodeValue = $arrayItemNode->value;
if ($arrayItemNodeValue instanceof StringNode) {
$arrayItemNodeValue = $arrayItemNodeValue->value;
}
$arrayItems[] = new ArrayItem(new Variable($arrayItemNodeValue), new String_($arrayItemNodeValue));
}
return new Array_($arrayItems);
}
@ -129,12 +134,24 @@ final class ThisRenderFactory
private function resolveTemplate(DoctrineAnnotationTagValueNode $doctrineAnnotationTagValueNode) : ?string
{
$templateParameter = $doctrineAnnotationTagValueNode->getValue('template');
if ($templateParameter instanceof ArrayItemNode && \is_string($templateParameter->value)) {
return $templateParameter->value;
if ($templateParameter instanceof ArrayItemNode) {
$templateParameterValue = $templateParameter->value;
if ($templateParameterValue instanceof StringNode) {
$templateParameterValue = $templateParameterValue->value;
}
if (\is_string($templateParameterValue)) {
return $templateParameterValue;
}
}
$arrayItemNode = $doctrineAnnotationTagValueNode->getSilentValue();
if ($arrayItemNode instanceof ArrayItemNode && \is_string($arrayItemNode->value)) {
return $arrayItemNode->value;
if ($arrayItemNode instanceof ArrayItemNode) {
$arrayItemNodeValue = $arrayItemNode->value;
if ($arrayItemNodeValue instanceof StringNode) {
$arrayItemNodeValue = $arrayItemNodeValue->value;
}
if (\is_string($arrayItemNodeValue)) {
return $arrayItemNodeValue;
}
}
return null;
}

View File

@ -4,11 +4,11 @@ declare (strict_types=1);
namespace Rector\Symfony\Rector\ClassMethod;
use PhpParser\Node;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
use Rector\BetterPhpDocParser\PhpDoc\StringNode;
use Rector\BetterPhpDocParser\PhpDocParser\StaticDoctrineAnnotationParser\ArrayParser;
use Rector\BetterPhpDocParser\ValueObject\PhpDoc\DoctrineAnnotation\CurlyListNode;
use Rector\Core\Rector\AbstractRector;
@ -132,8 +132,8 @@ CODE_SAMPLE
private function createRouteItems(SymfonyRouteMetadata $symfonyRouteMetadata) : array
{
$arrayItemNodes = [];
$arrayItemNodes[] = new ArrayItemNode($symfonyRouteMetadata->getPath(), 'path', String_::KIND_DOUBLE_QUOTED);
$arrayItemNodes[] = new ArrayItemNode($symfonyRouteMetadata->getName(), 'name', String_::KIND_DOUBLE_QUOTED);
$arrayItemNodes[] = new ArrayItemNode(new StringNode($symfonyRouteMetadata->getPath()), 'path');
$arrayItemNodes[] = new ArrayItemNode(new StringNode($symfonyRouteMetadata->getName()), 'name');
if ($symfonyRouteMetadata->getRequirements() !== []) {
$curlyListNode = $this->createCurlyQuoted($symfonyRouteMetadata->getRequirements());
$arrayItemNodes[] = new ArrayItemNode($curlyListNode, 'requirements');
@ -149,7 +149,7 @@ CODE_SAMPLE
$arrayItemNodes[] = new ArrayItemNode($defaultsWithoutControllerCurlyList, 'defaults');
}
if ($symfonyRouteMetadata->getHost() !== '') {
$arrayItemNodes[] = new ArrayItemNode($symfonyRouteMetadata->getHost(), 'host', String_::KIND_DOUBLE_QUOTED);
$arrayItemNodes[] = new ArrayItemNode(new StringNode($symfonyRouteMetadata->getHost()), 'host');
}
if ($symfonyRouteMetadata->getMethods() !== []) {
$methodsCurlyList = $this->createCurlyQuoted($symfonyRouteMetadata->getMethods());
@ -160,7 +160,7 @@ CODE_SAMPLE
$arrayItemNodes[] = new ArrayItemNode($schemesArrayItemNodes, 'schemes');
}
if ($symfonyRouteMetadata->getCondition() !== '') {
$arrayItemNodes[] = new ArrayItemNode($symfonyRouteMetadata->getCondition(), 'condition', String_::KIND_DOUBLE_QUOTED);
$arrayItemNodes[] = new ArrayItemNode(new StringNode($symfonyRouteMetadata->getCondition()), 'condition');
}
return $arrayItemNodes;
}
@ -186,10 +186,10 @@ CODE_SAMPLE
$curlyListNode = new CurlyListNode($methodsArrayItems);
foreach ($curlyListNode->values as $nestedMethodsArrayItem) {
if (\is_string($nestedMethodsArrayItem->value)) {
$nestedMethodsArrayItem->kindValueQuoted = String_::KIND_DOUBLE_QUOTED;
$nestedMethodsArrayItem->value = new StringNode($nestedMethodsArrayItem->value);
}
if (\is_string($nestedMethodsArrayItem->key)) {
$nestedMethodsArrayItem->kindKeyQuoted = String_::KIND_DOUBLE_QUOTED;
$nestedMethodsArrayItem->key = new StringNode($nestedMethodsArrayItem->key);
}
if ($nestedMethodsArrayItem->value === null) {
$nestedMethodsArrayItem->value = 'null';

View File

@ -4,11 +4,11 @@ declare (strict_types=1);
namespace Rector\Symfony\Rector\ClassMethod;
use PhpParser\Node;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
use Rector\BetterPhpDocParser\PhpDoc\StringNode;
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover;
use Rector\BetterPhpDocParser\Printer\PhpDocInfoPrinter;
use Rector\BetterPhpDocParser\ValueObject\PhpDoc\DoctrineAnnotation\CurlyListNode;
@ -104,8 +104,8 @@ CODE_SAMPLE
if ($sensioMethods === null) {
return null;
}
if (\is_string($sensioMethods)) {
$sensioMethods = new CurlyListNode([new ArrayItemNode($sensioMethods, null, String_::KIND_DOUBLE_QUOTED)]);
if (\is_string($sensioMethods) || $sensioMethods instanceof StringNode) {
$sensioMethods = new CurlyListNode([new ArrayItemNode($sensioMethods)]);
}
$symfonyMethodsArrayItemNode = $symfonyDoctrineAnnotationTagValueNode->getValue('methods');
// value is already filled, do not enter anything
@ -118,7 +118,7 @@ CODE_SAMPLE
return $node;
}
/**
* @return string|string[]|null|CurlyListNode
* @return string|string[]|null|CurlyListNode|StringNode
*/
private function resolveMethods(DoctrineAnnotationTagValueNode $doctrineAnnotationTagValueNode)
{

View File

@ -10,6 +10,7 @@ use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
use Rector\BetterPhpDocParser\PhpDoc\StringNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\Provider\CurrentFileProvider;
@ -101,12 +102,24 @@ final class JMSDITypeResolver
private function resolveServiceName(DoctrineAnnotationTagValueNode $doctrineAnnotationTagValueNode, Property $property) : string
{
$serviceNameParameter = $doctrineAnnotationTagValueNode->getValue('serviceName');
if ($serviceNameParameter instanceof ArrayItemNode && \is_string($serviceNameParameter->value)) {
return $serviceNameParameter->value;
if ($serviceNameParameter instanceof ArrayItemNode) {
$serviceNameParameterValue = $serviceNameParameter->value;
if ($serviceNameParameterValue instanceof StringNode) {
$serviceNameParameterValue = $serviceNameParameterValue->value;
}
if (\is_string($serviceNameParameterValue)) {
return $serviceNameParameterValue;
}
}
$arrayItemNode = $doctrineAnnotationTagValueNode->getSilentValue();
if ($arrayItemNode instanceof ArrayItemNode && \is_string($arrayItemNode->value)) {
return $arrayItemNode->value;
if ($arrayItemNode instanceof ArrayItemNode) {
$arrayItemNodeValue = $arrayItemNode->value;
if ($arrayItemNodeValue instanceof StringNode) {
$arrayItemNodeValue = $arrayItemNodeValue->value;
}
if (\is_string($arrayItemNodeValue)) {
return $arrayItemNodeValue;
}
}
return $this->nodeNameResolver->getName($property);
}