CheckVulnerabilitiesStep::execute()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.6
c 0
b 0
f 0
cc 3
nc 3
nop 2
1
<?php
2
3
/*
4
 * This file is part of `Composer as a service`.
5
 *
6
 * (c) Pascal Borreli <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ayaline\Bundle\ComposerBundle\Consumer\Step;
13
14
use SensioLabs\Security\SecurityChecker;
15
use Sonata\NotificationBundle\Consumer\ConsumerEvent;
16
17
/**
18
 * @author Hubert Moutot <[email protected]>
19
 */
20
class CheckVulnerabilitiesStep extends AbstractStep
21
{
22
    protected $securityChecker;
23
24
    /**
25
     * Constructor.
26
     *
27
     * @param SecurityChecker $securityChecker
28
     */
29
    public function __construct(SecurityChecker $securityChecker)
30
    {
31
        $this->securityChecker = $securityChecker;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function execute(ConsumerEvent $event, $directory)
38
    {
39
        $this->triggerNewStep($event, ['message' => 'Checking vulnerability']);
40
41
        try {
42
            $alerts = $this->securityChecker->check($this->workingTempPath.'/'.$directory.'/composer.lock');
43
        } catch (\RuntimeException $e) {
44
            $this->triggerError($event, ['message' => $e->getMessage()]);
45
46
            return 1;
47
        }
48
49
        $vulnerabilityCount = $this->securityChecker->getLastVulnerabilityCount();
0 ignored issues
show
Bug introduced by
The method getLastVulnerabilityCount() does not seem to exist on object<SensioLabs\Security\SecurityChecker>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
50
        if ($vulnerabilityCount > 0) {
51
            $this->triggerStepError($event, ['message' => 'Vulnerability found : '.$vulnerabilityCount]);
52
            $this->triggerVulnerabilities($event, ['message' => json_encode($alerts)]);
53
        }
54
55
        return 0;
56
    }
57
}
58