MakeProjectorCommand   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 50
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 10 2
A getStub() 0 4 1
A getDefaultNamespace() 0 4 1
A rewriteToSyncProjector() 0 13 1
A getOptions() 0 6 1
1
<?php
2
3
namespace Spatie\EventProjector\Console;
4
5
use Illuminate\Console\GeneratorCommand;
6
use Symfony\Component\Console\Input\InputOption;
7
8
final class MakeProjectorCommand extends GeneratorCommand
9
{
10
    protected $name = 'make:projector';
11
12
    protected $description = 'Create a new projector';
13
14
    protected $type = 'Projector';
15
16
    public function handle()
17
    {
18
        parent::handle();
19
20
        if (! $this->option('queued')) {
21
            return;
22
        }
23
24
        $this->rewriteToSyncProjector();
25
    }
26
27
    protected function getStub()
28
    {
29
        return __DIR__.'/../../stubs/projector.stub';
30
    }
31
32
    protected function getDefaultNamespace($rootNamespace)
33
    {
34
        return $rootNamespace.'\Projectors';
35
    }
36
37
    protected function rewriteToSyncProjector()
38
    {
39
        $name = $this->qualifyClass($this->getNameInput());
40
41
        $path = $this->getPath($name);
42
43
        $content = file_get_contents($path);
44
45
        $content = str_replace('implements Projector', 'implements QueuedProjector', $content);
46
        $content = str_replace('use Spatie\EventProjector\Projectors\Projector;', 'use Spatie\EventProjector\Projectors\QueuedProjector;', $content);
47
48
        file_put_contents($path, $content);
49
    }
50
51
    protected function getOptions()
52
    {
53
        return [
54
            ['queued', 'Q', InputOption::VALUE_NONE, 'Create a QueuedProjector'],
55
        ];
56
    }
57
}
58