1 | <?php |
||
17 | class DiscussConversation extends Model |
||
18 | { |
||
19 | use Countable, |
||
20 | Sluggable, |
||
21 | FloodGate, |
||
22 | DiscussConversationPresenter, |
||
23 | HasMentionsTrait; |
||
24 | |||
25 | /** |
||
26 | * The attributes that are mass assignable. |
||
27 | * |
||
28 | * @var array |
||
29 | */ |
||
30 | protected $fillable = [ |
||
31 | 'user_id', |
||
32 | 'category_id', |
||
33 | 'title', |
||
34 | 'slug', |
||
35 | 'post_count', |
||
36 | 'participants_count', |
||
37 | 'is_locked', |
||
38 | 'is_pinned', |
||
39 | 'is_solved', |
||
40 | 'is_edited', |
||
41 | 'edit_count' |
||
42 | ]; |
||
43 | |||
44 | /** |
||
45 | * The accessors to append to the model's array form. |
||
46 | * |
||
47 | * @var array |
||
48 | */ |
||
49 | protected $appends = [ |
||
50 | 'conversation_url', |
||
51 | 'last_page' |
||
52 | ]; |
||
53 | |||
54 | /** |
||
55 | * The attributes that should be mutated to dates. |
||
56 | * |
||
57 | * @var array |
||
58 | */ |
||
59 | protected $dates = [ |
||
60 | 'edited_at' |
||
61 | ]; |
||
62 | |||
63 | /** |
||
64 | * The "booting" method of the model. |
||
65 | * |
||
66 | * @return void |
||
67 | */ |
||
68 | protected static function boot() |
||
82 | |||
83 | /** |
||
84 | * Return the field to slug. |
||
85 | * |
||
86 | * @return string |
||
87 | */ |
||
88 | public function slugStrategy(): string |
||
92 | |||
93 | /** |
||
94 | * Return the count cache configuration. |
||
95 | * |
||
96 | * @return array |
||
97 | */ |
||
98 | public function countCaches(): array |
||
105 | |||
106 | /** |
||
107 | * Get the category that owns the conversation. |
||
108 | * |
||
109 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
110 | */ |
||
111 | public function category() |
||
115 | |||
116 | /** |
||
117 | * Get the user that owns the conversation. |
||
118 | * |
||
119 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
120 | */ |
||
121 | public function user() |
||
125 | |||
126 | /** |
||
127 | * Get the posts for the conversation. |
||
128 | * |
||
129 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
130 | */ |
||
131 | public function posts() |
||
135 | |||
136 | /** |
||
137 | * Get the users for the conversation. |
||
138 | * |
||
139 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
140 | */ |
||
141 | public function users() |
||
145 | |||
146 | /** |
||
147 | * Get the first post of the conversation. |
||
148 | * |
||
149 | * @return \Illuminate\Database\Eloquent\Relations\HasOne |
||
150 | */ |
||
151 | public function firstPost() |
||
155 | |||
156 | /** |
||
157 | * Get the solved post of the conversation. |
||
158 | * |
||
159 | * @return \Illuminate\Database\Eloquent\Relations\HasOne |
||
160 | */ |
||
161 | public function solvedPost() |
||
165 | |||
166 | /** |
||
167 | * Get the last post of the conversation. |
||
168 | * |
||
169 | * @return \Illuminate\Database\Eloquent\Relations\HasOne |
||
170 | */ |
||
171 | public function lastPost() |
||
175 | |||
176 | /** |
||
177 | * Get the user that edited the conversation. |
||
178 | * |
||
179 | * @return \Illuminate\Database\Eloquent\Relations\HasOne |
||
180 | */ |
||
181 | public function editedUser() |
||
185 | |||
186 | /** |
||
187 | * Get the discuss logs for the conversation. |
||
188 | * |
||
189 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany |
||
190 | */ |
||
191 | public function discussLogs() |
||
195 | |||
196 | /** |
||
197 | * Get the logs and posts related to the current conversation |
||
198 | * for the given the pagination posts and return the data |
||
199 | * ordered by `created_at` as a Collection. |
||
200 | * |
||
201 | * @param \Illuminate\Support\Collection $posts |
||
202 | * @param int $page |
||
203 | * |
||
204 | * @return \Illuminate\Support\Collection |
||
205 | */ |
||
206 | public function getPostsWithLogs(Collection $posts, int $page): Collection |
||
247 | } |
||
248 |
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: