13
13
14
14
/**
15
15
* Checks installed dependencies against the SensioLabs Security Advisory database.
16
- *
17
- * @author Baldur Rensch <[email protected] >
18
16
*/
19
17
class SecurityAdvisory extends AbstractCheck
20
18
{
@@ -29,13 +27,33 @@ class SecurityAdvisory extends AbstractCheck
29
27
protected $ securityChecker ;
30
28
31
29
/**
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
34
32
* @throws \InvalidArgumentException
35
33
*/
36
- public function __construct (SecurityChecker $ securityChecker , $ lockFilePath )
34
+ public function __construct (SecurityChecker $ securityChecker = null , $ lockFilePath = null )
37
35
{
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 )) {
39
57
throw new InvalidArgumentException (sprintf (
40
58
'Invalid argument 2 provided for SecurityAdvisory check - expected file name (string) , got %s ' ,
41
59
gettype ($ lockFilePath )
@@ -46,9 +64,6 @@ public function __construct(SecurityChecker $securityChecker, $lockFilePath)
46
64
$ this ->securityChecker = $ securityChecker ;
47
65
}
48
66
49
- /**
50
- * {@inheritdoc}
51
- */
52
67
public function check ()
53
68
{
54
69
try {
0 commit comments