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 | 9 | public function changeUpdatedBy($userId) |
|
65 | |||
66 | /** |
||
67 | * Reassign the issue to a new user. |
||
68 | * |
||
69 | * @param int $assignTo |
||
70 | * @param \Illuminate\Contracts\Auth\Authenticatable|null $user |
||
71 | * |
||
72 | * @return Eloquent\Model |
||
73 | */ |
||
74 | 4 | public function reassign($assignTo, $user) |
|
75 | { |
||
76 | 2 | $assignToId = !$assignTo instanceof User ? $assignTo : $assignTo->id; |
|
77 | 2 | $userId = !$user instanceof User ? $user : $user->id; |
|
78 | 2 | $this->assigned_to = $assignToId; |
|
79 | |||
80 | // Add event on successful save |
||
81 | static::saved(function (Project\Issue $issue) use ($userId) { |
||
82 | 4 | $this->queueAssign($issue, $userId); |
|
83 | 2 | }); |
|
84 | |||
85 | 2 | $this->save(); |
|
86 | |||
87 | return $this->activities()->save(new User\Activity([ |
||
88 | 'type_id' => Activity::TYPE_REASSIGN_ISSUE, |
||
89 | 'parent_id' => $this->project->id, |
||
90 | 'user_id' => $userId, |
||
91 | 'action_id' => $this->assigned_to, |
||
92 | ])); |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * Update the given issue. |
||
97 | * |
||
98 | * @param array $input |
||
99 | * |
||
100 | * @return Eloquent\Model |
||
101 | */ |
||
102 | 3 | public function updateIssue(array $input) |
|
103 | { |
||
104 | $fill = [ |
||
105 | 3 | 'title' => $input['title'], |
|
106 | 3 | 'body' => $input['body'], |
|
107 | 3 | 'assigned_to' => $input['assigned_to'], |
|
108 | 3 | 'time_quote' => $input['time_quote'], |
|
109 | 3 | 'updated_by' => $this->updatedBy->id, |
|
110 | ]; |
||
111 | |||
112 | /* Add to activity log for assignment if changed */ |
||
113 | 3 | if ($input['assigned_to'] != $this->assigned_to) { |
|
114 | 1 | $this->activities()->save(new User\Activity([ |
|
115 | 1 | 'type_id' => Activity::TYPE_REASSIGN_ISSUE, |
|
116 | 1 | 'parent_id' => $this->project->id, |
|
117 | 1 | 'user_id' => $this->updatedBy->id, |
|
118 | 1 | 'action_id' => $this->assigned_to, |
|
119 | ])); |
||
120 | } |
||
121 | |||
122 | 3 | $this->fill($fill); |
|
123 | |||
124 | 3 | $this->syncTags($input, $this->tags()->with('parent')->get()); |
|
125 | |||
126 | // Add event on successful save |
||
127 | 3 | static::saved(function (Project\Issue $issue) { |
|
128 | 3 | $this->queueUpdate($issue, $issue->updatedBy); |
|
129 | 3 | }); |
|
130 | |||
131 | 3 | return $this->save(); |
|
132 | } |
||
133 | |||
134 | /** |
||
135 | * Create a new issue. |
||
136 | * |
||
137 | * @param array $input |
||
138 | * |
||
139 | * @return CrudTrait |
||
140 | */ |
||
141 | 31 | public function createIssue(array $input) |
|
182 | |||
183 | /** |
||
184 | * Move the issue (comments & activities) to another project. |
||
185 | * |
||
186 | * @param int $projectId |
||
187 | * |
||
188 | * @return $this |
||
189 | */ |
||
190 | public function changeProject($projectId) |
||
208 | } |
||
209 |
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.