Skip to content

Commit

Permalink
Merge branch 'since-version'
Browse files Browse the repository at this point in the history
  • Loading branch information
leemason committed Feb 17, 2017
2 parents 8767879 + 7927000 commit d75700d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion bin/phpca
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use wapmorgan\PhpCodeAnalyzer\PhpCodeAnalyzer;

$doc = <<<DOC
Usage:
phpca [-v] [--no-report] [--no-progress] [FILES ...]
phpca [-v] [--no-report] [--no-progress] [--since-version=<version>] [FILES ...]
phpca [-v] --extension=<ext> [FILES ...]
phpca -h
Expand All @@ -18,6 +18,7 @@ Options:
--extension=<ext> Look for usage a specific extension
--no-report Turn off summary report
--no-progress Turn off progress
--since-version=<version> Only include extensions not included since version
DOC;

Expand All @@ -39,6 +40,9 @@ if (isset($args['--extension']))
else
$analyzer->loadData();

if (isset($args['--since-version']) && $args['--since-version'])
$analyzer->setSinceVersion($args['--since-version']);

if (!empty($args['FILES'])) {
foreach ($args['FILES'] as $file) {
if (is_dir($file)) {
Expand Down
12 changes: 12 additions & 0 deletions src/PhpCodeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ class PhpCodeAnalyzer {
private $constantsSet = array();
private $extensions = array();
private $usedExtensions = array();
private $sinceVersion = null;

public function setSinceVersion($version){
$this->sinceVersion = $version;
}

public function loadData() {
foreach (glob(dirname(dirname(__FILE__)).'/data/*.php') as $extension_file) {
Expand Down Expand Up @@ -266,6 +271,13 @@ public function printUsedExtensions() {
arsort($this->usedExtensions);
foreach ($this->usedExtensions as $extension => $uses_number) {
$extension_data = $this->extensions[$extension];

if (!is_null($this->sinceVersion) && isset($extension_data['php_version'])) {
if(version_compare($extension_data['php_version'], $this->sinceVersion, '<=')){
continue;
}
}

if (isset($extension_data['description']))
echo '- ['.$extension.'] '.$extension_data['description'].'.';
else
Expand Down

0 comments on commit d75700d

Please sign in to comment.