Completed
Pull Request — master (#24)
by Anton
02:57 queued 39s
created

ReacterableObserver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 6
dl 0
loc 16
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A shouldRegisterAsReacterOnCreate() 0 5 2
A created() 0 6 3
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\Reacterable\Observers;
15
16
use Cog\Contracts\Love\Reacterable\Models\Reacterable as ReacterableContract;
17
18
final class ReacterableObserver
19
{
20
    public function created(
21
        ReacterableContract $reacterable
22
    ): void {
23
        if ($this->shouldRegisterAsReacterOnCreate($reacterable)
24
            && $reacterable->isNotRegisteredAsLoveReacter()) {
25
            $reacterable->registerAsLoveReacter();
26
        }
27
    }
28
29
    private function shouldRegisterAsReacterOnCreate(
30
        ReacterableContract $reacterable
31
    ): bool {
32
        return !method_exists($reacterable, 'shouldRegisterAsLoveReacterOnCreate')
33
            || $reacterable->shouldRegisterAsLoveReacterOnCreate();
34
    }
35
}
36