Passed
Pull Request — master (#10)
by
unknown
15:04
created

SecurityCommand   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
dl 0
loc 48
ccs 9
cts 9
cp 1
rs 10
c 2
b 1
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 12 1
1
<?php
2
3
namespace Jorijn\LaravelSecurityChecker\Console;
4
5
use Illuminate\Console\Command;
6
use SensioLabs\Security\Formatters\SimpleFormatter;
7
use SensioLabs\Security\SecurityChecker;
8
9
class SecurityCommand extends Command
10
{
11
    /**
12
     * The name and signature of the console command.
13
     *
14
     * @var string
15
     */
16
    protected $name = 'security-check:now';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Checks composer.lock for any vulnerabilities against the SensioLabs checker.';
24
25
    /**
26
     * @var SecurityChecker
27
     */
28
    protected $checker;
29
30
    /**
31 15
     * SecurityCommand constructor.
32
     *
33 15
     * @param SecurityChecker $checker
34
     */
35 15
    public function __construct(SecurityChecker $checker)
36 15
    {
37
        parent::__construct();
38
39
        $this->checker = $checker;
40
    }
41 3
42
    /**
43
     * Execute the console command.
44 3
     */
45
    public function handle()
46
    {
47 3
        // get the path to composer.lock
48
        $composerLock = base_path('composer.lock');
49
50 3
        // and feed it into the SecurityChecker
51
        $checkResult = $this->checker->check($composerLock);
52 3
53
        // then display it using the formatter provided for Symfony
54
        app(SimpleFormatter::class)->displayResults($this->getOutput(), $composerLock, $checkResult);
55
56
        return 0;
57
    }
58
}
59