GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( ec26c3...2349d2 )
by Simon
11:27 queued 06:17
created

RebuildProjectionsCommand::handle()   B

Complexity

Conditions 5
Paths 9

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 0
loc 20
rs 8.8571
cc 5
eloc 12
nc 9
nop 0
1
<?php
2
namespace SmoothPhp\LaravelAdapter\Console;
3
4
use Illuminate\Console\Command;
5
use Illuminate\Contracts\Config\Repository;
6
use Illuminate\Contracts\Foundation\Application;
7
use Illuminate\Database\DatabaseManager;
8
use SmoothPhp\Contracts\EventDispatcher\EventDispatcher;
9
use SmoothPhp\Contracts\Serialization\Serializer;
10
use SmoothPhp\Serialization\Exception\SerializedClassDoesNotExist;
11
12
/**
13
 * Class RebuildProjectionsCommand
14
 * @package SmoothPhp\LaravelAdapter\Console
15
 * @author Simon Bennett <[email protected]>
16
 */
17
final class RebuildProjectionsCommand extends Command
18
{
19
    /**
20
     * The name and signature of the console command.
21
     *
22
     * @var string
23
     */
24
    protected $signature = 'smoothphp:rebuild';
25
26
    /**
27
     * The console command description.
28
     *
29
     * @var string
30
     */
31
    protected $description = 'Rebuild all projection';
32
33
    /** @var Repository */
34
    private $config;
35
36
    /**
37
     * @var EventDispatcher
38
     */
39
    private $dispatcher;
40
41
    /** @var DatabaseManager */
42
    private $databaseManager;
43
44
    /** @var Serializer */
45
    private $serializer;
46
47
48
    /**
49
     * BuildLaravelEventStore constructor.
50
     * @param Repository $config
51
     * @param Application $application
52
     * @param DatabaseManager $databaseManager
53
     * @param Serializer $serializer
54
     */
55
    public function __construct(
56
        Repository $config,
57
        Application $application,
58
        DatabaseManager $databaseManager,
59
        Serializer $serializer
60
    ) {
61
        parent::__construct();
62
        $this->config = $config;
63
64
        $this->dispatcher = $application->make(EventDispatcher::class);
65
        $this->databaseManager = $databaseManager;
66
        $this->serializer = $serializer;
67
    }
68
69
    /**
70
     * Execute the console command.
71
     *
72
     * @return mixed
73
     */
74
    public function handle()
75
    {
76
        foreach ($this->config->get('cqrses.pre_rebuild_commands') as $preRebuildCommand) {
77
            if (is_array($preRebuildCommand)) {
78
                $this->call(key($preRebuildCommand), current($preRebuildCommand));
79
            } else {
80
                $this->call($preRebuildCommand);
81
            }
82
        }
83
84
        $this->replayEvents();
85
86
        foreach ($this->config->get('cqrses.post_rebuild_commands') as $postRebuildCommand) {
87
            if (is_array($postRebuildCommand)) {
88
                $this->call(key($postRebuildCommand), current($postRebuildCommand));
89
            } else {
90
                $this->call($postRebuildCommand);
91
            }
92
        }
93
    }
94
    
95
    /**
96
     *
97
     */
98
    protected function replayEvents()
99
    {
100
        $allEvents = $this->getAllEvents();
101
        $this->output->progressStart(count($allEvents));
102
103
        foreach ($allEvents as $eventRow) {
0 ignored issues
show
Bug introduced by
The expression $allEvents of type object<stdClass> is not traversable.
Loading history...
104
            $payload = json_decode($eventRow->payload, true)['payload'];
105
            $this->dispatcher->dispatch($eventRow->type,
106
                                        [
107
                                            (call_user_func(
108
                                                [
109
                                                    str_replace('.', '\\', $eventRow->type),
110
                                                    'deserialize'
111
                                                ],
112
                                                $payload
113
                                            ))
114
                                        ],
115
                                        true);
116
117
118
        }
119
120
121
        $this->output->progressFinish();
122
    }
123
124
    /**
125
     * @return \stdClass
126
     */
127
    private function getAllEvents()
128
    {
129
        return $this->databaseManager
130
            ->connection($this->config->get('cqrses.eventstore_connection'))
131
            ->table($this->config->get('cqrses.eventstore_table'))
132
            ->get();
133
    }
134
}
135