Completed
Push — master ( 64b2fe...fbb439 )
by Freek
01:55
created

ReplayCommand::guardAgainstNonExistingProjectors()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 3
nop 1
1
<?php
2
3
namespace Spatie\EventProjector\Console;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Collection;
7
use Spatie\EventProjector\Console\Concerns\SelectsProjectors;
8
use Spatie\EventProjector\EventProjectionist;
9
use Spatie\EventProjector\Projectors\Projector;
10
use Spatie\EventProjector\Console\Concerns\ReplaysEvents;
11
use Spatie\EventProjector\Exceptions\InvalidEventHandler;
12
13 View Code Duplication
class ReplayCommand 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...
14
{
15
    use ReplaysEvents, SelectsProjectors;
16
17
    protected $signature = 'event-projector:replay {projector?*}';
18
19
    protected $description = 'Replay stored events';
20
21
    /** @var \Spatie\EventProjector\EventProjectionist */
22
    protected $eventProjectionist;
23
24
    /** @var string */
25
    protected $storedEventModelClass;
26
27
    public function __construct(EventProjectionist $eventProjectionist, string $storedEventModelClass)
28
    {
29
        parent::__construct();
30
31
        $this->eventProjectionist = $eventProjectionist;
32
33
        $this->storedEventModelClass = $storedEventModelClass;
34
    }
35
36
    public function handle()
37
    {
38
        $projectors = $this->selectsProjectors($this->argument('projector'), 'Are you sure you want to replay events to all projectors?');
0 ignored issues
show
Bug introduced by
It seems like $this->argument('projector') targeting Illuminate\Console\Command::argument() can also be of type string; however, Spatie\EventProjector\Co...rs::selectsProjectors() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
39
40
        if (is_null($projectors)) {
41
            $this->warn('No events replayed!');
42
43
            return;
44
        }
45
46
        $this->replayEvents($projectors);
47
    }
48
}
49