1 | <?php |
||
8 | trait HasProjects |
||
9 | { |
||
10 | use HasProjectRoles; |
||
11 | |||
12 | public function projects() : BelongsToMany |
||
16 | |||
17 | /** |
||
18 | * Get count of the model's Project relations |
||
19 | * |
||
20 | * @return bool |
||
21 | */ |
||
22 | public function hasProjects() : bool |
||
26 | |||
27 | /** |
||
28 | * Determine if the given Project is owned by the model. |
||
29 | * |
||
30 | * @param \Chriscreates\Projects\Models\Project $project |
||
31 | * @return bool |
||
32 | */ |
||
33 | public function ownsProject(Project $project) : bool |
||
37 | |||
38 | /** |
||
39 | * Determine if the given model is on a Project. |
||
40 | * |
||
41 | * @param \Chriscreates\Projects\Models\Project $project |
||
42 | * @return bool |
||
43 | */ |
||
44 | public function isOnProject(Project $project) : bool |
||
52 | } |
||
53 |
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.