Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Trying to scan an excluded folder #463

Open
stolentine opened this issue Sep 5, 2021 · 2 comments
Open

[Bug] Trying to scan an excluded folder #463

stolentine opened this issue Sep 5, 2021 · 2 comments
Labels

Comments

@stolentine
Copy link

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.

@niconoe- niconoe- added the bug label Jan 30, 2023
@veerajongit
Copy link

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.

@wojciech-z
Copy link

I have the same issue. In my case it is also a Docker setup.

I've found that it does in fact attempt to find composer.json in ./:
https://github.com/phpmetrics/PhpMetrics/blob/v3.0.0rc6/src/Hal/Metric/System/Packages/Composer/Composer.php#L134

The search is recursive and first gathers the files and then checks if composer.json is there. Which means it will attempt to descend into all directories and fail if it cannot do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants