Passed
Pull Request — master (#68)
by Anton
05:41 queued 02:10
created

ReactionTotal::getConnectionName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\Models;
15
16
use Cog\Contracts\Love\Reactant\Models\Reactant as ReactantContract;
17
use Cog\Contracts\Love\Reactant\ReactionTotal\Models\ReactionTotal as ReactionTotalContract;
18
use Cog\Laravel\Love\Reactant\Models\Reactant;
19
use Illuminate\Database\Eloquent\Model;
20
use Illuminate\Database\Eloquent\Relations\BelongsTo;
21
22
final class ReactionTotal extends Model implements
23
    ReactionTotalContract
24
{
25
    protected $table = 'love_reactant_reaction_totals';
26
27
    protected $fillable = [
28
        'count',
29
        'weight',
30
    ];
31
32
    protected $casts = [
33
        'count' => 'integer',
34
        'weight' => 'integer',
35
    ];
36
37
    public function getConnectionName(): ?string
38
    {
39
        return COG_LOVE_DB_CONNECTION ?? $this->connection;
40
    }
41
42
    public function reactant(): BelongsTo
43
    {
44
        return $this->belongsTo(Reactant::class, 'reactant_id');
45
    }
46
47
    public function getReactant(): ReactantContract
48
    {
49
        return $this->getAttribute('reactant');
50
    }
51
52
    public function getCount(): int
53
    {
54
        return $this->getAttributeValue('count') ?? 0;
55
    }
56
57
    public function getWeight(): int
58
    {
59
        return $this->getAttributeValue('weight') ?? 0;
60
    }
61
62
    public function incrementCount(
63
        int $amount
64
    ): void {
65
        $this->increment('count', $amount);
66
    }
67
68
    public function decrementCount(
69
        int $amount
70
    ): void {
71
        $this->decrement('count', $amount);
72
    }
73
74
    public function incrementWeight(
75
        int $amount
76
    ): void {
77
        $this->increment('weight', $amount);
78
    }
79
80
    public function decrementWeight(
81
        int $amount
82
    ): void {
83
        $this->decrement('weight', $amount);
84
    }
85
}
86