CompatInfo 4.0.0-beta-1 preview.

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

Highlight the main feature that will be available in the new API 4.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\phpcompatinfo -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('compatibility');

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

print_r($metrics);

  • Example 2: Compare analyser list process

CLI
$ php bin\phpcompatinfo -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\CompatInfo\Api\Analyser
$api = $client->api('analyser');

$analysers = $api->dir();

print_r($analysers);

  • Example 3: Compare reference list process

CLI
$ php bin\phpcompatinfo -vvv reference: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\CompatInfo\Api\Reference
$api = $client->api('reference');

$refs = $api->dir();

print_r($refs);

  • Example 4: Compare reference show process (with full details)

CLI
$ php bin\phpcompatinfo -vvv reference:show amqp
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\CompatInfo\Api\Reference
$api = $client->api('reference');

$ref = $api->show('amqp');

print_r($ref);

  • Example 5: Compare reference show process (with closure to filter results)

CLI
$ php bin\phpcompatinfo -vvv reference:show amqp --classes --filter=YourFilters.php

With (for example) a YourFilters.php file contents as follow (anywhere in your include_path)

<?php
// returns all classes of extension that have release 1.0.0 or greater
$closure = function ($data) {
    foreach ($data as $title => &$values) {
        foreach ($values as $key => $val) {
            switch ($title) {
                case 'classes':
                    if (version_compare($val['ext.min'], '1.0.0', 'lt')) {
                        unset($values[$key]);
                    }
                    break;
            }
        }
    }
    return $data;
};
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\CompatInfo\Api\Reference
$api = $client->api('reference');

include_once 'YourFilters.php';

$ref = $api->show('amqp', $closure, false, false, false, false, false, true);

print_r($ref);

  • Example 6: Compare reflection class process (inherit from php-reflect)

CLI
$ php bin\phpcompatinfo 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