Passed
Pull Request — master (#24)
by Anton
04:12
created

Love::getReactableReactionsTotalCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 7
rs 10
c 0
b 0
f 0
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\Facades;
15
16
use Cog\Contracts\Love\Reactable\Models\Reactable as ReactableContract;
17
use Cog\Contracts\Love\Reacterable\Models\Reacterable as ReacterableContract;
18
use Cog\Contracts\Love\Reaction\Models\Reaction as ReactionContract;
19
use Cog\Laravel\Love\ReactionType\Models\ReactionType;
20
21
final class Love
22
{
23
    public static function isReactionOfTypeName(
24
        ReactionContract $reaction,
25
        string $typeName
26
    ): bool {
27
        return $reaction->isOfType(ReactionType::fromName($typeName));
28
    }
29
30
    public static function isReactionNotOfTypeName(
31
        ReactionContract $reaction,
32
        string $typeName
33
    ): bool {
34
        return !self::isReactionOfTypeName($reaction, $typeName);
35
    }
36
37
    public static function isReacterableReactedToWithTypeName(
38
        ?ReacterableContract $reacterable,
39
        ReactableContract $reactable,
40
        string $typeName
41
    ): bool {
42
        if (is_null($reacterable)) {
43
            return false;
44
        }
45
46
        return $reacterable
47
            ->getLoveReacter()
48
            ->isReactedToWithType(
49
                $reactable->getLoveReactant(),
50
                ReactionType::fromName($typeName)
51
            );
52
    }
53
54
    public static function isReacterableNotReactedToWithTypeName(
55
        ?ReacterableContract $reacterable,
56
        ReactableContract $reactable,
57
        string $typeName
58
    ): bool {
59
        return !self::isReacterableReactedToWithTypeName(
60
            $reacterable,
61
            $reactable,
62
            $typeName
63
        );
64
    }
65
66
    public static function isReacterableReactedTo(
67
        ?ReacterableContract $reacterable,
68
        ReactableContract $reactable
69
    ): bool {
70
        if (is_null($reacterable)) {
71
            return false;
72
        }
73
74
        return $reacterable
75
            ->getLoveReacter()
76
            ->isReactedTo($reactable->getLoveReactant());
77
    }
78
79
    public static function isReacterableNotReactedTo(
80
        ?ReacterableContract $reacterable,
81
        ReactableContract $reactable
82
    ): bool {
83
        return !self::isReacterableReactedTo($reacterable, $reactable);
84
    }
85
86
    public static function isReactableReactedByWithTypeName(
87
        ReactableContract $reactable,
88
        ?ReacterableContract $reacterable,
89
        string $typeName
90
    ): bool {
91
        if (is_null($reacterable)) {
92
            return false;
93
        }
94
95
        return $reactable
96
            ->getLoveReactant()
97
            ->isReactedByWithType(
98
                $reacterable->getLoveReacter(),
99
                ReactionType::fromName($typeName)
100
            );
101
    }
102
103
    public static function isReactableNotReactedByWithTypeName(
104
        ReactableContract $reactable,
105
        ?ReacterableContract $reacterable,
106
        string $typeName
107
    ): bool {
108
        return !self::isReactableReactedByWithTypeName(
109
            $reactable,
110
            $reacterable,
111
            $typeName
112
        );
113
    }
114
115
    public static function isReactableReactedBy(
116
        ReactableContract $reactable,
117
        ?ReacterableContract $reacterable
118
    ): bool {
119
        if (is_null($reacterable)) {
120
            return false;
121
        }
122
123
        return $reactable
124
            ->getLoveReactant()
125
            ->isReactedBy($reacterable->getLoveReacter());
126
    }
127
128
    public static function isReactableNotReactedBy(
129
        ReactableContract $reactable,
130
        ?ReacterableContract $reacterable
131
    ): bool {
132
        return !self::isReactableReactedBy($reactable, $reacterable);
133
    }
134
135
    public static function getReactableReactionsCountForTypeName(
136
        ReactableContract $reactable,
137
        string $typeName
138
    ): int {
139
        return $reactable
140
            ->getLoveReactant()
141
            ->getReactionCounterOfType(ReactionType::fromName($typeName))
142
            ->getCount();
143
    }
144
145
    public static function getReactableReactionsWeightForTypeName(
146
        ReactableContract $reactable,
147
        string $typeName
148
    ): int {
149
        return $reactable
150
            ->getLoveReactant()
151
            ->getReactionCounterOfType(ReactionType::fromName($typeName))
152
            ->getWeight();
153
    }
154
155
    public static function getReactableReactionsTotalCount(
156
        ReactableContract $reactable
157
    ): int {
158
        return $reactable
159
            ->getLoveReactant()
160
            ->getReactionTotal()
161
            ->getCount();
162
    }
163
164
    public static function getReactableReactionsTotalWeight(
165
        ReactableContract $reactable
166
    ): int {
167
        return $reactable
168
            ->getLoveReactant()
169
            ->getReactionTotal()
170
            ->getWeight();
171
    }
172
}
173