Skip to content

Commit

Permalink
Fix ShortenedObjectType not resolving to correct class reflection (#3397
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jackbentley committed May 6, 2023
1 parent 48e431b commit 6a8ebb9
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Rector\Tests\Php71\Rector\FuncCall\RemoveExtraParametersRector\Fixture;

use Rector\Tests\Php71\Rector\FuncCall\RemoveExtraParametersRector\Source\Stan;

final class SkipPHPStanPhar
{
public function run()
{
$stan = new Stan();
$stan->foo(1, 2);

Stan::bar(1, 2);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\Php71\Rector\FuncCall\RemoveExtraParametersRector\Source;

final class Stan
{
public function foo(): void
{
}

public static function bar(): void
{
}
}
8 changes: 8 additions & 0 deletions rules/Php71/Rector/FuncCall/RemoveExtraParametersRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ private function shouldSkipFunctionReflection(MethodReflection|FunctionReflectio
}
}

if ($reflection instanceof MethodReflection) {
$class = $reflection->getDeclaringClass();
$fileName = (string) $class->getFileName();
if (str_contains($fileName, 'phpstan.phar')) {
return \true;
}
}

return false;
}

Expand Down
10 changes: 8 additions & 2 deletions src/Reflection/ReflectionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\NodeTypeResolver\NodeTypeResolver;
use Rector\StaticTypeMapper\ValueObject\Type\ShortenedObjectType;
use Symfony\Contracts\Service\Attribute\Required;

final class ReflectionResolver
Expand Down Expand Up @@ -137,8 +138,13 @@ public function resolveMethodReflectionFromStaticCall(StaticCall $staticCall): ?
{
$objectType = $this->nodeTypeResolver->getType($staticCall->class);

/** @var array<class-string> $classNames */
$classNames = TypeUtils::getDirectClassNames($objectType);
if ($objectType instanceof ShortenedObjectType) {
/** @var array<class-string> $classNames */
$classNames = [$objectType->getFullyQualifiedName()];
} else {
/** @var array<class-string> $classNames */
$classNames = TypeUtils::getDirectClassNames($objectType);
}

$methodName = $this->nodeNameResolver->getName($staticCall->name);
if ($methodName === null) {
Expand Down

0 comments on commit 6a8ebb9

Please sign in to comment.