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

PartialParts::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 1
nc 1
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
        $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