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

CodeAnalyseCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 54
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A phpstanBinary() 0 3 1
A handle() 0 25 4
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