Updated Rector to commit 7ca4de097ed6b2f0f2b20a8f2b55ea2121120173

7ca4de097e [DeadCode] Skip nullable array on RemoveUnusedNonEmptyArrayBeforeForeachRector (#5375)
This commit is contained in:
Tomas Votruba 2023-12-21 15:22:15 +00:00
parent f8011a76d3
commit 949ab12adb
9 changed files with 32 additions and 14 deletions

View File

@ -7,6 +7,7 @@ use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\BinaryOp\BooleanAnd;
use PhpParser\Node\Expr\Empty_;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Foreach_;
@ -166,6 +167,17 @@ CODE_SAMPLE
if (!$this->uselessIfCondBeforeForeachDetector->isMatchingEmptyAndForeachedExpr($previousStmt, $stmt->expr)) {
continue;
}
/** @var Empty_ $empty */
$empty = $previousStmt->cond;
// scope need to be pulled from Empty_ node to ensure it get correct type
$scope = $empty->getAttribute(AttributeKey::SCOPE);
if (!$scope instanceof Scope) {
continue;
}
$ifType = $scope->getNativeType($empty->expr);
if (!$ifType->isArray()->yes()) {
continue;
}
unset($stmtsAware->stmts[$key - 1]);
return $stmtsAware;
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '0.18.13';
public const PACKAGE_VERSION = '7ca4de097ed6b2f0f2b20a8f2b55ea2121120173';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-12-18 19:30:04';
public const RELEASE_DATE = '2023-12-21 22:20:06';
/**
* @var int
*/

View File

@ -1679,12 +1679,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-doctrine.git",
"reference": "9de7d58cb2b3438a469a609457a92dd37a310acc"
"reference": "c7ff3e533aa58c456290c0e17e12f04369f55ec1"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/9de7d58cb2b3438a469a609457a92dd37a310acc",
"reference": "9de7d58cb2b3438a469a609457a92dd37a310acc",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/c7ff3e533aa58c456290c0e17e12f04369f55ec1",
"reference": "c7ff3e533aa58c456290c0e17e12f04369f55ec1",
"shasum": ""
},
"require": {
@ -1710,7 +1710,7 @@
"tomasvotruba\/type-coverage": "^0.2",
"tomasvotruba\/unused-public": "^0.3"
},
"time": "2023-10-22T17:44:32+00:00",
"time": "2023-12-21T14:33:58+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/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main 9de7d58'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main 917085c'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main 90e87f1'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main 5f1e96d'));
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main c7ff3e5'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main 917085c'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main 90e87f1'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main 5f1e96d'));
private function __construct()
{
}

View File

@ -354,7 +354,7 @@ Complete `@var` annotations or types based on @ORM\*toMany annotations or attrib
{
/**
* @ORM\OneToMany(targetEntity="App\Product")
+ * @var \Doctrine\Common\Collections\Collection<\App\Product>
+ * @var \Doctrine\Common\Collections\Collection<int, \App\Product>
*/
- private $products;
+ private \Doctrine\Common\Collections\Collection $products;

View File

@ -85,7 +85,7 @@ class SimpleColumn
{
/**
* @ORM\OneToMany(targetEntity="App\Product")
* @var \Doctrine\Common\Collections\Collection<\App\Product>
* @var \Doctrine\Common\Collections\Collection<int, \App\Product>
*/
private \Doctrine\Common\Collections\Collection $products;
}

View File

@ -5,7 +5,6 @@ namespace Rector\Doctrine\NodeManipulator;
use PhpParser\Node\Expr;
use PhpParser\Node\Stmt\Property;
use PHPStan\Type\Generic\GenericObjectType;
use PHPStan\Type\Type;
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
@ -14,6 +13,7 @@ use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Core\PhpParser\Node\Value\ValueResolver;
use Rector\Doctrine\NodeAnalyzer\AttributeFinder;
use Rector\Doctrine\PhpDoc\ShortClassExpander;
use Rector\Doctrine\TypeAnalyzer\CollectionTypeFactory;
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
final class ToManyRelationPropertyTypeResolver
{
@ -37,6 +37,11 @@ final class ToManyRelationPropertyTypeResolver
* @var \Rector\Core\PhpParser\Node\Value\ValueResolver
*/
private $valueResolver;
/**
* @readonly
* @var \Rector\Doctrine\TypeAnalyzer\CollectionTypeFactory
*/
private $collectionTypeFactory;
/**
* @var string
*/
@ -45,12 +50,13 @@ final class ToManyRelationPropertyTypeResolver
* @var class-string[]
*/
private const TO_MANY_ANNOTATION_CLASSES = ['Doctrine\\ORM\\Mapping\\OneToMany', 'Doctrine\\ORM\\Mapping\\ManyToMany'];
public function __construct(PhpDocInfoFactory $phpDocInfoFactory, ShortClassExpander $shortClassExpander, AttributeFinder $attributeFinder, ValueResolver $valueResolver)
public function __construct(PhpDocInfoFactory $phpDocInfoFactory, ShortClassExpander $shortClassExpander, AttributeFinder $attributeFinder, ValueResolver $valueResolver, CollectionTypeFactory $collectionTypeFactory)
{
$this->phpDocInfoFactory = $phpDocInfoFactory;
$this->shortClassExpander = $shortClassExpander;
$this->attributeFinder = $attributeFinder;
$this->valueResolver = $valueResolver;
$this->collectionTypeFactory = $collectionTypeFactory;
}
public function resolve(Property $property) : ?Type
{
@ -93,6 +99,6 @@ final class ToManyRelationPropertyTypeResolver
}
$entityFullyQualifiedClass = $this->shortClassExpander->resolveFqnTargetEntity($targetEntity, $property);
$fullyQualifiedObjectType = new FullyQualifiedObjectType($entityFullyQualifiedClass);
return new GenericObjectType(self::COLLECTION_TYPE, [$fullyQualifiedObjectType]);
return $this->collectionTypeFactory->createGenericObjectType($fullyQualifiedObjectType);
}
}

View File

@ -17,7 +17,7 @@ final class CollectionTypeFactory
$arrayType = new ArrayType(new MixedType(), $fullyQualifiedObjectType);
return new UnionType([$genericObjectType, $arrayType]);
}
private function createGenericObjectType(FullyQualifiedObjectType $fullyQualifiedObjectType) : GenericObjectType
public function createGenericObjectType(FullyQualifiedObjectType $fullyQualifiedObjectType) : GenericObjectType
{
$genericTypes = [new IntegerType(), $fullyQualifiedObjectType];
return new GenericObjectType('Doctrine\\Common\\Collections\\Collection', $genericTypes);