Passed
Pull Request — master (#90)
by Anton
03:04
created

ReactionCounterObserver::creating()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 9
rs 10
cc 3
nc 4
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\Reactant\ReactionCounter\Observers;
15
16
use Cog\Laravel\Love\Reactant\ReactionCounter\Models\ReactionCounter;
17
18
final class ReactionCounterObserver
19
{
20
    public function creating(
21
        ReactionCounter $counter
22
    ): void {
23
        if (is_null($counter->getAttributeValue('count'))) {
24
            $counter->setAttribute('count', ReactionCounter::DEFAULT_COUNT);
25
        }
26
27
        if (is_null($counter->getAttributeValue('weight'))) {
28
            $counter->setAttribute('weight', ReactionCounter::DEFAULT_WEIGHT);
29
        }
30
    }
31
}
32