Passed
Pull Request — master (#34)
by Paras
14:04
created

SecurityCommand::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 16
ccs 5
cts 5
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Jorijn\LaravelSecurityChecker\Console;
4
5
use Enlightn\SecurityChecker\AdvisoryAnalyzer;
6
use Enlightn\SecurityChecker\AdvisoryFetcher;
7
use Enlightn\SecurityChecker\AdvisoryParser;
8
use Enlightn\SecurityChecker\Composer;
9
use Illuminate\Console\Command;
10
use Jorijn\LaravelSecurityChecker\Formatter\SimpleFormatter;
11
12
class SecurityCommand extends Command
13
{
14
    /**
15
     * @var string
16
     */
17
    protected $name = 'security-check:now';
18
19
    /**
20
     * @var string
21
     */
22
    protected $description = 'Checks composer.lock for any vulnerabilities against the SensioLabs checker.';
23
24
    /**
25
     * Execute the command
26
     */
27
    public function handle()
28
    {
29
        // get the path to composer.lock
30
        $composerLock = base_path('composer.lock');
31 27
32
        $parser = new AdvisoryParser((new AdvisoryFetcher)->fetchAdvisories());
33 27
34
        $dependencies = (new Composer)->getDependencies($composerLock);
35 27
36 27
        // and feed it into the AdvisoryAnalyzer
37
        $checkResult = (new AdvisoryAnalyzer($parser->getAdvisories()))->analyzeDependencies($dependencies);
38
39
        // then display it using the formatter provided
40
        app(SimpleFormatter::class)->displayResults($this->getOutput(), $composerLock, $checkResult);
41 6
42
        return (int) (count($checkResult) > 0);
43
    }
44
}
45