NullReacter   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 12
eloc 15
c 2
b 1
f 0
dl 0
loc 77
rs 10

12 Methods

Rating   Name   Duplication   Size   Complexity  
A getId() 0 3 1
A __construct() 0 4 1
A getReacterable() 0 3 1
A getReactions() 0 3 1
A hasNotReactedTo() 0 6 1
A isNotNull() 0 3 1
A isEqualTo() 0 4 1
A isNotEqualTo() 0 4 1
A isNull() 0 3 1
A reactTo() 0 6 1
A hasReactedTo() 0 6 1
A unreactTo() 0 5 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\Reacter\Models;
15
16
use Cog\Contracts\Love\Reactant\Models\Reactant as ReactantInterface;
17
use Cog\Contracts\Love\Reacter\Exceptions\ReacterInvalid;
18
use Cog\Contracts\Love\Reacter\Models\Reacter as ReacterInterface;
19
use Cog\Contracts\Love\Reacterable\Models\Reacterable as ReacterableInterface;
20
use Cog\Contracts\Love\ReactionType\Models\ReactionType as ReactionTypeInterface;
21
use Illuminate\Support\Collection;
22
use TypeError;
23
24
final class NullReacter implements
25
    ReacterInterface
26
{
27
    private ReacterableInterface $reacterable;
28
29
    public function __construct(
30
        ReacterableInterface $reacterable,
31
    ) {
32
        $this->reacterable = $reacterable;
33
    }
34
35
    public function getId(): string
36
    {
37
        throw new TypeError();
38
    }
39
40
    public function getReacterable(): ReacterableInterface
41
    {
42
        return $this->reacterable;
43
    }
44
45
    public function getReactions(): iterable
46
    {
47
        return new Collection();
48
    }
49
50
    public function reactTo(
51
        ReactantInterface $reactant,
52
        ReactionTypeInterface $reactionType,
53
        float | null $rate = null,
54
    ): void {
55
        throw ReacterInvalid::notExists();
56
    }
57
58
    public function unreactTo(
59
        ReactantInterface $reactant,
60
        ReactionTypeInterface $reactionType,
61
    ): void {
62
        throw ReacterInvalid::notExists();
63
    }
64
65
    public function hasReactedTo(
66
        ReactantInterface $reactant,
67
        ReactionTypeInterface | null $reactionType = null,
68
        float | null $rate = null,
69
    ): bool {
70
        return false;
71
    }
72
73
    public function hasNotReactedTo(
74
        ReactantInterface $reactant,
75
        ReactionTypeInterface | null $reactionType = null,
76
        float | null $rate = null,
77
    ): bool {
78
        return true;
79
    }
80
81
    public function isEqualTo(
82
        ReacterInterface $that,
83
    ): bool {
84
        return $that instanceof self;
85
    }
86
87
    public function isNotEqualTo(
88
        ReacterInterface $that,
89
    ): bool {
90
        return !$this->isEqualTo($that);
91
    }
92
93
    public function isNull(): bool
94
    {
95
        return true;
96
    }
97
98
    public function isNotNull(): bool
99
    {
100
        return false;
101
    }
102
}
103