for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Roave\ApiCompare\SourceLocator;
use Assert\Assert;
use Roave\BetterReflection\Identifier\Identifier;
use Roave\BetterReflection\SourceLocator\Ast\Locator;
use Roave\BetterReflection\SourceLocator\Located\LocatedSource;
use Roave\BetterReflection\SourceLocator\Type\AbstractSourceLocator;
final class StaticClassMapSourceLocator extends AbstractSourceLocator
{
/** @var string[] */
private $classMap;
public function __construct(
array $classMap,
Locator $astLocator
) {
parent::__construct($astLocator);
$realPaths = array_map('realpath', $classMap);
Assert::that($classMap)->all()->file();
Assert::that(array_keys($classMap))->all()->string()->notEmpty();
$this->classMap = $realPaths;
}
/**
* {@inheritDoc}
*/
protected function createLocatedSource(Identifier $identifier) : ?LocatedSource
if (! $identifier->isClass()) {
return null;
$classFile = $this->classMap[$identifier->getName()] ?? null;
if (null === $classFile) {
return new LocatedSource(file_get_contents($classFile), $classFile);