Completed
Push — master ( 3cd148...6fd5a8 )
by Freek
01:45 queued 14s
created

CreateSnapshotCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
3
namespace Spatie\EventProjector\Console\Snapshots;
4
5
use Illuminate\Console\Command;
6
use Spatie\EventProjector\EventProjectionist;
7
use Spatie\EventProjector\Snapshots\SnapshotFactory;
8
use Spatie\EventProjector\Snapshots\Snapshotter;
9
10
class CreateSnapshotCommand extends Command
11
{
12
    protected $signature = 'event-projector:create-snapshot {projectorName} {--name}';
13
14
    protected $description = 'Create new snapshots';
15
16
    /** @var \Spatie\EventProjector\EventProjectionist */
17
    protected $eventProjectionist;
18
19
    /** @var \Spatie\EventProjector\Snapshots\SnapshotFactory */
20
    protected $snapshotFactory;
21
22
    public function __construct(EventProjectionist $eventProjectionist, SnapshotFactory $snapshotFactory)
23
    {
24
        parent::__construct();
25
26
        $this->eventProjectionist = $eventProjectionist;
27
28
        $this->snapshotFactory = $snapshotFactory;
29
    }
30
31
    public function handle()
32
    {
33
        $projectorName = $this->argument('projectorName');
34
35
        $projector = $this->eventProjectionist->getProjector($projectorName);
0 ignored issues
show
Bug introduced by
It seems like $projectorName defined by $this->argument('projectorName') on line 33 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...
36
37
        if (! $projector) {
38
            $this->warn("No projector named `{$projectorName}` found!");
39
40
            return;
41
        }
42
43
        $this->snapshotFactory->createForProjector($projector, $this->option('name'));
0 ignored issues
show
Bug introduced by
It seems like $this->option('name') targeting Illuminate\Console\Command::option() can also be of type array; however, Spatie\EventProjector\Sn...y::createForProjector() does only seem to accept string, 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...
44
    }
45
}
46
47