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

PartialParts   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 45
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 23 2
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