1 | <?php |
||
12 | trait Voteable |
||
13 | { |
||
14 | /** |
||
15 | * This model has many votes. |
||
16 | * |
||
17 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany |
||
18 | */ |
||
19 | public function votes() |
||
23 | |||
24 | /** |
||
25 | * @return mixed |
||
26 | */ |
||
27 | public function upVotesCount() |
||
31 | |||
32 | public function likesCount() |
||
36 | |||
37 | /** |
||
38 | * @return mixed |
||
39 | */ |
||
40 | public function downVotesCount() |
||
44 | |||
45 | public function dislikesCount() |
||
49 | |||
50 | public function unlikesCount() |
||
54 | |||
55 | /** |
||
56 | * @return bool |
||
57 | */ |
||
58 | public function isUpVoted() |
||
62 | |||
63 | public function isLiked() |
||
67 | |||
68 | /** |
||
69 | * @return bool |
||
70 | */ |
||
71 | public function isDownVoted() |
||
75 | |||
76 | /** |
||
77 | * @param int $user_id |
||
78 | * |
||
79 | * @return bool |
||
80 | */ |
||
81 | public function isUpVotedByUser(int $user_id) |
||
85 | |||
86 | public function isLikedByUser(int $user_id) |
||
90 | |||
91 | /** |
||
92 | * @param int $user_id |
||
93 | * |
||
94 | * @return bool |
||
95 | */ |
||
96 | public function isDownVotedByUser(int $user_id) |
||
100 | |||
101 | public function isDislikedByUser(int $user_id) |
||
105 | |||
106 | public function isUnlikedByUser(int $user_id) |
||
110 | |||
111 | /** |
||
112 | * @param Builder $query |
||
113 | * @param string $direction |
||
114 | * @param string $type |
||
115 | * |
||
116 | * @return Builder |
||
117 | */ |
||
118 | public function scopeOrderByUpVotes(Builder $query, string $direction = 'asc', string $type = '>=') |
||
131 | |||
132 | public function scopeOrderByLikes(Builder $query, string $direction = 'asc', string $type = '>=') |
||
136 | |||
137 | /** |
||
138 | * @param Builder $query |
||
139 | * @param string $direction |
||
140 | * |
||
141 | * @return Builder |
||
142 | */ |
||
143 | public function scopeOrderByDownVotes(Builder $query, string $direction = 'asc') |
||
147 | |||
148 | public function scopeOrderByDislikes(Builder $query, string $direction = 'asc') |
||
152 | |||
153 | /** |
||
154 | * @param int $vote_id |
||
155 | * |
||
156 | * @return mixed |
||
157 | */ |
||
158 | public function deleteVote(int $vote_id) |
||
162 | |||
163 | public function deleteLike(int $like_id) |
||
167 | |||
168 | /** |
||
169 | * @return mixed |
||
170 | */ |
||
171 | public function resetVotes() |
||
175 | |||
176 | public function resetLikes() |
||
180 | |||
181 | /** |
||
182 | * @param int $user_id |
||
183 | * |
||
184 | * @return mixed |
||
185 | */ |
||
186 | public function deleteVotesForUser(int $user_id) |
||
190 | |||
191 | public function deleteLikesForUser(int $user_id) |
||
195 | |||
196 | /** |
||
197 | * @param int $user_id |
||
198 | * @param int $score |
||
199 | * |
||
200 | * @return int |
||
201 | */ |
||
202 | public function updateVotesForUser(int $user_id, int $score) |
||
206 | |||
207 | public function updateLikesForUser(int $user_id, int $score) |
||
211 | |||
212 | /** |
||
213 | * @param int $vote_id |
||
214 | * @param int $score |
||
215 | * |
||
216 | * @return int |
||
217 | */ |
||
218 | public function updateVote(int $vote_id, int $score) |
||
222 | |||
223 | public function updateLike(int $vote_id, int $score) |
||
227 | |||
228 | /** |
||
229 | * @return VoteBuilder |
||
230 | * |
||
231 | * @throws \Throwable |
||
232 | */ |
||
233 | public function getRatingBuilder() |
||
238 | } |
||
239 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.