mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-02 17:30:50 +00:00
Updated Rector to commit 71c6dd929f07d6491847ee9004224441265d0197
71c6dd929f
Support NullSafeProperty fetches in unused-code analysis (#5839)
This commit is contained in:
parent
3e1d355024
commit
c041415e42
|
@ -5,6 +5,7 @@ namespace Rector\DeadCode\NodeAnalyzer;
|
||||||
|
|
||||||
use PhpParser\Node;
|
use PhpParser\Node;
|
||||||
use PhpParser\Node\Expr;
|
use PhpParser\Node\Expr;
|
||||||
|
use PhpParser\Node\Expr\NullsafePropertyFetch;
|
||||||
use PhpParser\Node\Expr\PropertyFetch;
|
use PhpParser\Node\Expr\PropertyFetch;
|
||||||
use PhpParser\Node\Expr\StaticPropertyFetch;
|
use PhpParser\Node\Expr\StaticPropertyFetch;
|
||||||
use PhpParser\Node\Stmt\Class_;
|
use PhpParser\Node\Stmt\Class_;
|
||||||
|
@ -24,7 +25,7 @@ final class PropertyWriteonlyAnalyzer
|
||||||
public function hasClassDynamicPropertyNames(Class_ $class) : bool
|
public function hasClassDynamicPropertyNames(Class_ $class) : bool
|
||||||
{
|
{
|
||||||
return (bool) $this->betterNodeFinder->findFirst($class, static function (Node $node) : bool {
|
return (bool) $this->betterNodeFinder->findFirst($class, static function (Node $node) : bool {
|
||||||
if (!$node instanceof PropertyFetch) {
|
if (!$node instanceof PropertyFetch && !$node instanceof NullsafePropertyFetch) {
|
||||||
return \false;
|
return \false;
|
||||||
}
|
}
|
||||||
// has dynamic name - could be anything
|
// has dynamic name - could be anything
|
||||||
|
@ -34,7 +35,7 @@ final class PropertyWriteonlyAnalyzer
|
||||||
/**
|
/**
|
||||||
* The property fetches are always only assigned to, nothing else
|
* The property fetches are always only assigned to, nothing else
|
||||||
*
|
*
|
||||||
* @param array<PropertyFetch|StaticPropertyFetch> $propertyFetches
|
* @param array<PropertyFetch|StaticPropertyFetch|NullsafePropertyFetch> $propertyFetches
|
||||||
*/
|
*/
|
||||||
public function arePropertyFetchesExclusivelyBeingAssignedTo(array $propertyFetches) : bool
|
public function arePropertyFetchesExclusivelyBeingAssignedTo(array $propertyFetches) : bool
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||||
* @api
|
* @api
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public const PACKAGE_VERSION = '4cd2622ccbe9989cdf76a16aa6d282b5ba73adb0';
|
public const PACKAGE_VERSION = '71c6dd929f07d6491847ee9004224441265d0197';
|
||||||
/**
|
/**
|
||||||
* @api
|
* @api
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public const RELEASE_DATE = '2024-04-22 02:20:32';
|
public const RELEASE_DATE = '2024-04-22 02:22:37';
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -6,6 +6,7 @@ namespace Rector\NodeAnalyzer;
|
||||||
use PhpParser\Node;
|
use PhpParser\Node;
|
||||||
use PhpParser\Node\Expr\Assign;
|
use PhpParser\Node\Expr\Assign;
|
||||||
use PhpParser\Node\Expr\MethodCall;
|
use PhpParser\Node\Expr\MethodCall;
|
||||||
|
use PhpParser\Node\Expr\NullsafePropertyFetch;
|
||||||
use PhpParser\Node\Expr\PropertyFetch;
|
use PhpParser\Node\Expr\PropertyFetch;
|
||||||
use PhpParser\Node\Expr\StaticCall;
|
use PhpParser\Node\Expr\StaticCall;
|
||||||
use PhpParser\Node\Expr\StaticPropertyFetch;
|
use PhpParser\Node\Expr\StaticPropertyFetch;
|
||||||
|
@ -67,10 +68,10 @@ final class PropertyFetchAnalyzer
|
||||||
}
|
}
|
||||||
public function isLocalPropertyFetch(Node $node) : bool
|
public function isLocalPropertyFetch(Node $node) : bool
|
||||||
{
|
{
|
||||||
if (!$node instanceof PropertyFetch && !$node instanceof StaticPropertyFetch) {
|
if (!$node instanceof PropertyFetch && !$node instanceof StaticPropertyFetch && !$node instanceof NullsafePropertyFetch) {
|
||||||
return \false;
|
return \false;
|
||||||
}
|
}
|
||||||
$variableType = $node instanceof PropertyFetch ? $this->nodeTypeResolver->getType($node->var) : $this->nodeTypeResolver->getType($node->class);
|
$variableType = $node instanceof StaticPropertyFetch ? $this->nodeTypeResolver->getType($node->class) : $this->nodeTypeResolver->getType($node->var);
|
||||||
if ($variableType instanceof ObjectType) {
|
if ($variableType instanceof ObjectType) {
|
||||||
$classReflection = $this->reflectionResolver->resolveClassReflection($node);
|
$classReflection = $this->reflectionResolver->resolveClassReflection($node);
|
||||||
if ($classReflection instanceof ClassReflection) {
|
if ($classReflection instanceof ClassReflection) {
|
||||||
|
@ -85,7 +86,7 @@ final class PropertyFetchAnalyzer
|
||||||
}
|
}
|
||||||
public function isLocalPropertyFetchName(Node $node, string $desiredPropertyName) : bool
|
public function isLocalPropertyFetchName(Node $node, string $desiredPropertyName) : bool
|
||||||
{
|
{
|
||||||
if (!$node instanceof PropertyFetch && !$node instanceof StaticPropertyFetch) {
|
if (!$node instanceof PropertyFetch && !$node instanceof StaticPropertyFetch && !$node instanceof NullsafePropertyFetch) {
|
||||||
return \false;
|
return \false;
|
||||||
}
|
}
|
||||||
if (!$this->nodeNameResolver->isName($node->name, $desiredPropertyName)) {
|
if (!$this->nodeNameResolver->isName($node->name, $desiredPropertyName)) {
|
||||||
|
|
|
@ -9,6 +9,7 @@ use PhpParser\Node\Expr\ArrayDimFetch;
|
||||||
use PhpParser\Node\Expr\Assign;
|
use PhpParser\Node\Expr\Assign;
|
||||||
use PhpParser\Node\Expr\FuncCall;
|
use PhpParser\Node\Expr\FuncCall;
|
||||||
use PhpParser\Node\Expr\MethodCall;
|
use PhpParser\Node\Expr\MethodCall;
|
||||||
|
use PhpParser\Node\Expr\NullsafePropertyFetch;
|
||||||
use PhpParser\Node\Expr\PropertyFetch;
|
use PhpParser\Node\Expr\PropertyFetch;
|
||||||
use PhpParser\Node\Expr\StaticCall;
|
use PhpParser\Node\Expr\StaticCall;
|
||||||
use PhpParser\Node\Expr\StaticPropertyFetch;
|
use PhpParser\Node\Expr\StaticPropertyFetch;
|
||||||
|
@ -96,15 +97,18 @@ final class PropertyFetchFinder
|
||||||
return $this->findPropertyFetchesInClassLike($class, $nodes, $propertyName, $hasTrait, $scope);
|
return $this->findPropertyFetchesInClassLike($class, $nodes, $propertyName, $hasTrait, $scope);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @return PropertyFetch[]|StaticPropertyFetch[]
|
* @return PropertyFetch[]|StaticPropertyFetch[]|NullsafePropertyFetch[]
|
||||||
*/
|
*/
|
||||||
public function findLocalPropertyFetchesByName(Class_ $class, string $paramName) : array
|
public function findLocalPropertyFetchesByName(Class_ $class, string $paramName) : array
|
||||||
{
|
{
|
||||||
/** @var PropertyFetch[]|StaticPropertyFetch[] $foundPropertyFetches */
|
/** @var PropertyFetch[]|StaticPropertyFetch[]|NullsafePropertyFetch[] $foundPropertyFetches */
|
||||||
$foundPropertyFetches = $this->betterNodeFinder->find($class->getMethods(), function (Node $subNode) use($paramName) : bool {
|
$foundPropertyFetches = $this->betterNodeFinder->find($class->getMethods(), function (Node $subNode) use($paramName) : bool {
|
||||||
if ($subNode instanceof PropertyFetch) {
|
if ($subNode instanceof PropertyFetch) {
|
||||||
return $this->propertyFetchAnalyzer->isLocalPropertyFetchName($subNode, $paramName);
|
return $this->propertyFetchAnalyzer->isLocalPropertyFetchName($subNode, $paramName);
|
||||||
}
|
}
|
||||||
|
if ($subNode instanceof NullsafePropertyFetch) {
|
||||||
|
return $this->propertyFetchAnalyzer->isLocalPropertyFetchName($subNode, $paramName);
|
||||||
|
}
|
||||||
if ($subNode instanceof StaticPropertyFetch) {
|
if ($subNode instanceof StaticPropertyFetch) {
|
||||||
return $this->propertyFetchAnalyzer->isLocalPropertyFetchName($subNode, $paramName);
|
return $this->propertyFetchAnalyzer->isLocalPropertyFetchName($subNode, $paramName);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user