Completed
Pull Request — master (#51)
by Anton
05:35
created

Install::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of Laravel Love.
5
 *
6
 * (c) Anton Komarev <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Cog\Laravel\Love\Console\Commands;
15
16
use Cog\Laravel\Love\ReactionType\Models\ReactionType;
17
use Illuminate\Console\Command;
18
use Illuminate\Contracts\Events\Dispatcher;
19
20
final class Install extends Command
21
{
22
    /**
23
     * The name and signature of the console command.
24
     *
25
     * @var string
26
     */
27
    protected $signature = 'love:install';
28
29
    /**
30
     * The console command description.
31
     *
32
     * @var string
33
     */
34
    protected $description = 'Install Laravel Love';
35
36
    /**
37
     * Execute the console command.
38
     *
39
     * @param \Illuminate\Contracts\Events\Dispatcher $events
40
     * @return void
41
     */
42
    public function handle(
43
        Dispatcher $events
0 ignored issues
show
Unused Code introduced by
The parameter $events is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

43
        /** @scrutinizer ignore-unused */ Dispatcher $events

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
44
    ): void {
45
        $this->createDefaultReactionTypes();
46
    }
47
48
    private function createDefaultReactionTypes(): void
49
    {
50
        $types = [
51
            [
52
                'name' => 'Like',
53
                'weight' => 1,
54
            ],
55
            [
56
                'name' => 'Dislike',
57
                'weight' => -1,
58
            ],
59
        ];
60
61
        foreach ($types as $type) {
62
            if (ReactionType::query()->where('name', $type['name'])->exists()) {
63
                continue;
64
            }
65
66
            ReactionType::query()->create($type);
67
        }
68
    }
69
}
70