Skip to content

Commit

Permalink
security-checker - enable overriding composer.lock location
Browse files Browse the repository at this point in the history
Necessary if only src/ directory is analyzed in monorepo
  • Loading branch information
zdenekdrahos committed Apr 30, 2022
1 parent 16174b5 commit 5bac59f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .phpqa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ psalm:
deptrac:
depfile: null # depfile.yml (https://github.com/qossmic/deptrac#the-depfile)

security-checker:
composerLock: null # use it if composer.lock is not in current working directory or analyzed directory

# paths are relative to .phpqa.yml, so don't copy-paste this section if you don't have custom templates
report:
phploc: app/report/phploc.xsl
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ Tool | Settings | Default Value | Your value
[psalm.showInfo](https://github.com/vimeo/psalm/wiki/Running-Psalm#command-line-options) | Display or not information (non-error) messages (option `--show-info=` of psalm) | `true` | Boolean value
[psalm.memoryLimit](https://github.com/vimeo/psalm/issues/842) | Custom memory limit, ignore unless you are getting `Fatal error: Allowed memory size of ... bytes exhausted` | `null` | String value, e.g. `'1024M'`, `'1G'`
[deptrac.depfile](https://github.com/vimeo/psalm/wiki/Configuration) | Complete [deptract config](https://github.com/qossmic/deptrac#getting-started) _(phpqa won't update source and excluded files)_ | `null` | Path to `depfile.yml` file
[composer.lock](https://github.com/EdgedesignCZ/phpqa/blob/master/.phpqa.yml#L94) | Use it if composer.lock is not in current working directory or analyzed directory | `null` | Path to `composer.lock` file

## HTML reports

Expand Down
22 changes: 15 additions & 7 deletions src/Tools/Analyzer/SecurityChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,26 @@ class SecurityChecker extends \Edge\QA\Tools\Tool

public function __invoke()
{
$composerLock = getcwd() . "/composer.lock";
$composerLockFromConfig = $this->config->path('security-checker.composerLock');
$composerLock = file_exists($composerLockFromConfig)
? $composerLockFromConfig
: $this->detectComposerLock();

return [
'security:check',
$composerLock,
];
}

private function detectComposerLock()
{
foreach ($this->options->getAnalyzedDirs() as $escapedDir) {
$dir = rtrim(trim($escapedDir, '"'), '/');
$path = "{$dir}/composer.lock";
if (file_exists($path)) {
$composerLock = $path;
break;
return $path;
}
}
return [
'security:check',
$composerLock,
];
return getcwd() . '/composer.lock';
}
}
1 change: 1 addition & 0 deletions tests/Config/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function testLoadDefaultConfig()
assertThat($config->value('phpmetrics.git'), identicalTo(false));
assertThat($config->value('pdepend.coverageReport'), is(nullValue()));
assertThat($config->value('deptrac.depfile'), is(nullValue()));
assertThat($config->value('security-checker.composerLock'), is(nullValue()));
}

public function testBuildAbsolutePath()
Expand Down

0 comments on commit 5bac59f

Please sign in to comment.