Completed
Push — master ( 91b636...82125a )
by Freek
01:52
created

ResetProjectorCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Importance

Changes 0
Metric Value
dl 6
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Spatie\EventProjector\Console;
4
5
use Illuminate\Console\Command;
6
use Spatie\EventProjector\Console\Snapshots\Concerns\ChooseSnapshot;
7
use Spatie\EventProjector\EventProjectionist;
8 View Code Duplication
class ResetProjectorCommand extends Command
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
9
{
10
    use ChooseSnapshot;
11
12
    protected $signature = 'event-projector:reset-projector {projectorName}';
13
14
    protected $description = 'Reset a projector';
15
16
    /** @var \Spatie\EventProjector\EventProjectionist */
17
    protected $eventProjectionist;
18
19
    public function __construct(EventProjectionist $eventProjectionist)
20
    {
21
        parent::__construct();
22
23
        $this->eventProjectionist = $eventProjectionist;
24
    }
25
26
    public function handle()
27
    {
28
        $projectorName = $this->argument('projectorName');
29
30
        $projector = $this->eventProjectionist->getProjector($projectorName);
0 ignored issues
show
Bug introduced by
It seems like $projectorName defined by $this->argument('projectorName') on line 28 can also be of type array; however, Spatie\EventProjector\Ev...tionist::getProjector() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
31
32
        if (! $projector) {
33
            $this->warn("No projector named `{$projectorName}` found!");
34
35
            return;
36
        }
37
38
        $projector->reset();
39
40
        $this->comment("Projector reset!");
41
    }
42
}
43