Passed
Push — master ( 3e5454...4b648e )
by Jorijn
03:20
created

src/Console/SecurityMailCommand.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Jorijn\LaravelSecurityChecker\Console;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Facades\Mail;
7
use Jorijn\LaravelSecurityChecker\Mailables\SecurityMail;
8
use SensioLabs\Security\SecurityChecker;
9
10
class SecurityMailCommand extends Command
11
{
12
    /**
13
     * @var string
14
     */
15
    protected $name = 'security-check:email';
16
17
    /**
18
     * @var string
19
     */
20
    protected $description = 'Emails any vulnerabilities for packages you have in your composer.lock file.';
21
22
    /**
23
     * @var SecurityChecker
24
     */
25
    protected $checker;
26
27
    /**
28
     * SecurityCommand constructor.
29
     *
30
     * @param SecurityChecker $checker
31
     */
32
    public function __construct(SecurityChecker $checker)
33
    {
34
        parent::__construct();
35
36
        $this->checker = $checker;
37
    }
38
39
    /**
40
     *
41
     */
42
    public function fire()
43
    {
44
        // get the path to composer.lock
45
        $composerLock = base_path('composer.lock');
46
47
        // and feed it into the SecurityChecker
48
        $checkResult = $this->checker->check($composerLock);
49
50
        $recipients = config('laravel-security-checker.recipients', []);
51
        if (count($recipients) === 0) {
52
            $this->error(__('No recipients has been configured yet!'));
0 ignored issues
show
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

52
            $this->error(/** @scrutinizer ignore-call */ __('No recipients has been configured yet!'));
Loading history...
53
            return 1;
54
        }
55
56
        Mail::to($recipients)->send(new SecurityMail($checkResult));
57
    }
58
}
59