Conditions | 2 |
Paths | 2 |
Total Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
9 | public function commentAsUser(Model $user, string $comment) |
||
10 | { |
||
11 | if ( ! $this->allow_comments) { |
||
|
|||
12 | return null; |
||
13 | } |
||
14 | |||
15 | return $this->comments()->create([ |
||
16 | 'content' => $comment, |
||
17 | 'user_id' => $user->getKey(), |
||
18 | 'email' => $user->email, |
||
19 | 'is_approved' => true, |
||
20 | ]); |
||
21 | } |
||
22 | |||
38 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: