-
Notifications
You must be signed in to change notification settings - Fork 478
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempt to load remaining classes after skipping them in ClassBlackli…
…stSourceLocator if they're not in Composer paths
- Loading branch information
1 parent
3902d73
commit 2e61259
Showing
3 changed files
with
55 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/Reflection/BetterReflection/SourceLocator/ClassWhitelistSourceLocator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Reflection\BetterReflection\SourceLocator; | ||
|
||
use Nette\Utils\Strings; | ||
use Roave\BetterReflection\Identifier\Identifier; | ||
use Roave\BetterReflection\Identifier\IdentifierType; | ||
use Roave\BetterReflection\Reflection\Reflection; | ||
use Roave\BetterReflection\Reflector\Reflector; | ||
use Roave\BetterReflection\SourceLocator\Type\SourceLocator; | ||
|
||
class ClassWhitelistSourceLocator implements SourceLocator | ||
{ | ||
|
||
private SourceLocator $sourceLocator; | ||
|
||
/** @var string[] */ | ||
private array $patterns; | ||
|
||
/** | ||
* @param SourceLocator $sourceLocator | ||
* @param string[] $patterns | ||
*/ | ||
public function __construct( | ||
SourceLocator $sourceLocator, | ||
array $patterns | ||
) | ||
{ | ||
$this->sourceLocator = $sourceLocator; | ||
$this->patterns = $patterns; | ||
} | ||
|
||
public function locateIdentifier(Reflector $reflector, Identifier $identifier): ?Reflection | ||
{ | ||
if ($identifier->isClass()) { | ||
foreach ($this->patterns as $pattern) { | ||
if (Strings::match($identifier->getName(), $pattern) !== null) { | ||
return $this->sourceLocator->locateIdentifier($reflector, $identifier); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
return $this->sourceLocator->locateIdentifier($reflector, $identifier); | ||
} | ||
|
||
public function locateIdentifiersByType(Reflector $reflector, IdentifierType $identifierType): array | ||
{ | ||
return $this->sourceLocator->locateIdentifiersByType($reflector, $identifierType); | ||
} | ||
|
||
} |