Passed
Push — master ( 4ef900...ead902 )
by Nuno
01:39
created

CodeAnalyseCommand::phpstanBinary()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of Laravel Code Analyse.
7
 *
8
 * (c) Nuno Maduro <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace NunoMaduro\LaravelCodeAnalyse\Console;
15
16
use function substr;
17
use function implode;
18
use function strtoupper;
19
use Illuminate\Console\Command;
20
use Symfony\Component\Process\Process;
21
use Illuminate\Console\Application as Artisan;
22
23
final class CodeAnalyseCommand extends Command
24
{
25
    /**
26
     * @var \Illuminate\Foundation\Application
27
     */
28
    protected $laravel;
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    protected $signature = 'code:analyse {--level=1}';
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    protected $description = 'Analyses source code';
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function handle(): void
44
    {
45
        $level = is_string($this->option('level')) ? $this->option('level') : 'max';
0 ignored issues
show
introduced by
The condition is_string($this->option('level')) is always false.
Loading history...
46
47
        $params = [
48
            static::phpstanBinary(),
49
            'analyse',
50
            '--level='.$level,
51
            '--autoload-file='.$this->laravel->basePath('vendor/autoload.php'),
52
            '--configuration='.__DIR__.'/../../extension.neon',
53
            $this->laravel['path'],
54
        ];
55
56
        $process = new Process(implode(' ', $params), $this->laravel->basePath('vendor/bin'));
57
58
        if (Process::isTtySupported()) {
59
            $process->setTty(true);
60
        }
61
62
        $process->setTimeout(null);
63
64
        $process->start();
65
66
        foreach ($process as $type => $data) {
67
            $this->output->writeln($data);
68
        }
69
    }
70
71
    /**
72
     * @return string
73
     */
74
    private static function phpstanBinary(): string
75
    {
76
        return sprintf('%s %s', Artisan::phpBinary(), 'phpstan');
77
    }
78
}
79