Completed
Push — master ( c9545d...9b8f2e )
by Freek
01:31
created

ListSnapshotsCommand   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A handle() 0 15 1
1
<?php
2
3
namespace Spatie\EventProjector\Console\Snapshots;
4
5
use Illuminate\Console\Command;
6
use Spatie\EventProjector\Snapshots\Snapshot;
7
use Spatie\EventProjector\Snapshots\SnapshotRepository;
8
9
class ListSnapshotsCommand extends Command
10
{
11
    protected $signature = 'event-projector:list-snapshots';
12
13
    protected $description = 'List all snapshots';
14
15
    /** @var \Spatie\EventProjector\Snapshots\SnapshotRepository */
16
    protected $snapshotRepository;
17
18
    public function __construct(SnapshotRepository $snapshotRepository)
19
    {
20
        parent::__construct();
21
22
        $this->snapshotRepository = $snapshotRepository;
23
    }
24
25
    public function handle()
26
    {
27
        $titles = ['Projector', 'Last processed event id', 'Created at', 'Name'];
28
29
        $rows = $this->snapshotRepository->get()->map(function(Snapshot $snapshot) {
30
            return [
31
                $snapshot->projectorName(),
32
                $snapshot->lastProcessedEventId(),
33
                $snapshot->createdAt(),
34
                $snapshot->name(),
35
            ];
36
        });
37
38
        $this->table($titles, $rows);
39
    }
40
}
41