Completed
Push — master ( c986f6...75cf25 )
by Freek
03:55
created

DeleteSnapshotCommand   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 26
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 19 1
1
<?php
2
3
namespace Spatie\EventProjector\Console\Snapshots;
4
5
use Illuminate\Console\Command;
6
7
class DeleteSnapshotCommand extends Command
8
{
9
    protected $signature = 'event-projector:delete-snapshot';
10
11
    protected $description = 'Delete snapshots';
12
13
    public function handle()
14
    {
15
        $titles = ['Number', 'Projector', 'Last processed event id', 'Created at', 'Name'];
16
17
        $rows = $this->snapshotRepository->get()->map(function (Snapshot $snapshot) {
0 ignored issues
show
Bug introduced by
The property snapshotRepository does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
18
            static $number = 0;
19
            return [
20
                $number++,
21
                $snapshot->projectorName(),
22
                $snapshot->lastProcessedEventId(),
23
                $snapshot->createdAt(),
24
                $snapshot->name(),
25
            ];
26
        });
27
28
        $this->table($titles, $rows);
29
30
        $snapshotNumber = $this->ask('Which snapshot would you like to delete?');
0 ignored issues
show
Unused Code introduced by
$snapshotNumber is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
31
    }
32
}
33