Completed
Pull Request — master (#4)
by Mark
01:09
created

PartialParts::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.552
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace DigiFactory\PartialDown\Commands;
4
5
use DigiFactory\PartialDown\Middleware\CheckForPartialMaintenanceMode;
6
use Illuminate\Console\Command;
7
use Symfony\Component\Console\Output\BufferedOutput;
8
9
class PartialParts extends Command
10
{
11
    /**
12
     * The console command name.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'partial-parts';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Show all parts that are used in the application';
24
25
    /**
26
     * Execute the console command.
27
     *
28
     * @return int
29
     */
30
    public function handle()
31
    {
32
        $outputBuffer = new BufferedOutput();
33
34
        $this->runCommand('route:list', [], $outputBuffer);
35
36
        $output = $outputBuffer->fetch();
37
38
        $className = CheckForPartialMaintenanceMode::class;
39
40
        preg_match_all('/'.preg_quote($className).':(.*[a-z])/', $output, $matches);
41
42
        $parts = collect($matches[0])->unique()->map(function ($part) use ($className) {
43
            return [str_replace($className.':', '', $part)];
44
        });
45
46
        if ($parts->count() === 0) {
47
            $this->error('No parts found!');
48
        } else {
49
            $headers = ['Parts in use'];
50
            $this->table($headers, $parts->toArray());
51
        }
52
    }
53
}
54