Passed
Pull Request — master (#251)
by Anton
03:07
created

ReactionTotalObserver::creating()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 4
c 2
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\ReactionTotal\Observers;
15
16
use Cog\Laravel\Love\Reactant\ReactionTotal\Models\ReactionTotal;
17
18
final class ReactionTotalObserver
19
{
20
    public function creating(
21
        ReactionTotal $total,
22
    ): void {
23
        if ($total->getAttributeValue('count') === null) {
24
            $total->setAttribute('count', ReactionTotal::COUNT_DEFAULT);
25
        }
26
27
        if ($total->getAttributeValue('weight') === null) {
28
            $total->setAttribute('weight', ReactionTotal::WEIGHT_DEFAULT);
29
        }
30
    }
31
}
32