Updated Rector to commit 3cbf7104d0b81ba1b930ce9a4cd3456e1c082b43

3cbf7104d0 [CodeQuality] Skip empty cases on SwitchTrueToIfRector (#3556)
This commit is contained in:
Tomas Votruba 2023-04-03 08:47:41 +00:00
parent d7fe9b627b
commit 123448aa91
19 changed files with 104 additions and 32 deletions

2
vendor/autoload.php vendored
View File

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

View File

@ -1702,6 +1702,7 @@ return array(
'Rector\\Doctrine\\Rector\\Class_\\ManagerRegistryGetManagerToEntityManagerRector' => $vendorDir . '/rector/rector-doctrine/src/Rector/Class_/ManagerRegistryGetManagerToEntityManagerRector.php',
'Rector\\Doctrine\\Rector\\Class_\\MoveCurrentDateTimeDefaultInEntityToConstructorRector' => $vendorDir . '/rector/rector-doctrine/src/Rector/Class_/MoveCurrentDateTimeDefaultInEntityToConstructorRector.php',
'Rector\\Doctrine\\Rector\\Class_\\MoveRepositoryFromParentToConstructorRector' => $vendorDir . '/rector/rector-doctrine/src/Rector/Class_/MoveRepositoryFromParentToConstructorRector.php',
'Rector\\Doctrine\\Rector\\Class_\\RemoveEmptyTableAttributeRector' => $vendorDir . '/rector/rector-doctrine/src/Rector/Class_/RemoveEmptyTableAttributeRector.php',
'Rector\\Doctrine\\Rector\\Class_\\RemoveRedundantDefaultClassAnnotationValuesRector' => $vendorDir . '/rector/rector-doctrine/src/Rector/Class_/RemoveRedundantDefaultClassAnnotationValuesRector.php',
'Rector\\Doctrine\\Rector\\Class_\\RemoveRepositoryFromEntityAnnotationRector' => $vendorDir . '/rector/rector-doctrine/src/Rector/Class_/RemoveRepositoryFromEntityAnnotationRector.php',
'Rector\\Doctrine\\Rector\\MethodCall\\ChangeCompositeExpressionAddMultipleWithWithRector' => $vendorDir . '/rector/rector-doctrine/src/Rector/MethodCall/ChangeCompositeExpressionAddMultipleWithWithRector.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit90b0a339f5e68da0f08b9e7390f4c7cd
class ComposerAutoloaderInit4c05484305864b0e5733b0ca9f0cc86e
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInit90b0a339f5e68da0f08b9e7390f4c7cd
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit90b0a339f5e68da0f08b9e7390f4c7cd', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit4c05484305864b0e5733b0ca9f0cc86e', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit90b0a339f5e68da0f08b9e7390f4c7cd', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit4c05484305864b0e5733b0ca9f0cc86e', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit90b0a339f5e68da0f08b9e7390f4c7cd::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit4c05484305864b0e5733b0ca9f0cc86e::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit90b0a339f5e68da0f08b9e7390f4c7cd::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInit4c05484305864b0e5733b0ca9f0cc86e::$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 ComposerStaticInit90b0a339f5e68da0f08b9e7390f4c7cd
class ComposerStaticInit4c05484305864b0e5733b0ca9f0cc86e
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -1949,6 +1949,7 @@ class ComposerStaticInit90b0a339f5e68da0f08b9e7390f4c7cd
'Rector\\Doctrine\\Rector\\Class_\\ManagerRegistryGetManagerToEntityManagerRector' => __DIR__ . '/..' . '/rector/rector-doctrine/src/Rector/Class_/ManagerRegistryGetManagerToEntityManagerRector.php',
'Rector\\Doctrine\\Rector\\Class_\\MoveCurrentDateTimeDefaultInEntityToConstructorRector' => __DIR__ . '/..' . '/rector/rector-doctrine/src/Rector/Class_/MoveCurrentDateTimeDefaultInEntityToConstructorRector.php',
'Rector\\Doctrine\\Rector\\Class_\\MoveRepositoryFromParentToConstructorRector' => __DIR__ . '/..' . '/rector/rector-doctrine/src/Rector/Class_/MoveRepositoryFromParentToConstructorRector.php',
'Rector\\Doctrine\\Rector\\Class_\\RemoveEmptyTableAttributeRector' => __DIR__ . '/..' . '/rector/rector-doctrine/src/Rector/Class_/RemoveEmptyTableAttributeRector.php',
'Rector\\Doctrine\\Rector\\Class_\\RemoveRedundantDefaultClassAnnotationValuesRector' => __DIR__ . '/..' . '/rector/rector-doctrine/src/Rector/Class_/RemoveRedundantDefaultClassAnnotationValuesRector.php',
'Rector\\Doctrine\\Rector\\Class_\\RemoveRepositoryFromEntityAnnotationRector' => __DIR__ . '/..' . '/rector/rector-doctrine/src/Rector/Class_/RemoveRepositoryFromEntityAnnotationRector.php',
'Rector\\Doctrine\\Rector\\MethodCall\\ChangeCompositeExpressionAddMultipleWithWithRector' => __DIR__ . '/..' . '/rector/rector-doctrine/src/Rector/MethodCall/ChangeCompositeExpressionAddMultipleWithWithRector.php',
@ -3130,9 +3131,9 @@ class ComposerStaticInit90b0a339f5e68da0f08b9e7390f4c7cd
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit90b0a339f5e68da0f08b9e7390f4c7cd::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit90b0a339f5e68da0f08b9e7390f4c7cd::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit90b0a339f5e68da0f08b9e7390f4c7cd::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit4c05484305864b0e5733b0ca9f0cc86e::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit4c05484305864b0e5733b0ca9f0cc86e::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit4c05484305864b0e5733b0ca9f0cc86e::$classMap;
}, null, ClassLoader::class);
}

