1 | <?php |
||
49 | trait CrudTrait |
||
50 | { |
||
51 | /** |
||
52 | * Set the issue is updated by a user. |
||
53 | * |
||
54 | * @param int $userId |
||
55 | * |
||
56 | * @return Eloquent\Model |
||
57 | */ |
||
58 | 10 | public function changeUpdatedBy($userId) |
|
65 | |||
66 | /** |
||
67 | * Reassign the issue to a new user. |
||
68 | * |
||
69 | * @param int|User $assignTo |
||
70 | * @param User $user |
||
71 | * |
||
72 | * @return Eloquent\Model |
||
73 | */ |
||
74 | 3 | public function reassign($assignTo, User $user) |
|
93 | |||
94 | /** |
||
95 | * Update the given issue. |
||
96 | * |
||
97 | * @param array $input |
||
98 | * |
||
99 | * @return Eloquent\Model |
||
100 | */ |
||
101 | 8 | public function updateIssue(array $input) |
|
102 | { |
||
103 | 6 | $fill = array_only($input, [ |
|
104 | 6 | 'title', 'body', 'assigned_to', |
|
105 | 6 | ]); |
|
106 | 6 | $fill['updated_by'] = $this->updatedBy->id; |
|
107 | |||
108 | 6 | if (isset($input['time_quote']['lock'])) { |
|
109 | $fill['lock_quote'] = $input['time_quote']['lock']; |
||
110 | } |
||
111 | |||
112 | // Only save quote if not locked or locked & user allowed to modify it |
||
113 | 6 | if (array_key_exists('time_quote', $input) && |
|
114 | 6 | (!$this->isQuoteLocked() || $this->user->permission(Model\Permission::PERM_ISSUE_LOCK_QUOTE)) |
|
115 | 6 | ) { |
|
116 | 6 | $fill['time_quote'] = $input['time_quote']; |
|
117 | 6 | } |
|
118 | |||
119 | /* Add to activity log for assignment if changed */ |
||
120 | 6 | if ($input['assigned_to'] != $this->assigned_to) { |
|
121 | 1 | $this->activities()->save(new User\Activity([ |
|
122 | 1 | 'type_id' => Activity::TYPE_REASSIGN_ISSUE, |
|
123 | 1 | 'parent_id' => $this->project->id, |
|
124 | 1 | 'user_id' => $this->updatedBy->id, |
|
125 | 1 | 'action_id' => $this->assigned_to, |
|
126 | 1 | ])); |
|
127 | 1 | } |
|
128 | |||
129 | 6 | $this->fill($fill); |
|
130 | |||
131 | 6 | $this->syncTags($input, $this->tags()->with('parent')->get()); |
|
132 | |||
133 | // Add event on successful save |
||
134 | static::saved(function (Project\Issue $issue) { |
||
135 | 6 | $this->queueUpdate($issue, $issue->updatedBy); |
|
136 | 8 | }); |
|
137 | |||
138 | 6 | return $this->save(); |
|
139 | } |
||
140 | |||
141 | /** |
||
142 | * Create a new issue. |
||
143 | * |
||
144 | * @param array $input |
||
145 | * |
||
146 | * @return CrudTrait |
||
147 | */ |
||
148 | 37 | public function createIssue(array $input) |
|
189 | |||
190 | /** |
||
191 | * Move the issue (comments & activities) to another project. |
||
192 | * |
||
193 | * @param int $projectId |
||
194 | * |
||
195 | * @return $this |
||
196 | */ |
||
197 | 7 | public function changeProject($projectId) |
|
215 | |||
216 | /** |
||
217 | * Delete an issue. |
||
218 | * |
||
219 | * @return bool |
||
220 | * |
||
221 | * @throws \Exception |
||
222 | */ |
||
223 | public function delete() |
||
250 | } |
||
251 |
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.