Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit 4d80b70

Browse files
committed
Fix use of SecurityAdvisory without supplying checker instance or composer.lock path.
1 parent 35a31b6 commit 4d80b70

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

src/ZendDiagnostics/Check/SecurityAdvisory.php

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
/**
1515
* Checks installed dependencies against the SensioLabs Security Advisory database.
16-
*
17-
* @author Baldur Rensch <[email protected]>
1816
*/
1917
class SecurityAdvisory extends AbstractCheck
2018
{
@@ -29,13 +27,33 @@ class SecurityAdvisory extends AbstractCheck
2927
protected $securityChecker;
3028

3129
/**
32-
* @param SecurityChecker $securityChecker An instance of SecurityChecker
33-
* @param string $lockFilePath Path to composer.lock
30+
* @param SecurityChecker|null $securityChecker An instance of SecurityChecker
31+
* @param string $lockFilePath Path to composer.lock
3432
* @throws \InvalidArgumentException
3533
*/
36-
public function __construct(SecurityChecker $securityChecker, $lockFilePath)
34+
public function __construct(SecurityChecker $securityChecker = null, $lockFilePath = null)
3735
{
38-
if (empty($lockFilePath) || !is_scalar($lockFilePath)) {
36+
if(!$securityChecker) {
37+
if(!class_exists('SensioLabs\Security\SecurityChecker')) {
38+
throw new InvalidArgumentException(sprintf(
39+
'Unable to find "%s" class. Please install "%s" library to use this Check.',
40+
'SensioLabs\Security\SecurityChecker',
41+
'sensiolabs/security-checker'
42+
));
43+
}
44+
45+
$securityChecker = new SecurityChecker();
46+
}
47+
48+
if(!$lockFilePath) {
49+
if(!file_exists('composer.lock')) {
50+
throw new InvalidArgumentException(
51+
'You have not provided lock file path and there is no "composer.lock" file in current directory.'
52+
);
53+
}
54+
55+
$lockFilePath = getcwd() . DIRECTORY_SEPARATOR . 'composer.lock';
56+
} elseif (!is_scalar($lockFilePath)) {
3957
throw new InvalidArgumentException(sprintf(
4058
'Invalid argument 2 provided for SecurityAdvisory check - expected file name (string) , got %s',
4159
gettype($lockFilePath)
@@ -46,9 +64,6 @@ public function __construct(SecurityChecker $securityChecker, $lockFilePath)
4664
$this->securityChecker = $securityChecker;
4765
}
4866

49-
/**
50-
* {@inheritdoc}
51-
*/
5267
public function check()
5368
{
5469
try {

0 commit comments

Comments
 (0)