1 | <?php |
||
18 | class DiscussConversation extends Model |
||
19 | { |
||
20 | use Countable, |
||
21 | Sluggable, |
||
22 | FloodGate, |
||
23 | DiscussConversationPresenter, |
||
24 | HasMentionsTrait; |
||
25 | |||
26 | /** |
||
27 | * The attributes that are mass assignable. |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | protected $fillable = [ |
||
32 | 'user_id', |
||
33 | 'category_id', |
||
34 | 'title', |
||
35 | 'slug', |
||
36 | 'post_count', |
||
37 | 'participants_count', |
||
38 | 'is_locked', |
||
39 | 'is_pinned', |
||
40 | 'is_solved', |
||
41 | 'is_edited', |
||
42 | 'edit_count' |
||
43 | ]; |
||
44 | |||
45 | /** |
||
46 | * The accessors to append to the model's array form. |
||
47 | * |
||
48 | * @var array |
||
49 | */ |
||
50 | protected $appends = [ |
||
51 | 'conversation_url', |
||
52 | 'last_page' |
||
53 | ]; |
||
54 | |||
55 | /** |
||
56 | * The attributes that should be mutated to dates. |
||
57 | * |
||
58 | * @var array |
||
59 | */ |
||
60 | protected $dates = [ |
||
61 | 'edited_at' |
||
62 | ]; |
||
63 | |||
64 | /** |
||
65 | * The "booting" method of the model. |
||
66 | * |
||
67 | * @return void |
||
68 | */ |
||
69 | protected static function boot() |
||
119 | |||
120 | /** |
||
121 | * Return the field to slug. |
||
122 | * |
||
123 | * @return string |
||
124 | */ |
||
125 | public function slugStrategy(): string |
||
129 | |||
130 | /** |
||
131 | * Return the count cache configuration. |
||
132 | * |
||
133 | * @return array |
||
134 | */ |
||
135 | public function countCaches(): array |
||
142 | |||
143 | /** |
||
144 | * Get the category that owns the conversation. |
||
145 | * |
||
146 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
147 | */ |
||
148 | public function category() |
||
152 | |||
153 | /** |
||
154 | * Get the user that owns the conversation. |
||
155 | * |
||
156 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
157 | */ |
||
158 | public function user() |
||
162 | |||
163 | /** |
||
164 | * Get the posts for the conversation. |
||
165 | * |
||
166 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
167 | */ |
||
168 | public function posts() |
||
172 | |||
173 | /** |
||
174 | * Get the users for the conversation. |
||
175 | * |
||
176 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
177 | */ |
||
178 | public function users() |
||
182 | |||
183 | /** |
||
184 | * Get the first post of the conversation. |
||
185 | * |
||
186 | * @return \Illuminate\Database\Eloquent\Relations\HasOne |
||
187 | */ |
||
188 | public function firstPost() |
||
192 | |||
193 | /** |
||
194 | * Get the solved post of the conversation. |
||
195 | * |
||
196 | * @return \Illuminate\Database\Eloquent\Relations\HasOne |
||
197 | */ |
||
198 | public function solvedPost() |
||
202 | |||
203 | /** |
||
204 | * Get the last post of the conversation. |
||
205 | * |
||
206 | * @return \Illuminate\Database\Eloquent\Relations\HasOne |
||
207 | */ |
||
208 | public function lastPost() |
||
212 | |||
213 | /** |
||
214 | * Get the user that edited the conversation. |
||
215 | * |
||
216 | * @return \Illuminate\Database\Eloquent\Relations\HasOne |
||
217 | */ |
||
218 | public function editedUser() |
||
222 | |||
223 | /** |
||
224 | * Get the discuss logs for the conversation. |
||
225 | * |
||
226 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany |
||
227 | */ |
||
228 | public function discussLogs() |
||
232 | |||
233 | /** |
||
234 | * Get the logs and posts related to the current conversation |
||
235 | * for the given the pagination posts and return the data |
||
236 | * ordered by `created_at` as a Collection. |
||
237 | * |
||
238 | * @param \Illuminate\Support\Collection $posts |
||
239 | * @param int $page |
||
240 | * |
||
241 | * @return \Illuminate\Support\Collection |
||
242 | */ |
||
243 | public function getPostsWithLogs(Collection $posts, int $page): Collection |
||
284 | } |
||
285 |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: