Completed
Push — master ( 3cd3c1...676adf )
by Freek
02:19
created

ListCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
B handle() 0 24 3
1
<?php
2
3
namespace Spatie\EventProjector\Console;
4
5
use Illuminate\Console\Command;
6
use Spatie\EventProjector\EventProjectionist;
7
use Spatie\EventProjector\Projectors\Projector;
8
9
class ListCommand extends Command
10
{
11
    protected $signature = 'event-projector:list';
12
13
    protected $description = 'List all event projectors';
14
15
    /** @var \Spatie\EventProjector\EventProjectionist */
16
    protected $eventProjectionist;
17
18
    public function __construct(EventProjectionist $eventProjectionist)
19
    {
20
        parent::__construct();
21
22
        $this->eventProjectionist = $eventProjectionist;
23
    }
24
25
    public function handle()
26
    {
27
        $titles = ['Name', 'Up to date', 'Last processed event id', 'Last event processed at'];
28
29
        $rows = $this->eventProjectionist->projectors
30
            ->map(function ($eventHandler) {
31
                if (is_string($eventHandler)) {
32
                    $eventHandler = app($eventHandler);
33
                }
34
35
                return $eventHandler;
36
            })
37
            ->map(function (Projector $projector) {
38
                return [
39
                    $projector->getName(),
40
                    $projector->hasReceivedAllEvents() ? '✅' : '❌',
41
                    $projector->getLastProcessedEventId(),
42
                    $projector->lastEventProcessedAt()->format('Y-m-d H:i:s'),
43
                ];
44
            })
45
            ->toArray();
46
47
        $this->table($titles, $rows);
48
    }
49
}
50