Passed
Pull Request — master (#24)
by Anton
02:47 queued 28s
created

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