Skip to content

Commit

Permalink
Updated Rector to commit 16d1df9be8cdbdf6e5b67f97fa225731ac0c9675
Browse files Browse the repository at this point in the history
rectorphp/rector-src@16d1df9 [NodeTypeResolver] No need to resolve class name on anonymous classes (#5886)
  • Loading branch information
TomasVotruba committed May 16, 2024
1 parent 6372b90 commit df8a377
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
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 = 'db213ee986c942d58e397b3713564349541e8de5';
public const PACKAGE_VERSION = '16d1df9be8cdbdf6e5b67f97fa225731ac0c9675';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-05-16 19:48:22';
public const RELEASE_DATE = '2024-05-16 20:19:00';
/**
* @var int
*/
Expand Down
23 changes: 15 additions & 8 deletions src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
use PHPStan\Analyser\ScopeContext;
use PHPStan\Node\UnreachableStatementNode;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\ShouldNotHappenException;
use PHPStan\Type\ObjectType;
use PHPStan\Type\TypeCombinator;
use Rector\Exception\ShouldNotHappenException;
use Rector\NodeAnalyzer\ClassAnalyzer;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\Node\AttributeKey;
Expand Down Expand Up @@ -231,7 +231,7 @@ private function nodeScopeResolverProcessNodes(array $stmts, MutatingScope $muta
{
try {
$this->nodeScopeResolver->processNodes($stmts, $mutatingScope, $nodeCallback);
} catch (\PHPStan\ShouldNotHappenException $exception) {
} catch (ShouldNotHappenException $exception) {
}
}
private function processCallike(CallLike $callLike, MutatingScope $mutatingScope) : void
Expand Down Expand Up @@ -342,25 +342,26 @@ private function processTernary(Ternary $ternary, MutatingScope $mutatingScope)
*/
private function resolveClassOrInterfaceScope($classLike, MutatingScope $mutatingScope) : MutatingScope
{
$className = $this->resolveClassName($classLike);
$isAnonymous = $this->classAnalyzer->isAnonymousClass($classLike);
// is anonymous class? - not possible to enter it since PHPStan 0.12.33, see https://github.com/phpstan/phpstan-src/commit/e87fb0ec26f9c8552bbeef26a868b1e5d8185e91
if ($classLike instanceof Class_ && $isAnonymous) {
$classReflection = $this->reflectionProvider->getAnonymousClassReflection($classLike, $mutatingScope);
} elseif (!$this->reflectionProvider->hasClass($className)) {
return $mutatingScope;
} else {
$className = $this->resolveClassName($classLike);
if (!$this->reflectionProvider->hasClass($className)) {
return $mutatingScope;
}
$classReflection = $this->reflectionProvider->getClass($className);
}
try {
return $mutatingScope->enterClass($classReflection);
} catch (\PHPStan\ShouldNotHappenException $exception) {
} catch (ShouldNotHappenException $exception) {
}
$context = $this->privatesAccessor->getPrivateProperty($mutatingScope, 'context');
$this->privatesAccessor->setPrivateProperty($context, 'classReflection', null);
try {
return $mutatingScope->enterClass($classReflection);
} catch (\PHPStan\ShouldNotHappenException $exception) {
} catch (ShouldNotHappenException $exception) {
}
return $mutatingScope;
}
Expand All @@ -373,7 +374,7 @@ private function resolveClassName($classLike) : string
return (string) $classLike->namespacedName;
}
if (!$classLike->name instanceof Identifier) {
throw new ShouldNotHappenException();
return '';
}
return $classLike->name->toString();
}
Expand All @@ -383,6 +384,12 @@ private function resolveClassName($classLike) : string
private function processTrait(Trait_ $trait, MutatingScope $mutatingScope, callable $nodeCallback) : void
{
$traitName = $this->resolveClassName($trait);
if (!$this->reflectionProvider->hasClass($traitName)) {
$trait->setAttribute(AttributeKey::SCOPE, $mutatingScope);
$this->nodeScopeResolverProcessNodes($trait->stmts, $mutatingScope, $nodeCallback);
$this->decorateTraitAttrGroups($trait, $mutatingScope);
return;
}
$traitClassReflection = $this->reflectionProvider->getClass($traitName);
$traitScope = clone $mutatingScope;
/** @var ScopeContext $scopeContext */
Expand Down

0 comments on commit df8a377

Please sign in to comment.