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.

BuildLaravelEventStore::handle()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 3
nop 0
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace SmoothPhp\LaravelAdapter\Console;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Contracts\Config\Repository;
7
use Illuminate\Database\QueryException;
8
use Illuminate\Database\Schema\Blueprint;
9
use Schema;
10
11
/**
12
 * Class BuildLaravelEventStore
13
 * @package SmoothPhp\LaravelAdapter\Console
14
 * @author Simon Bennett <[email protected]>
15
 */
16
final class BuildLaravelEventStore extends Command
17
{
18
    /**
19
     * The name and signature of the console command.
20
     *
21
     * @var string
22
     */
23
    protected $signature = 'smoothphp:buildeventstore {--force=false}';
24
25
    /**
26
     * The console command description.
27
     *
28
     * @var string
29
     */
30
    protected $description = 'Build the Laravel Event Store';
31
32
    /** @var Repository */
33
    private $config;
34
35
    /**
36
     * BuildLaravelEventStore constructor.
37
     * @param Repository $config
38
     */
39
    public function __construct(Repository $config)
40
    {
41
        parent::__construct();
42
        $this->config = $config;
43
    }
44
45
    /**
46
     * Execute the console command.
47
     *
48
     * @return mixed
49
     */
50
    public function handle()
51
    {
52
        if ($this->option('force') == 'true' || $this->confirm(
53
                "Are you sure you want to make a new table '{$this->config->get('cqrses.eventstore_table')}'"
54
                . " on connection '{$this->config->get('cqrses.eventstore_connection')}'"
55
                . " Do you wish to continue?"
56
            )
57
        ) {
58
            try {
59
                return $this->buildEventStoreTable();
60
            } catch (QueryException $ex) {
61
                $this->error("Error creating table :'{$this->config->get('cqrses.eventstore_table')}'");
62
                $this->error($ex->getMessage());
63
            }
64
        }
65
        $this->line("Stopping");
66
    }
67
68
    /**
69
     * Build eventstore table
70
     */
71
    protected function buildEventStoreTable()
72
    {
73
        Schema::connection($this->config->get('cqrses.eventstore_connection'))
74
              ->create(
75
                  $this->config->get('cqrses.eventstore_table'),
76
                  function (Blueprint $table) {
77
                      $table->increments('id');
78
                      $table->string('uuid', 56);
79
                      $table->integer('playhead')->unsigned();
80
                      $table->text('metadata');
81
                      $table->longText('payload');
82
                      $table->timestamp('recorded_on')->nullable()->index();
83
                      $table->string('type', 255)->index();
84
                      $table->unique(['uuid', 'playhead']);
85
86
                      $table->index(['id', 'type']);
87
                  }
88
              );
89
    }
90
}