Passed
Push — master ( 497393...f8a28c )
by Anton
03:12 queued 16s
created

NullReactant::getReactionsBy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
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\Models;
15
16
use Cog\Contracts\Love\Reactable\Models\Reactable as ReactableInterface;
17
use Cog\Contracts\Love\Reactant\Exceptions\ReactantInvalid;
18
use Cog\Contracts\Love\Reactant\Models\Reactant as ReactantInterface;
19
use Cog\Contracts\Love\Reactant\ReactionCounter\Models\ReactionCounter as ReactionCounterInterface;
20
use Cog\Contracts\Love\Reactant\ReactionTotal\Models\ReactionTotal as ReactionTotalInterface;
21
use Cog\Contracts\Love\Reacter\Models\Reacter;
22
use Cog\Contracts\Love\Reacter\Models\Reacter as ReacterInterface;
23
use Cog\Contracts\Love\ReactionType\Models\ReactionType as ReactionTypeInterface;
24
use Cog\Laravel\Love\Reactant\ReactionCounter\Models\NullReactionCounter;
25
use Cog\Laravel\Love\Reactant\ReactionTotal\Models\NullReactionTotal;
26
use Illuminate\Support\Collection;
27
use TypeError;
28
29
final class NullReactant implements
30
    ReactantInterface
31
{
32
    private ReactableInterface $reactable;
33
34
    public function __construct(
35
        ReactableInterface $reactable,
36
    ) {
37
        $this->reactable = $reactable;
38
    }
39
40
    public function getId(): string
41
    {
42
        throw new TypeError();
43
    }
44
45
    public function getReactable(): ReactableInterface
46
    {
47
        return $this->reactable;
48
    }
49
50
    public function getReactions(): iterable
51
    {
52
        return new Collection();
53
    }
54
55
    public function getReactionsBy(
56
        Reacter $reacter,
57
    ): iterable {
58
        return new Collection();
59
    }
60
61
    public function getReactionCounters(): iterable
62
    {
63
        return new Collection();
64
    }
65
66
    public function getReactionCounterOfType(
67
        ReactionTypeInterface $reactionType,
68
    ): ReactionCounterInterface {
69
        return new NullReactionCounter($this, $reactionType);
70
    }
71
72
    public function getReactionTotal(): ReactionTotalInterface
73
    {
74
        return new NullReactionTotal($this);
75
    }
76
77
    public function isReactedBy(
78
        ReacterInterface $reacter,
79
        ReactionTypeInterface | null $reactionType = null,
80
        float | null $rate = null,
81
    ): bool {
82
        return false;
83
    }
84
85
    public function isNotReactedBy(
86
        ReacterInterface $reacter,
87
        ReactionTypeInterface | null $reactionType = null,
88
        float | null $rate = null,
89
    ): bool {
90
        return true;
91
    }
92
93
    public function isEqualTo(
94
        ReactantInterface $that,
95
    ): bool {
96
        return $that instanceof self;
97
    }
98
99
    public function isNotEqualTo(
100
        ReactantInterface $that,
101
    ): bool {
102
        return !$this->isEqualTo($that);
103
    }
104
105
    public function isNull(): bool
106
    {
107
        return true;
108
    }
109
110
    public function isNotNull(): bool
111
    {
112
        return false;
113
    }
114
115
    public function createReactionCounterOfType(
116
        ReactionTypeInterface $reactionType,
117
    ): void {
118
        throw ReactantInvalid::notExists();
119
    }
120
121
    public function createReactionTotal(): void
122
    {
123
        throw ReactantInvalid::notExists();
124
    }
125
}
126