| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | namespace PHPStan\BetterReflection\SourceLocator\Type; |
| 6: | |
| 7: | use InvalidArgumentException; |
| 8: | use PHPStan\BetterReflection\Identifier\Identifier; |
| 9: | use PHPStan\BetterReflection\SourceLocator\Ast\Locator; |
| 10: | use PHPStan\BetterReflection\SourceLocator\Exception\InvalidFileLocation; |
| 11: | use PHPStan\BetterReflection\SourceLocator\FileChecker; |
| 12: | use PHPStan\BetterReflection\SourceLocator\Located\LocatedSource; |
| 13: | |
| 14: | use function file_get_contents; |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | class SingleFileSourceLocator extends AbstractSourceLocator |
| 25: | { |
| 26: | |
| 27: | |
| 28: | |
| 29: | private $fileName; |
| 30: | |
| 31: | public function __construct(string $fileName, Locator $astLocator) |
| 32: | { |
| 33: | $this->fileName = $fileName; |
| 34: | FileChecker::assertReadableFile($fileName); |
| 35: | |
| 36: | parent::__construct($astLocator); |
| 37: | } |
| 38: | |
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: | |
| 44: | |
| 45: | protected function createLocatedSource(Identifier $identifier): ?\PHPStan\BetterReflection\SourceLocator\Located\LocatedSource |
| 46: | { |
| 47: | return new LocatedSource(file_get_contents($this->fileName), $identifier->getName(), $this->fileName); |
| 48: | } |
| 49: | } |
| 50: | |