Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions rules/Php81/Rector/Array_/ArrayToFirstClassCallableRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ public function refactor(Node $node): StaticCall|MethodCall|null
return null;
}

if ($node->getAttribute(AttributeKey::IS_ARRAY_IN_ATTRIBUTE) === true) {
return null;
}

$scope = ScopeFetcher::fetch($node);

$arrayCallable = $this->arrayCallableMethodMatcher->match($node, $scope);
Expand Down
54 changes: 2 additions & 52 deletions src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\ArrowFunction;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\AssignOp;
use PhpParser\Node\Expr\AssignRef;
Expand All @@ -21,7 +20,6 @@
use PhpParser\Node\Expr\Cast;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\Clone_;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Expr\Empty_;
use PhpParser\Node\Expr\ErrorSuppress;
Expand Down Expand Up @@ -56,13 +54,9 @@
use PhpParser\Node\Name;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\NullableType;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Catch_;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassConst;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Do_;
use PhpParser\Node\Stmt\Echo_;
use PhpParser\Node\Stmt\ElseIf_;
Expand All @@ -72,7 +66,6 @@
use PhpParser\Node\Stmt\Finally_;
use PhpParser\Node\Stmt\For_;
use PhpParser\Node\Stmt\Foreach_;
use PhpParser\Node\Stmt\Function_;
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Interface_;
use PhpParser\Node\Stmt\Property;
Expand Down Expand Up @@ -207,8 +200,6 @@ public function processNodes(
return;
}

$this->decorateNodeAttrGroups($node, $mutatingScope, $nodeCallback);

if ((
$node instanceof Expression ||
$node instanceof Return_ ||
Expand Down Expand Up @@ -466,8 +457,8 @@ private function nodeScopeResolverProcessNodes(
try {
$this->nodeScopeResolver->processNodes($stmts, $mutatingScope, $nodeCallback);
} catch (ParserErrorsException|ParserException|ShouldNotHappenException|UndefinedVariableException) {
// nothing we can do more precise here as error parsing from deep internal PHPStan service with service injection we cannot reset
// in the middle of process
// nothing we can do more precise here as error parsing from deep internal PHPStan
// service with service injection we cannot reset in the middle of process
// fallback to fill by found scope
RectorNodeScopeResolver::processNodes($stmts, $mutatingScope);
}
Expand Down Expand Up @@ -528,40 +519,6 @@ private function processArrayItem(ArrayItem $arrayItem, MutatingScope $mutatingS
}
}

/**
* @param callable(Node $trait, MutatingScope $scope): void $nodeCallback
*/
private function decorateNodeAttrGroups(Node $node, MutatingScope $mutatingScope, callable $nodeCallback): void
{
// better to have AttrGroupsAwareInterface for all Node definition with attrGroups property
// but because may conflict with StmtsAwareInterface patch, this needs to be here
if (
! $node instanceof Param &&
! $node instanceof ArrowFunction &&
! $node instanceof Closure &&
! $node instanceof ClassConst &&
! $node instanceof ClassLike &&
! $node instanceof ClassMethod &&
! $node instanceof EnumCase &&
! $node instanceof Function_ &&
! $node instanceof Property
) {
return;
}

foreach ($node->attrGroups as $attrGroup) {
foreach ($attrGroup->attrs as $attr) {
foreach ($attr->args as $arg) {
$this->nodeScopeResolverProcessNodes(
[new Expression($arg->value)],
$mutatingScope,
$nodeCallback
);
}
}
}
}

private function processSwitch(Switch_ $switch, MutatingScope $mutatingScope): void
{
$switch->cond->setAttribute(AttributeKey::SCOPE, $mutatingScope);
Expand Down Expand Up @@ -682,11 +639,6 @@ private function resolveClassOrInterfaceScope(
$context = $this->privatesAccessor->getPrivateProperty($mutatingScope, 'context');
$this->privatesAccessor->setPrivateProperty($context, 'classReflection', null);

try {
return $mutatingScope->enterClass($classReflection);
} catch (ShouldNotHappenException) {
}

return $mutatingScope;
}

Expand All @@ -713,7 +665,6 @@ private function processTrait(Trait_ $trait, MutatingScope $mutatingScope, calla
if (! $this->reflectionProvider->hasClass($traitName)) {
$trait->setAttribute(AttributeKey::SCOPE, $mutatingScope);
$this->nodeScopeResolverProcessNodes($trait->stmts, $mutatingScope, $nodeCallback);
$this->decorateNodeAttrGroups($trait, $mutatingScope, $nodeCallback);

return;
}
Expand All @@ -736,6 +687,5 @@ private function processTrait(Trait_ $trait, MutatingScope $mutatingScope, calla

$trait->setAttribute(AttributeKey::SCOPE, $traitScope);
$this->nodeScopeResolverProcessNodes($trait->stmts, $traitScope, $nodeCallback);
$this->decorateNodeAttrGroups($trait, $traitScope, $nodeCallback);
}
}
8 changes: 8 additions & 0 deletions tests/Issues/Issue7374/Fixture/fixture.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Rector\Tests\Issues\Issue7374\Fixture;

use Rector\Tests\Issues\Issue7374\Source\BusibooksBusinesses;

final class ClassWithTwoMethods
{
private function displayTree($name, $data, $other = null)
Expand All @@ -19,11 +21,15 @@ final class ClassWithTwoMethods
));
}
}

?>
-----
<?php

namespace Rector\Tests\Issues\Issue7374\Fixture;

use Rector\Tests\Issues\Issue7374\Source\BusibooksBusinesses;

final class ClassWithTwoMethods
{
private function displayTree($data)
Expand All @@ -38,3 +44,5 @@ final class ClassWithTwoMethods
$this->displayTree($equity);
}
}

?>
9 changes: 9 additions & 0 deletions tests/Issues/Issue7374/Source/BusibooksBusinesses.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\Issues\Issue7374\Source;

final class BusibooksBusinesses
{
}
5 changes: 4 additions & 1 deletion tests/Issues/Issue7374/config/configured_rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
use Rector\Naming\Rector\ClassMethod\RenameVariableToMatchNewTypeRector;

return RectorConfig::configure()
->withRules([RemoveUnusedPrivateMethodParameterRector::class, RenameVariableToMatchNewTypeRector::class]);
->withRules([
RemoveUnusedPrivateMethodParameterRector::class,
RenameVariableToMatchNewTypeRector::class,
]);
Loading