SecurityCommand::handle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 12
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\SecurityChecker;
6
use Illuminate\Console\Command;
7
use Jorijn\LaravelSecurityChecker\Formatter\SimpleFormatter;
8
9
class SecurityCommand extends Command
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $name = 'security-check:now';
15
16
    /**
17
     * @var string
18
     */
19
    protected $description = 'Checks composer.lock for any vulnerabilities against the SensioLabs checker.';
20
21
    /**
22
     * @var SecurityChecker
23
     */
24
    protected $checker;
25
26
    /**
27
     * SecurityCommand constructor.
28
     *
29
     * @param SecurityChecker $checker
30
     */
31 27
    public function __construct(SecurityChecker $checker)
32
    {
33 27
        parent::__construct();
34
35 27
        $this->checker = $checker;
36 27
    }
37
38
    /**
39
     * Execute the command
40
     */
41 6
    public function handle()
42
    {
43
        // get the path to composer.lock
44 6
        $composerLock = base_path('composer.lock');
45
46
        // and feed it into the SecurityChecker
47 6
        $checkResult = $this->checker->check($composerLock);
48
49
        // then display it using the formatter provided
50 6
        app(SimpleFormatter::class)->displayResults($this->getOutput(), $composerLock, $checkResult);
51
52 6
        return (int) (count($checkResult) > 0);
53
    }
54
}
55