View File

@ -1919,12 +1919,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-doctrine.git",
"reference": "5fe59e9f3a2ef37bacca898a7a7dd438cc389626"
"reference": "b88c766bfa958d04cf778203a41c3e8b469557be"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/5fe59e9f3a2ef37bacca898a7a7dd438cc389626",
"reference": "5fe59e9f3a2ef37bacca898a7a7dd438cc389626",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/b88c766bfa958d04cf778203a41c3e8b469557be",
"reference": "b88c766bfa958d04cf778203a41c3e8b469557be",
"shasum": ""
},
"require": {
@ -1951,7 +1951,7 @@
"symplify\/rule-doc-generator": "^11.1",
"symplify\/vendor-patches": "^11.1"
},
"time": "2023-03-03T10:04:37+00:00",
"time": "2023-04-03T08:35:29+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 5fe59e9'), '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 23e55c6'), '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 dfeb67c'), '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 141e7e2'));
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 b88c766'), '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 23e55c6'), '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 dfeb67c'), '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 141e7e2'));
private function __construct()
{
}

View File

@ -7,6 +7,7 @@ use Rector\Config\RectorConfig;
use Rector\Doctrine\Rector\Class_\InitializeDefaultEntityCollectionRector;
use Rector\Doctrine\Rector\Class_\ManagerRegistryGetManagerToEntityManagerRector;
use Rector\Doctrine\Rector\Class_\MoveCurrentDateTimeDefaultInEntityToConstructorRector;
use Rector\Doctrine\Rector\Class_\RemoveEmptyTableAttributeRector;
use Rector\Doctrine\Rector\Class_\RemoveRedundantDefaultClassAnnotationValuesRector;
use Rector\Doctrine\Rector\ClassMethod\MakeEntitySetterNullabilityInSyncWithPropertyRector;
use Rector\Doctrine\Rector\Property\ChangeBigIntEntityPropertyToIntTypeRector;
@ -31,6 +32,7 @@ return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->rule(ImproveDoctrineCollectionDocTypeInEntityRector::class);
$rectorConfig->rule(RemoveRedundantDefaultPropertyAnnotationValuesRector::class);
$rectorConfig->rule(RemoveRedundantDefaultClassAnnotationValuesRector::class);
$rectorConfig->rule(RemoveEmptyTableAttributeRector::class);
// typed properties in entities from annotations/attributes
$rectorConfig->rule(TypedPropertyFromColumnTypeRector::class);
$rectorConfig->rule(TypedPropertyFromToOneRelationTypeRector::class);

View File

