| Conditions | 7 |
| Paths | 20 |
| Total Lines | 31 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 56 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 20 | public static function estimateReadingTime( |
||
| 21 | string $content = '', |
||
| 22 | int $wpm = 200, |
||
| 23 | string $format = null |
||
| 24 | ): string { |
||
| 25 | |||
| 26 | $word_count = str_word_count(strip_tags($content)); |
||
| 27 | |||
| 28 | $minutes = floor($word_count / $wpm); |
||
| 29 | $seconds = floor($word_count % $wpm / ($wpm / 60)); |
||
| 30 | |||
| 31 | $str_minutes = ($minutes == 1) ? "minute" : "minutes"; |
||
| 32 | $str_seconds = ($seconds == 1) ? "second" : "seconds"; |
||
| 33 | |||
| 34 | if ($format == 'minutes') { |
||
| 35 | if ($minutes == 0) { |
||
| 36 | return 'Less then one minute'; |
||
| 37 | } else { |
||
| 38 | return "{$minutes}"; |
||
| 39 | } |
||
| 40 | } |
||
| 41 | |||
| 42 | if ($format == 'minutesAndSeconds') { |
||
| 43 | if ($minutes == 0) { |
||
| 44 | return "{$seconds} {$str_seconds}"; |
||
| 45 | } else { |
||
| 46 | return "{$minutes} {$str_minutes}, {$seconds} {$str_seconds}"; |
||
| 47 | } |
||
| 48 | } |
||
| 49 | |||
| 50 | return "Please specify the time format"; |
||
| 51 | } |
||
| 53 |