Skip to content

Commit

Permalink
Updated Rector to commit 0a2dc3d52b679bad1b07849d951748a8faad7f9a
Browse files Browse the repository at this point in the history
rectorphp/rector-src@0a2dc3d Fix array type if property is used in TypedPropertyFromStrictConstructorRector (#5339)
  • Loading branch information
TomasVotruba committed Dec 8, 2023
1 parent d471c4d commit 548d510
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Identifier;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Else_;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\If_;
use PhpParser\NodeFinder;
use PhpParser\NodeTraverser;
use PHPStan\Type\ObjectType;
use Rector\Core\NodeAnalyzer\PropertyFetchAnalyzer;
Expand Down Expand Up @@ -79,6 +82,11 @@ public function isPropertyAssigned(ClassLike $classLike, string $propertyName) :
}
/** @var Assign $assign */
$assign = $node;
// is merged in assign?
if ($this->isPropertyUsedInAssign($assign, $propertyName)) {
$isAssignedInConstructor = \false;
return NodeTraverser::STOP_TRAVERSAL;
}
$isFirstLevelStatement = $assign->getAttribute(self::IS_FIRST_LEVEL_STATEMENT);
// cannot be nested
if ($isFirstLevelStatement !== \true) {
Expand Down Expand Up @@ -168,4 +176,17 @@ private function matchInitializeClassMethod(ClassLike $classLike) : array
}
return $initializingClassMethods;
}
private function isPropertyUsedInAssign(Assign $assign, string $propertyName) : bool
{
$nodeFinder = new NodeFinder();
return (bool) $nodeFinder->findFirst($assign->expr, static function (Node $node) use($propertyName) : ?bool {
if (!$node instanceof PropertyFetch) {
return null;
}
if (!$node->name instanceof Identifier) {
return null;
}
return $node->name->toString() === $propertyName;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use PhpParser\Node\Expr;
use PhpParser\Node\Stmt\PropertyProperty;
use PHPStan\Type\ArrayType;
use PHPStan\Type\Type;
use Rector\StaticTypeMapper\StaticTypeMapper;
final class PropertyTypeDefaultValueAnalyzer
Expand All @@ -25,6 +26,9 @@ public function doesConflictWithDefaultValue(PropertyProperty $propertyProperty,
}
// the defaults can be in conflict
$defaultType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($propertyProperty->default);
if ($defaultType instanceof ArrayType && $propertyType instanceof ArrayType) {
return \false;
}
// type is not matching, skip it
return !$defaultType->isSuperTypeOf($propertyType)->yes();
}
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 = 'af55788ca8f814c658d39444a9cefa67135805b6';
public const PACKAGE_VERSION = '0a2dc3d52b679bad1b07849d951748a8faad7f9a';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-12-08 11:27:51';
public const RELEASE_DATE = '2023-12-08 13:56:59';
/**
* @var int
*/
Expand Down

0 comments on commit 548d510

Please sign in to comment.