Reflect 3.0.0-beta-1 preview.

While 3.0.0-beta1 was initially planned on 2015-01-30 (see roadmap), it’s now ready to be released on Februrary 3rd 2015.

Highlight the main feature that will be available in the new API 3.0 :

  • A unified API for all platforms and usages.
    Command-Line Interface or via PHP code with the same pattern.

With Symfony Console verbosity level 3, you will print the raw API response rather than the console view report. Easy to debug and compare.

  • Example 1: Compare analyser run process (with a single analyser)

CLI
$ php bin\phpreflect -vvv analyser:run ../src
PHP
<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';

use Bartlett\Reflect\Client;

// creates an instance of client
$client = new Client();

// request for a Bartlett\Reflect\Api\Analyser
$api = $client->api('analyser');

// perform request, on a data source with default analyser
$dataSource = dirname(__DIR__) . '/src';
$analysers  = array('structure');

$metrics = $api->run($dataSource, $analysers);

print_r($metrics);

  • Example 2: Compare analyser list process

CLI
$ php bin\phpreflect -vvv analyser:list
PHP
<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';

use Bartlett\Reflect\Client;

// creates an instance of client
$client = new Client();

// request for a Bartlett\Reflect\Api\Analyser
$api = $client->api('analyser');

$analysers = $api->dir();

print_r($analysers);

  • Example 3: Compare plugin list process

CLI
$ php bin\phpreflect -vvv plugin:list
PHP
<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';

use Bartlett\Reflect\Client;
use Bartlett\Reflect\Environment;

// defines environment where to find the JSON config file
if (!getenv("BARTLETTRC")) {
    putenv("BARTLETTRC=phpreflect.json");
}
Environment::setScanDir();

// creates an instance of client
$client = new Client();

// request for a Bartlett\Reflect\Api\Plugin
$api = $client->api('plugin');

$plugins = $api->dir();

print_r($plugins);

  • Example 4: Compare reflection class process

CLI
$ php bin\phpreflect reflection:class Bartlett\Reflect ../src
Do not use verbose level 3 to compare results in this case. It will return a Bartlett\Reflect\Model\ClassModel instance.
PHP
<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';

use Bartlett\Reflect\Client;

// creates an instance of client
$client = new Client();

// request for a Bartlett\Reflect\Api\Reflection
$api = $client->api('reflection');

// perform request, on a data source
$dataSource = dirname(__DIR__) . '/src';

$model = $api->class_('Bartlett\\Reflect', $dataSource);

echo $model;

CLI or PHP mode will print such output

Class [ <user> class Bartlett\Reflect extends Bartlett\Reflect\Event\AbstractDispatcher ] {
  @@ C:\home\github\php-reflect\src\Bartlett\Reflect.php 45 - 340

  - Constants [0] {
  }

  - Properties [2] {
    Property [ private $analysers ]
    Property [ private $dataSourceId ]
  }

  - Methods [6] {
    Method [ <user> public method __construct ] {
      @@ C:\home\github\php-reflect\src\Bartlett\Reflect.php 53 - 57

      - Parameters [0] {
      }
    }

    Method [ <user> public method addAnalyser ] {
      @@ C:\home\github\php-reflect\src\Bartlett\Reflect.php 66 - 71

      - Parameters [1] {
        Parameter #0 [ <required> PhpParser\NodeVisitor $analyser ]
      }
    }

    Method [ <user> public method getAnalysers ] {
      @@ C:\home\github\php-reflect\src\Bartlett\Reflect.php 78 - 81

      - Parameters [0] {
      }
    }

    Method [ <user> public method setDataSourceId ] {
      @@ C:\home\github\php-reflect\src\Bartlett\Reflect.php 90 - 94

      - Parameters [1] {
        Parameter #0 [ <required> $id ]
      }
    }

    Method [ <user> public method getDataSourceId ] {
      @@ C:\home\github\php-reflect\src\Bartlett\Reflect.php 101 - 104

      - Parameters [0] {
      }
    }

    Method [ <user> public method parse ] {
      @@ C:\home\github\php-reflect\src\Bartlett\Reflect.php 113 - 339

      - Parameters [1] {
        Parameter #0 [ <required> Symfony\Component\Finder\Finder $finder ]
      }
    }
  }
}
Published by Laurent Laville on 2015-02-02