Skip to content

Commit

Permalink
Allow usage of a since PHP version argument.
Browse files Browse the repository at this point in the history
Most projects support PHP 5.4 at a minimum these days, therefore its
almost useless to pollute the result set with extensions bundled since 5.2 etc.

This additional flag `--since-version` llows you to pass a version string which will
be compared using the `version_compare` function.
If the extension php version is less it will be ommitted from the report.
  • Loading branch information
leemason committed Feb 17, 2017
1 parent 8767879 commit c893113
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions bin/phpca
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ if (isset($args['--extension']))
else
$analyzer->loadData();

if (isset($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 c893113

Please sign in to comment.