@ -6,6 +6,7 @@ namespace Rector\Doctrine\NodeAnalyzer;
use PhpParser\Node\Attribute;
use PhpParser\Node\AttributeGroup;
use PhpParser\Node\Expr;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\ClassLike;
@ -82,7 +83,7 @@ final class AttributeFinder
private function findArgByName(Attribute $attribute, string $argName) : ?\PhpParser\Node\Expr
{
foreach ($attribute->args as $arg) {
if ($arg->name === null) {
if (!$arg->name instanceof Identifier) {
continue;
}
if (!$this->nodeNameResolver->isName($arg->name, $argName)) {

View File

@ -116,7 +116,7 @@ final class IssetDimFetchCleaner
if (!$expr instanceof ArrayDimFetch) {
return null;
}
if ($expr->dim === null) {
if (!$expr->dim instanceof Expr) {
return null;
}
if (!$this->isArrayDimFetchOnVariable($expr, $variable)) {

View File

@ -55,7 +55,7 @@ final class ToManyRelationPropertyTypeResolver
{
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($property);
$doctrineAnnotationTagValueNode = $phpDocInfo->getByAnnotationClasses(self::TO_MANY_ANNOTATION_CLASSES);
if ($doctrineAnnotationTagValueNode !== null) {
if ($doctrineAnnotationTagValueNode instanceof DoctrineAnnotationTagValueNode) {
return $this->processToManyRelation($property, $doctrineAnnotationTagValueNode);
}
$expr = $this->attributeFinder->findAttributeByClassesArgByName($property, self::TO_MANY_ANNOTATION_CLASSES, 'targetEntity');

View File

@ -128,7 +128,7 @@ CODE_SAMPLE
}
$node = $this->constructorAssignPropertyAnalyzer->resolveConstructorAssign($property);
// 0. already has default
if ($node !== null) {
if ($node instanceof Node) {
return;
}
// 1. remove default options from database level

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\Doctrine\Rector\Class_;
use PhpParser\Node;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\Class_;
use PHPStan\Type\Generic\GenericObjectType;
use PHPStan\Type\ObjectType;
@ -94,7 +95,7 @@ CODE_SAMPLE
if (!$this->isObjectType($node, new ObjectType('Doctrine\\ORM\\EntityRepository'))) {
return null;
}
if ($node->extends === null) {
if (!$node->extends instanceof Name) {
return null;
}
// remove parent class

View File

@ -0,0 +1,70 @@
<?php
declare (strict_types=1);
namespace Rector\Doctrine\Rector\Class_;
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Doctrine\Tests\Rector\Class_\RemoveEmptyTableAttributeRector\RemoveEmptyTableAttributeRectorTest
*/
final class RemoveEmptyTableAttributeRector extends AbstractRector
{
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Remove empty Table attribute on entities because it\'s useless', [new CodeSample(<<<'CODE_SAMPLE'
use Doctrine\ORM\Mapping as ORM;
#[ORM\Table]
#[ORM\Entity]
class Product
{
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
class Product
{
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [Class_::class];
}
/**
* @param Class_ $node
*/
public function refactor(Node $node) : ?Node
{
$removed = \false;
foreach ($node->attrGroups as $attrGroup) {
foreach ($attrGroup->attrs as $attribute) {
if (!$this->nodeNameResolver->isName($attribute, 'Doctrine\\ORM\\Mapping\\Table')) {
continue;
}
if ($attribute->args !== []) {
continue;
}
$this->removeNode($attribute);
}
if ($attrGroup->attrs === []) {
$this->removeNode($attrGroup);
$removed = \true;
}
}
if ($removed) {
return $node;
}
return null;
}
}

View File

@ -94,7 +94,7 @@ CODE_SAMPLE
}
private function refactorToBoolType(PropertyProperty $propertyProperty, Property $property) : ?Property
{
if ($propertyProperty->default === null) {
if (!$propertyProperty->default instanceof Expr) {
return null;
}
$defaultExpr = $propertyProperty->default;
@ -110,7 +110,7 @@ CODE_SAMPLE
}
private function refactorToIntType(PropertyProperty $propertyProperty, Property $property) : ?Property
{
if ($propertyProperty->default === null) {
if (!$propertyProperty->default instanceof Expr) {
return null;
}
$defaultExpr = $propertyProperty->default;

View File

@ -95,7 +95,7 @@ CODE_SAMPLE
$phpDocInfo = $this->phpDocInfoFactory->createFromNode($node);
if ($phpDocInfo instanceof PhpDocInfo) {
$property = $this->changeTypeInAnnotationTypes($node, $phpDocInfo);
$annotationDetected = $property !== null || $phpDocInfo->hasChanged();
$annotationDetected = $property instanceof Property || $phpDocInfo->hasChanged();
if ($annotationDetected) {
return $property;
}

View File

@ -205,7 +205,7 @@ CODE_SAMPLE
private function refactorPropertyPhpDocInfo(Property $property, PhpDocInfo $phpDocInfo) : ?Property
{
$varTagValueNode = $this->collectionVarTagValueNodeResolver->resolve($property);
if ($varTagValueNode !== null) {
if ($varTagValueNode instanceof VarTagValueNode) {
$collectionObjectType = $this->collectionTypeResolver->resolveFromTypeNode($varTagValueNode->type, $property);
if (!$collectionObjectType instanceof FullyQualifiedObjectType) {
return null;

View File

@ -43,7 +43,7 @@ final class CollectionTypeResolver
if ($typeNode instanceof UnionTypeNode) {
foreach ($typeNode->types as $unionedTypeNode) {
$resolvedUnionedType = $this->resolveFromTypeNode($unionedTypeNode, $node);
if ($resolvedUnionedType !== null) {
if ($resolvedUnionedType instanceof FullyQualifiedObjectType) {
return $resolvedUnionedType;
}
}

View File

@ -32,18 +32,14 @@ final class DoctrineCollectionTypeAnalyzer
if (!$hasDoctrineCollectionType) {
return \false;
}
return $arrayType !== null;
return $arrayType instanceof ArrayType;
}
private function isCollectionObjectType(Type $type) : bool
{
if (!$type instanceof TypeWithClassName) {
return \false;
}
if ($type instanceof ShortenedObjectType) {
$className = $type->getFullyQualifiedName();
} else {
$className = $type->getClassName();
}
$className = $type instanceof ShortenedObjectType ? $type->getFullyQualifiedName() : $type->getClassName();
return $className === 'Doctrine\\Common\\Collections\\Collection';
}
}