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

PartialParts   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 16 1
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
        $output = new BufferedOutput();
33
34
        $this->runCommand('route:list', [], $output);
35
36
        $className = CheckForPartialMaintenanceMode::class;
37
38
        preg_match_all('/'.preg_quote($className).':(.*[a-z])/', $output->fetch(), $matches);
39
40
        $parts = collect($matches[0])->unique()->map(function ($part) use ($className) {
41
            return str_replace($className.':', '', $part);
42
        });
43
44
        $this->line('Parts in use: '.$parts->join(', ', ' and '));
45
    }
46
}
47