1 | <?php |
||
21 | trait Commentable |
||
22 | { |
||
23 | |||
24 | /** |
||
25 | * @return string |
||
26 | */ |
||
27 | public function commentable_model() |
||
31 | |||
32 | /** |
||
33 | * @return mixed |
||
34 | */ |
||
35 | public function comments() |
||
39 | |||
40 | /** |
||
41 | * @param $data |
||
42 | * @param Model $creator |
||
43 | * @param Model|null $parent |
||
44 | * |
||
45 | * @return static |
||
46 | */ |
||
47 | public function comment($data, Model $creator, Model $parent = null) |
||
59 | |||
60 | /** |
||
61 | * @param $id |
||
62 | * @param $data |
||
63 | * @param Model|null $parent |
||
64 | * |
||
65 | * @return mixed |
||
66 | */ |
||
67 | public function updateComment($id, $data, Model $parent = null) |
||
79 | |||
80 | /** |
||
81 | * @param $id |
||
82 | * |
||
83 | * @return mixed |
||
84 | */ |
||
85 | public function deleteComment($id) |
||
91 | |||
92 | /** |
||
93 | * @return mixed |
||
94 | */ |
||
95 | public function commentCount() |
||
99 | } |
||
100 |
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.