| Conditions | 4 |
| Paths | 8 |
| Total Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 23 | public function getTimeToReadAttribute() |
||
| 24 | { |
||
| 25 | $word_count = str_word_count(strip_tags($this->content)); |
||
| 26 | |||
| 27 | $minutes = floor($word_count / 200); |
||
| 28 | $seconds = floor($word_count % 200 / (200 / 60)); |
||
| 29 | |||
| 30 | $str_minutes = ($minutes == 1) ? 'minute' : 'minutes'; |
||
| 31 | $str_seconds = ($seconds == 1) ? 'second' : 'seconds'; |
||
| 32 | |||
| 33 | if ($minutes == 0) { |
||
| 34 | return "{$seconds} {$str_seconds}"; |
||
| 35 | } |
||
| 36 | |||
| 37 | return "{$minutes} {$str_minutes}, {$seconds} {$str_seconds}"; |
||
| 38 | } |
||
| 39 | } |
||
| 40 |
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: