Skip to content

Raphhh/trex-parser

Repository files navigation

TRex parser

Latest Stable Version Build Status Scrutinizer Quality Score Code Coverage SensioLabsInsight Dependency Status Total Downloads Reference Status License

PHP tool to parse code and extract statements.

Install

$ composer require raphhh/trex-parser

Usage

ClassAnalyzer

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

Retrieve base name

$className = new ClassName('\Foo\Qux\Bar');
$className->getBaseName(); //"Bar"

Retrieve namespace

$className = new ClassName('\Foo\Qux\Bar');
$className->getNamespace(); //"Foo\Qux"

Split

$className = new ClassName('\Foo\Qux\Bar');
$className->split(); //["Foo", "Qux", "Bar"]

About

PHP tool to parse strings and extract statements

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages