Skip to content

Commit

Permalink
Fix Rector autoloading issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed May 4, 2022
1 parent 58b6023 commit 46f51e7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
Expand Up @@ -18,6 +18,7 @@
use PHPStan\Reflection\BetterReflection\SourceLocator\OptimizedDirectorySourceLocatorRepository;
use PHPStan\Reflection\BetterReflection\SourceLocator\OptimizedSingleFileSourceLocatorRepository;
use PHPStan\Reflection\BetterReflection\SourceLocator\PhpVersionBlacklistSourceLocator;
use PHPStan\Reflection\BetterReflection\SourceLocator\RectorAutoloadSourceLocator;
use PHPStan\Reflection\BetterReflection\SourceLocator\SkipClassAliasSourceLocator;
use function array_merge;
use function array_unique;
Expand Down Expand Up @@ -108,6 +109,7 @@ public function create(): SourceLocator
if (!$this->disableRuntimeReflectionProvider) {
$locators[] = new ClassWhitelistSourceLocator($this->autoloadSourceLocator, $this->staticReflectionClassNamePatterns);
} else {
$locators[] = new RectorAutoloadSourceLocator();
$locators[] = $this->autoloadSourceLocator;
}
$locators[] = new PhpVersionBlacklistSourceLocator(new PhpInternalSourceLocator($astLocator, $this->reflectionSourceStubber), $this->phpstormStubsSourceStubber);
Expand Down
@@ -0,0 +1,38 @@
<?php declare(strict_types = 1);

namespace PHPStan\Reflection\BetterReflection\SourceLocator;

use PHPStan\BetterReflection\Identifier\Identifier;
use PHPStan\BetterReflection\Identifier\IdentifierType;
use PHPStan\BetterReflection\Reflection\Reflection;
use PHPStan\BetterReflection\Reflector\Reflector;
use PHPStan\BetterReflection\SourceLocator\Type\SourceLocator;
use function class_exists;
use function interface_exists;
use function strpos;
use function strtolower;
use function trait_exists;

class RectorAutoloadSourceLocator implements SourceLocator
{

public function locateIdentifier(Reflector $reflector, Identifier $identifier): ?Reflection
{
if (!$identifier->isClass()) {
return null;
}

$className = strtolower($identifier->getName());
if (strpos($className, 'rectorprefix') === 0 || strpos($className, 'rector\\') === 0) {
class_exists($identifier->getName()) || interface_exists($identifier->getName()) || trait_exists($identifier->getName());
}

return null;
}

public function locateIdentifiersByType(Reflector $reflector, IdentifierType $identifierType): array
{
return [];
}

}

0 comments on commit 46f51e7

Please sign in to comment.