Skip to content

Commit

Permalink
Updated Rector to commit 39e4f0ae398befb8ad1aa63b66e50cc62e9a3883
Browse files Browse the repository at this point in the history
rectorphp/rector-src@39e4f0a [NodeTypeResolver] Remove AstResolver usage on ArrayTypeAnalyzer (#5110)
  • Loading branch information
TomasVotruba committed Oct 4, 2023
1 parent e7e6907 commit ea462b8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 72 deletions.
69 changes: 4 additions & 65 deletions packages/NodeTypeResolver/TypeAnalyzer/ArrayTypeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,73 +7,42 @@
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticPropertyFetch;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\Property;
use PHPStan\PhpDocParser\Ast\Type\ArrayShapeNode;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\Php\PhpPropertyReflection;
use PHPStan\Type\Accessory\HasOffsetType;
use PHPStan\Type\Accessory\NonEmptyArrayType;
use PHPStan\Type\ArrayType;
use PHPStan\Type\IntersectionType;
use PHPStan\Type\IterableType;
use PHPStan\Type\MixedType;
use PHPStan\Type\Type;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Core\PhpParser\AstResolver;
use Rector\Core\Reflection\ReflectionResolver;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\NodeTypeResolver;
final class ArrayTypeAnalyzer
{
/**
* @readonly
* @var \Rector\NodeNameResolver\NodeNameResolver
*/
private $nodeNameResolver;
/**
* @readonly
* @var \Rector\NodeTypeResolver\NodeTypeResolver
*/
private $nodeTypeResolver;
/**
* @readonly
* @var \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory
*/
private $phpDocInfoFactory;
/**
* @readonly
* @var \Rector\Core\Reflection\ReflectionResolver
*/
private $reflectionResolver;
/**
* @readonly
* @var \Rector\Core\PhpParser\AstResolver
*/
private $astResolver;
public function __construct(NodeNameResolver $nodeNameResolver, NodeTypeResolver $nodeTypeResolver, PhpDocInfoFactory $phpDocInfoFactory, ReflectionResolver $reflectionResolver, AstResolver $astResolver)
public function __construct(NodeTypeResolver $nodeTypeResolver, ReflectionResolver $reflectionResolver)
{
$this->nodeNameResolver = $nodeNameResolver;
$this->nodeTypeResolver = $nodeTypeResolver;
$this->phpDocInfoFactory = $phpDocInfoFactory;
$this->reflectionResolver = $reflectionResolver;
$this->astResolver = $astResolver;
}
public function isArrayType(Expr $expr) : bool
{
$nodeType = $this->nodeTypeResolver->getType($expr);
$nodeType = $this->nodeTypeResolver->getNativeType($expr);
if ($this->isIntersectionArrayType($nodeType)) {
return \true;
}
// PHPStan false positive, when variable has type[] docblock, but default array is missing
if ($expr instanceof PropertyFetch || $expr instanceof StaticPropertyFetch) {
if ($this->isPropertyFetchWithArrayDefault($expr)) {
return \true;
}
if ($this->isPropertyFetchWithArrayDocblockWithoutDefault($expr)) {
return \false;
}
if (($expr instanceof PropertyFetch || $expr instanceof StaticPropertyFetch) && $this->isPropertyFetchWithArrayDefault($expr)) {
return \true;
}
if ($nodeType instanceof MixedType) {
if ($nodeType->isExplicitMixed()) {
Expand Down Expand Up @@ -104,36 +73,6 @@ private function isIntersectionArrayType(Type $nodeType) : bool
}
return \true;
}
private function isPropertyFetchWithArrayDocblockWithoutDefault(Expr $expr) : bool
{
if (!$expr instanceof PropertyFetch && !$expr instanceof StaticPropertyFetch) {
return \false;
}
$classReflection = $this->reflectionResolver->resolveClassReflection($expr);
if (!$classReflection instanceof ClassReflection) {
return \false;
}
$propertyName = $this->nodeNameResolver->getName($expr->name);
if ($propertyName === null) {
return \false;
}
/** @var ClassLike $classLike */
$classLike = $this->astResolver->resolveClassFromClassReflection($classReflection);
$property = $classLike->getProperty($propertyName);
if (!$property instanceof Property) {
return \false;
}
$propertyProperty = $property->props[0];
if ($propertyProperty->default instanceof Array_) {
return \false;
}
$propertyPhpDocInfo = $this->phpDocInfoFactory->createFromNode($property);
if (!$propertyPhpDocInfo instanceof PhpDocInfo) {
return \false;
}
$varType = $propertyPhpDocInfo->getVarType();
return $varType instanceof ArrayType || $varType instanceof ArrayShapeNode || $varType instanceof IterableType;
}
/**
* phpstan bug workaround - https://phpstan.org/r/0443f283-244c-42b8-8373-85e7deb3504c
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'd7710f8758ef1a893424e3ab395c3f74c435d91c';
public const PACKAGE_VERSION = '39e4f0ae398befb8ad1aa63b66e50cc62e9a3883';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-10-03 09:39:49';
public const RELEASE_DATE = '2023-10-04 14:21:42';
/**
* @var int
*/
Expand Down
8 changes: 4 additions & 4 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,8 @@
},
{
"name": "illuminate\/container",
"version": "v10.25.2",
"version_normalized": "10.25.2.0",
"version": "v10.26.2",
"version_normalized": "10.26.2.0",
"source": {
"type": "git",
"url": "https:\/\/github.com\/illuminate\/container.git",
Expand Down Expand Up @@ -561,8 +561,8 @@
},
{
"name": "illuminate\/contracts",
"version": "v10.25.2",
"version_normalized": "10.25.2.0",
"version": "v10.26.2",
"version_normalized": "10.26.2.0",
"source": {
"type": "git",
"url": "https:\/\/github.com\/illuminate\/contracts.git",
Expand Down
Loading

0 comments on commit ea462b8

Please sign in to comment.