1 | <?php |
||
32 | trait CrudTrait |
||
33 | { |
||
34 | /** |
||
35 | * removes a user from a project. |
||
36 | * |
||
37 | * @param int $userId |
||
38 | * |
||
39 | * @return mixed |
||
40 | */ |
||
41 | 1 | public function unassignUser($userId) |
|
42 | { |
||
43 | 1 | return $this->projectUsers()->where('user_id', '=', $userId)->delete(); |
|
|
|||
44 | } |
||
45 | |||
46 | /** |
||
47 | * Create a new project. |
||
48 | * |
||
49 | * @param array $input |
||
50 | * |
||
51 | * @return $this |
||
52 | */ |
||
53 | 49 | public function createProject(array $input = []) |
|
72 | |||
73 | /** |
||
74 | * Update project details. |
||
75 | * |
||
76 | * @param array $attributes |
||
77 | * |
||
78 | * @return bool |
||
79 | */ |
||
80 | 1 | public function update(array $attributes = []) |
|
90 | |||
91 | /** |
||
92 | * Save the project tags. |
||
93 | * |
||
94 | * @param array $tagIds |
||
95 | * |
||
96 | * @return bool |
||
97 | */ |
||
98 | public function saveTags(array $tagIds) |
||
120 | |||
121 | /** |
||
122 | * Assign a user to a project. |
||
123 | * |
||
124 | * @param int $userId |
||
125 | * @param int $roleId |
||
126 | * |
||
127 | * @return Project\User |
||
128 | */ |
||
129 | 32 | public function assignUser($userId, $roleId = 0) |
|
136 | |||
137 | /** |
||
138 | * Delete a project. |
||
139 | * |
||
140 | * @return void |
||
141 | * |
||
142 | * @throws \Exception |
||
143 | */ |
||
144 | 1 | public function delete() |
|
172 | } |
||
173 |
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.