1 | <?php |
||
12 | trait GroupSerializerTrait { |
||
13 | |||
14 | /** |
||
15 | * @param mixed $model |
||
16 | * @return Relationship |
||
17 | */ |
||
18 | public function actions($model) { |
||
22 | |||
23 | /** |
||
24 | * @param mixed $model |
||
25 | * @param array $fields |
||
26 | */ |
||
27 | public function getAttributes($model, array $fields = null) { |
||
38 | |||
39 | /** |
||
40 | */ |
||
41 | public function getFields() { |
||
44 | |||
45 | /** |
||
46 | * @param mixed $model |
||
47 | * @return string |
||
48 | */ |
||
49 | public function getId($model) { |
||
52 | |||
53 | /** |
||
54 | */ |
||
55 | public function getRelationships() { |
||
61 | |||
62 | /** |
||
63 | */ |
||
64 | public function getSortFields() { |
||
67 | |||
68 | /** |
||
69 | * @param mixed $model |
||
70 | * @return string |
||
71 | */ |
||
72 | public function getType($model) { |
||
75 | |||
76 | /** |
||
77 | * @param mixed $model |
||
78 | * @param mixed $data |
||
79 | * @return mixed The model |
||
80 | */ |
||
81 | public function hydrate($model, $data) { |
||
92 | |||
93 | /** |
||
94 | * @param mixed $model |
||
95 | * @return Relationship |
||
96 | */ |
||
97 | public function users($model) { |
||
101 | |||
102 | /** |
||
103 | * @param mixed $model |
||
104 | * @param mixed $data |
||
105 | */ |
||
106 | abstract protected function hydrateRelationships($model, $data); |
||
107 | } |
||
108 |
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.