PhpMetrics icon indicating copy to clipboard operation
PhpMetrics copied to clipboard

[Bug] Trying to scan an excluded folder

Open stolentine opened this issue 3 years ago • 2 comments

Bug report

 php ./vendor/bin/phpmetrics --config=.phpmetrics.json      

Executing system analyzes...

Executing composer analyzes, requesting https://packagist.org...
Fatal error: Uncaught UnexpectedValueException: RecursiveDirectoryIterator::__construct(./docker/volumes/data-test): Failed to open directory: Permission denied in /var/www/vendor/phpmetrics/phpmetrics/src/Hal/Component/File/Finder.php:88
Stack trace:
#0 [internal function]: RecursiveDirectoryIterator->__construct('./docker/volume...', 0)
#1 [internal function]: RecursiveDirectoryIterator->getChildren()
#2 /var/www/vendor/phpmetrics/phpmetrics/src/Hal/Component/File/Finder.php(88): FilterIterator->next()
#3 /var/www/vendor/phpmetrics/phpmetrics/src/Hal/Metric/System/Packages/Composer/Composer.php(76): Hal\Component\File\Finder->fetch(Array)
#4 /var/www/vendor/phpmetrics/phpmetrics/src/Hal/Metric/System/Packages/Composer/Composer.php(39): Hal\Metric\System\Packages\Composer\Composer->getComposerJsonRequirements()
#5 /var/www/vendor/phpmetrics/phpmetrics/src/Hal/Application/Analyze.php(144): Hal\Metric\System\Packages\Composer\Composer->calculate(Object(Hal\Metric\Metrics))
#6 /var/www/vendor/phpmetrics/phpmetrics/src/Hal/Application/Application.php(57): Hal\Application\Analyze->run(Array)
#7 /var/www/vendor/phpmetrics/phpmetrics/bin/phpmetrics(27): Hal\Application\Application->run(Array)
#8 {main}
  thrown in /var/www/vendor/phpmetrics/phpmetrics/src/Hal/Component/File/Finder.php on line 88

My config

{
  "includes": [
    "app"
  ],
  "exclude": [
    "tests",
    "vendor",
    "docker"
  ],
  "report": {
    "html": "./tmp/php-metrics/report/",
    "csv": "./tmp/php-metrics/report.csv",
    "json": "./tmp/php-metrics/report.json",
    "violations": "./tmp/php-metrics/violations.xml"
  }
}

"docker" folder has access restrictions and added to config exclude. Despite this, the script tries to scan this folder.

If you run the script from another folder, for example from vendor, then there is no such problem. It looks like at startup there is a search for something without checking permission.

stolentine avatar Sep 05 '21 15:09 stolentine

Couldn't reproduce. It scans inside includes folder and excludes all the directories in array. Doesn't matter from where phpmetrics in run, as long as relative path to .phpmetrics.json is provided.

veerajongit avatar Nov 07 '23 12:11 veerajongit