-
-
Notifications
You must be signed in to change notification settings - Fork 687
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add DynamicSourceLocator that is shared by PHPStan and Rector
- Loading branch information
1 parent
9f28fe5
commit 2f3a909
Showing
10 changed files
with
189 additions
and
44 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
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
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
...type-resolver/src/Reflection/BetterReflection/SourceLocator/IntermediateSourceLocator.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 Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocator; | ||
|
||
use _HumbugBoxfac515c46e83\Roave\BetterReflection\Identifier\Identifier; | ||
use _HumbugBoxfac515c46e83\Roave\BetterReflection\Identifier\IdentifierType; | ||
use _HumbugBoxfac515c46e83\Roave\BetterReflection\Reflection\Reflection; | ||
use _HumbugBoxfac515c46e83\Roave\BetterReflection\Reflector\Reflector; | ||
use _HumbugBoxfac515c46e83\Roave\BetterReflection\SourceLocator\Type\SourceLocator; | ||
use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocator; | ||
|
||
final class IntermediateSourceLocator implements SourceLocator | ||
{ | ||
/** | ||
* @var DynamicSourceLocator | ||
*/ | ||
private $dynamicSourceLocator; | ||
|
||
public function __construct(DynamicSourceLocator $dynamicSourceLocator) | ||
{ | ||
$this->dynamicSourceLocator = $dynamicSourceLocator; | ||
} | ||
|
||
public function locateIdentifier(Reflector $reflector, Identifier $identifier): ?Reflection | ||
{ | ||
$sourceLocator = $this->dynamicSourceLocator->provide(); | ||
|
||
$locatedIdentifier = $sourceLocator->locateIdentifier($reflector, $identifier); | ||
if ($locatedIdentifier instanceof Reflection) { | ||
return $locatedIdentifier; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* Find all identifiers of a type | ||
* @return Reflection[] | ||
*/ | ||
public function locateIdentifiersByType(Reflector $reflector, IdentifierType $identifierType): array | ||
{ | ||
$sourceLocator = $this->dynamicSourceLocator->provide(); | ||
|
||
$reflections = $sourceLocator->locateIdentifiersByType($reflector, $identifierType); | ||
if ($reflections !== []) { | ||
return $reflections; | ||
} | ||
|
||
return []; | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...e-resolver/src/Reflection/BetterReflection/SourceLocatorProvider/DynamicSourceLocator.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,77 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider; | ||
|
||
use _HumbugBoxfac515c46e83\Roave\BetterReflection\Reflector\FunctionReflector; | ||
use _HumbugBoxfac515c46e83\Roave\BetterReflection\SourceLocator\Ast\Locator; | ||
use _HumbugBoxfac515c46e83\Roave\BetterReflection\SourceLocator\Type\AggregateSourceLocator; | ||
use _HumbugBoxfac515c46e83\Roave\BetterReflection\SourceLocator\Type\DirectoriesSourceLocator; | ||
use _HumbugBoxfac515c46e83\Roave\BetterReflection\SourceLocator\Type\SourceLocator; | ||
use PhpParser\Parser; | ||
use PHPStan\DependencyInjection\Container; | ||
use PHPStan\Reflection\BetterReflection\SourceLocator\FileNodesFetcher; | ||
use PHPStan\Reflection\BetterReflection\SourceLocator\OptimizedSingleFileSourceLocator; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
final class DynamicSourceLocator | ||
{ | ||
// /** | ||
// * @var string[] | ||
// */ | ||
// private $directories = []; | ||
// | ||
// /** | ||
// * @var Parser | ||
// */ | ||
// private $parser; | ||
|
||
/** | ||
* @var SmartFileInfo[] | ||
*/ | ||
private $fileInfos = []; | ||
|
||
// /** | ||
// * @var Container | ||
// */ | ||
// private $container; | ||
|
||
/** | ||
* @var FileNodesFetcher | ||
*/ | ||
private $fileNodesFetcher; | ||
|
||
public function __construct(/*Parser $parser , Container $container,*/ FileNodesFetcher $fileNodesFetcher) | ||
{ | ||
// $this->parser = $parser; | ||
// $this->container = $container; | ||
$this->fileNodesFetcher = $fileNodesFetcher; | ||
} | ||
|
||
// public function addDirectory(string $directory): void | ||
// { | ||
// $this->directories[] = $directory; | ||
// } | ||
|
||
public function addFileInfo(SmartFileInfo $fileInfo): void | ||
{ | ||
$this->fileInfos[] = $fileInfo; | ||
} | ||
|
||
public function provide(): SourceLocator | ||
{ | ||
// $locator = new Locator($this->parser, function (): FunctionReflector { | ||
// return $this->container->getService('betterReflectionFunctionReflector'); | ||
// }); | ||
// | ||
$sourceLocators = []; | ||
// $sourceLocators[] = new DirectoriesSourceLocator($this->directories, $locator); | ||
|
||
foreach ($this->fileInfos as $fileInfo) { | ||
$sourceLocators[] = new OptimizedSingleFileSourceLocator($this->fileNodesFetcher, $fileInfo->getRealPath()); | ||
} | ||
|
||
return new AggregateSourceLocator($sourceLocators); | ||
} | ||
} |
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