Reactant   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 12
eloc 25
c 1
b 0
f 0
dl 0
loc 84
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getReactions() 0 3 1
A getReactionTotal() 0 3 1
A getReactionCounterOfType() 0 5 1
A getReactionCounters() 0 3 1
A getReactionsBy() 0 5 1
A isNotReactedBy() 0 15 3
A isReactedBy() 0 15 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\Reactant\Facades;
15
16
use Cog\Contracts\Love\Reactant\Facades\Reactant as ReacterFacadeInterface;
17
use Cog\Contracts\Love\Reactant\Models\Reactant as ReactantInterface;
18
use Cog\Contracts\Love\Reactant\ReactionCounter\Models\ReactionCounter as ReactionCounterInterface;
19
use Cog\Contracts\Love\Reactant\ReactionTotal\Models\ReactionTotal as ReactionTotalInterface;
20
use Cog\Contracts\Love\Reacterable\Models\Reacterable as ReacterableInterface;
21
use Cog\Laravel\Love\ReactionType\Models\ReactionType;
22
23
final class Reactant implements
24
    ReacterFacadeInterface
25
{
26
    private ReactantInterface $reactant;
27
28
    public function __construct(
29
        ReactantInterface $reactant,
30
    ) {
31
        $this->reactant = $reactant;
32
    }
33
34
    /**
35
     * @return iterable|\Cog\Contracts\Love\Reaction\Models\Reaction[]
36
     */
37
    public function getReactions(): iterable
38
    {
39
        return $this->reactant->getReactions();
40
    }
41
42
    /**
43
     * @return iterable|\Cog\Contracts\Love\Reaction\Models\Reaction[]
44
     */
45
    public function getReactionsBy(
46
        ReacterableInterface $reacterable,
47
    ): iterable {
48
        return $this->reactant->getReactionsBy(
49
            $reacterable->getLoveReacter(),
50
        );
51
    }
52
53
    /**
54
     * @return iterable|\Cog\Contracts\Love\Reactant\ReactionCounter\Models\ReactionCounter[]
55
     */
56
    public function getReactionCounters(): iterable
57
    {
58
        return $this->reactant->getReactionCounters();
59
    }
60
61
    public function getReactionCounterOfType(
62
        string $reactionTypeName,
63
    ): ReactionCounterInterface {
64
        return $this->reactant->getReactionCounterOfType(
65
            ReactionType::fromName($reactionTypeName),
66
        );
67
    }
68
69
    public function getReactionTotal(): ReactionTotalInterface
70
    {
71
        return $this->reactant->getReactionTotal();
72
    }
73
74
    public function isReactedBy(
75
        ReacterableInterface | null $reacterable = null,
76
        string | null $reactionTypeName = null,
77
        float | null $rate = null,
78
    ): bool {
79
        if ($reacterable === null) {
80
            return false;
81
        }
82
83
        $reactionType = $reactionTypeName === null ? null : ReactionType::fromName($reactionTypeName);
84
85
        return $this->reactant->isReactedBy(
86
            $reacterable->getLoveReacter(),
87
            $reactionType,
88
            $rate,
89
        );
90
    }
91
92
    public function isNotReactedBy(
93
        ReacterableInterface | null $reacterable = null,
94
        string | null $reactionTypeName = null,
95
        float | null $rate = null,
96
    ): bool {
97
        if ($reacterable === null) {
98
            return true;
99
        }
100
101
        $reactionType = $reactionTypeName === null ? null : ReactionType::fromName($reactionTypeName);
102
103
        return $this->reactant->isNotReactedBy(
104
            $reacterable->getLoveReacter(),
105
            $reactionType,
106
            $rate,
107
        );
108
    }
109
}
110