Reacter   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 22
c 1
b 0
f 0
dl 0
loc 66
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A hasNotReactedTo() 0 11 2
A reactTo() 0 9 1
A __construct() 0 4 1
A hasReactedTo() 0 11 2
A getReactions() 0 3 1
A unreactTo() 0 7 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\Facades;
15
16
use Cog\Contracts\Love\Reactable\Models\Reactable as ReactableInterface;
17
use Cog\Contracts\Love\Reacter\Facades\Reacter as ReacterFacadeInterface;
18
use Cog\Contracts\Love\Reacter\Models\Reacter as ReacterInterface;
19
use Cog\Laravel\Love\ReactionType\Models\ReactionType;
20
21
final class Reacter implements
22
    ReacterFacadeInterface
23
{
24
    private ReacterInterface $reacter;
25
26
    public function __construct(
27
        ReacterInterface $reacter,
28
    ) {
29
        $this->reacter = $reacter;
30
    }
31
32
    /**
33
     * @return iterable|\Cog\Contracts\Love\Reaction\Models\Reaction[]
34
     */
35
    public function getReactions(): iterable
36
    {
37
        return $this->reacter->getReactions();
38
    }
39
40
    public function reactTo(
41
        ReactableInterface $reactable,
42
        string $reactionTypeName,
43
        float | null $rate = null,
44
    ): void {
45
        $this->reacter->reactTo(
46
            $reactable->getLoveReactant(),
47
            ReactionType::fromName($reactionTypeName),
48
            $rate,
49
        );
50
    }
51
52
    public function unreactTo(
53
        ReactableInterface $reactable,
54
        string $reactionTypeName,
55
    ): void {
56
        $this->reacter->unreactTo(
57
            $reactable->getLoveReactant(),
58
            ReactionType::fromName($reactionTypeName),
59
        );
60
    }
61
62
    public function hasReactedTo(
63
        ReactableInterface $reactable,
64
        string | null $reactionTypeName = null,
65
        float | null $rate = null,
66
    ): bool {
67
        $reactionType = $reactionTypeName === null ? null : ReactionType::fromName($reactionTypeName);
68
69
        return $this->reacter->hasReactedTo(
70
            $reactable->getLoveReactant(),
71
            $reactionType,
72
            $rate,
73
        );
74
    }
75
76
    public function hasNotReactedTo(
77
        ReactableInterface $reactable,
78
        string | null $reactionTypeName = null,
79
        float | null $rate = null,
80
    ): bool {
81
        $reactionType = $reactionTypeName === null ? null : ReactionType::fromName($reactionTypeName);
82
83
        return $this->reacter->hasNotReactedTo(
84
            $reactable->getLoveReactant(),
85
            $reactionType,
86
            $rate,
87
        );
88
    }
89
}
90