CleanupProvidedRoutesCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A handle() 0 12 2
1
<?php
2
3
4
namespace ElementsFramework\DynamicRouting\Console;
5
6
7
use ElementsFramework\DynamicRouting\Service\Publishing\RoutePublisher;
8
use Illuminate\Console\Command;
9
10
class CleanupProvidedRoutesCommand extends Command
11
{
12
    /**
13
     * The name and signature of the console command.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'dynamic-route:provided:cleanup';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Cleans up all routes that are persisted but no longer provided by a Elements component.';
25
26
    /**
27
     * The route compiler
28
     *
29
     * @var RouteDeclarationCompiler
30
     */
31
    protected $publisher;
32
33
    /**
34
     * Create a new command instance.
35
     *
36
     * @param RoutePublisher $publisher
37
     */
38
    public function __construct(RoutePublisher $publisher)
39
    {
40
        parent::__construct();
41
42
        $this->publisher = $publisher;
0 ignored issues
show
Documentation Bug introduced by
It seems like $publisher of type object<ElementsFramework...lishing\RoutePublisher> is incompatible with the declared type object<ElementsFramework...uteDeclarationCompiler> of property $publisher.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
43
    }
44
45
    /**
46
     * Execute the console command.
47
     *
48
     * @return mixed
49
     */
50
    public function handle()
51
    {
52
        $this->output->writeln('<info>Cleaning up old provided routes...</info>');
53
        $deleted = $this->publisher->cleanupProvidedRoutes();
54
55
        $this->output->writeln('<info>Deleted '.count($deleted).' dynamic routes:</info>');
56
        foreach($deleted as $route) {
57
            $this->output->writeln('<info>- '.$route->name.'</info>');
58
        }
59
60
        $this->call('dynamic-route:compile');
61
    }
62
}