Skip to content

Commit

Permalink
switch from internal api v3 to v5 with a lite analyser:run command wi…
Browse files Browse the repository at this point in the history
…th only source path (no more json config file required)
  • Loading branch information
llaville committed Aug 26, 2020
1 parent 21d6b55 commit c0959a1
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 170 deletions.
7 changes: 0 additions & 7 deletions bin/phpcompatinfo
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ if (\Phar::running()) {
if (!file_exists($vendorDir . '/autoload.php')) {
$vendorDir = dirname(dirname($baseDir));
}

if (!getenv("BARTLETTRC")) {
putenv("BARTLETTRC=" . $appName . '.json');
}
}
$loader = require_once $vendorDir . '/autoload.php';
$loader->setUseIncludePath(true);
Expand All @@ -23,10 +19,7 @@ if (PHP_SAPI !== 'cli') {
return;
}

use Bartlett\Reflect\Environment;
use Bartlett\CompatInfo\Console\Application;

Environment::setScanDir();

$application = new Application();
$application->run();
14 changes: 0 additions & 14 deletions bin/phpcompatinfo.json.dist

This file was deleted.

16 changes: 15 additions & 1 deletion src/Bartlett/CompatInfo/Api/Analyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

namespace Bartlett\CompatInfo\Api;

use Bartlett\Reflect\Api\BaseApi;

/**
* Collect and analyse metrics of parsing results.
*
Expand All @@ -22,6 +24,18 @@
* @license https://opensource.org/licenses/BSD-3-Clause The 3-Clause BSD License
* @since Class available since Release 5.4.0
*/
class Analyser extends \Bartlett\Reflect\Api\Analyser
class Analyser extends BaseApi
{
/**
* Analyse a data source and display results.
*
* @param string $source Path to the data source
*
* @return array metrics
*/
public function run($source)
{
$source = trim($source);
return $this->request('analyser/run', 'POST', array($source));
}
}
118 changes: 0 additions & 118 deletions src/Bartlett/CompatInfo/Api/V3/Analyser.php

This file was deleted.

57 changes: 57 additions & 0 deletions src/Bartlett/CompatInfo/Api/V5/Analyser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php declare(strict_types=1);

/**
* Collect and analyse metrics of parsing results.
*
* PHP version 7
*
* @category PHP
* @package PHP_CompatInfo
* @author Laurent Laville <[email protected]>
* @license https://opensource.org/licenses/BSD-3-Clause The 3-Clause BSD License
*/

namespace Bartlett\CompatInfo\Api\V5;

use Bartlett\CompatInfo\Analyser\CompatibilityAnalyser;
use Bartlett\Reflect;

use RuntimeException;

/**
* Collect and analyse metrics of parsing results.
*
* @category PHP
* @package PHP_CompatInfo
* @author Laurent Laville <[email protected]>
* @license https://opensource.org/licenses/BSD-3-Clause The 3-Clause BSD License
* @since Class available since Release 5.4.0
*/
class Analyser extends Reflect\Api\V3\Common
{
/**
* Analyse a data source and display results.
*
* @param string $source Path to the data source or its alias
*
* @return array metrics
*/
public function run(string $source)
{
$finder = $this->findProvider($source, false);

if ($finder === false) {
throw new RuntimeException(
'None data source matching'
);
}

$parser = new Parser();
$parser->setEventDispatcher($this->eventDispatcher);
$parser->setDataSourceId($this->dataSourceId);

$parser->addAnalyser(new CompatibilityAnalyser());

return $parser->parse($finder);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace Bartlett\CompatInfo\Api\V3;
namespace Bartlett\CompatInfo\Api\V5;

use Bartlett\CompatInfo\Collection\ReferenceCollection;
use Bartlett\CompatInfo\PhpParser\NodeVisitor\NameResolverVisitor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @license https://opensource.org/licenses/BSD-3-Clause The 3-Clause BSD License
*/

namespace Bartlett\CompatInfo\Api\V3;
namespace Bartlett\CompatInfo\Api\V5;

use Bartlett\CompatInfoDb\ExtensionFactory;

Expand Down
14 changes: 3 additions & 11 deletions src/Bartlett/CompatInfo/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
class Client
{
const API_V3 = 'http://php5.laurent-laville.org/compatinfo/api/v3/';
const API_V5 = 'http://php5.laurent-laville.org/compatinfo/api/v5/';

private $client;
private $token;
Expand All @@ -37,7 +37,7 @@ class Client
*/
public function __construct()
{
$this->client = new LocalClient('Bartlett\CompatInfo\Api\V3');
$this->client = new LocalClient('Bartlett\CompatInfo\Api\V5');
}

/**
Expand All @@ -51,14 +51,6 @@ public function __construct()
public function api($name): BaseApi
{
$classes = array(
'Bartlett\Reflect\Api\\' => array(
'Cache',
'Config',
'Diagnose',
'Diagram',
'Plugin',
'Reflection',
),
'Bartlett\CompatInfo\Api\\' => array(
'Analyser',
'Reference'
Expand All @@ -80,7 +72,7 @@ public function api($name): BaseApi
);
}

$this->client->setNamespace($ns . 'V3');
$this->client->setNamespace($ns . 'V5');

return new $class($this->client, $this->token);
}
Expand Down
18 changes: 1 addition & 17 deletions src/Bartlett/CompatInfo/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,7 @@ public function __construct(string $version = 'UNKNOWN')
$jsonFile = './' . getenv("BARTLETTRC");
}

$exceptions = array(
'analyser' => array(
'run' => array(
'analysers' => array(
'default' => array('compatibility'),
),
),
),
'config' => array(
'validate' => array(
'file' => array(
'default' => $jsonFile,
'replaceTokens' => array('{json}' => getenv("BARTLETTRC"))
),
),
),
);
$exceptions = array();

$factory = new CommandFactory($this, $exceptions);
$this->addCommands($factory->generateCommands());
Expand Down

0 comments on commit c0959a1

Please sign in to comment.