for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Elao\Enum\Bridge\PhpTranslation\Extractor;
use Elao\Enum\ReadableEnumInterface;
use Translation\Extractor\Model\SourceCollection;
use Translation\Extractor\Model\SourceLocation;
final class ReflectionEnumExtractor
{
/**
* Callable returning list of FCQN candidates for Enums.
* It's necessary for files containing these classes to be already loaded.
*
* @var callable
*/
private $classLoader;
public function __construct(callable $classLoader = null)
$this->classLoader = $classLoader ?: 'get_declared_classes';
}
public function getSourceLocations(SourceCollection $sourceCollection)
foreach (call_user_func($this->classLoader) as $class) {
if (!\in_array(ReadableEnumInterface::class, class_implements($class), true)) {
continue;
$reflectionClass = new \ReflectionClass($class);
if ($reflectionClass->isAbstract()) {
$line = $reflectionClass->getMethod('readables')->getStartLine();
/** @var ReadableEnumInterface $class */
foreach ($class::readables() as $value => $label) {
$sourceCollection->addLocation(new SourceLocation($label, $reflectionClass->getFileName(), $line));