PHP tool to parse code and extract statements.
$ composer require raphhh/trex-parser
First, give the PHP code to analyze:
$code = 'class Foo{}';
$analyzer = new ClassAnalyzer();
$classReflections = $analyzer->getClassReflections($code);
You can also give a file path to the analyzer:
$filePath = 'MyClass.php';
$analyzer = new ClassAnalyzer();
$classReflections = $analyzer->getClassReflectionsFromFile($filePath);
$classReflections
is an array of ReflectionClass.
$objects = [];
foreach($classReflections as $className => $classReflection){
$objects[$className] = $classReflection->newInstance();
}
$className = new ClassName('\Foo\Qux\Bar');
$className->getBaseName(); //"Bar"
$className = new ClassName('\Foo\Qux\Bar');
$className->getNamespace(); //"Foo\Qux"
$className = new ClassName('\Foo\Qux\Bar');
$className->split(); //["Foo", "Qux", "Bar"]