| Conditions | 5 |
| Paths | 6 |
| Total Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 36 | public function calculate(string $text, array $options = []): int |
||
| 37 | { |
||
| 38 | $readingSpeed = abs( |
||
| 39 | isset($options[Settings::READING_SPEED_KEY]) |
||
| 40 | ? (int)$options[Settings::READING_SPEED_KEY] |
||
| 41 | : $this->settings->readingSpeed() |
||
| 42 | ); |
||
| 43 | |||
| 44 | $isRoundingUpEnabled = isset($options[Settings::ROUNDING_UP_ENABLED_KEY]) |
||
| 45 | ? (bool)$options[Settings::ROUNDING_UP_ENABLED_KEY] |
||
| 46 | : $this->settings->isRoundingUpEnabled(); |
||
| 47 | |||
| 48 | if (!$readingSpeed) { |
||
| 49 | return 0; |
||
| 50 | } else { |
||
| 51 | $rawTimeToRead = str_word_count(strip_tags($text)) / $readingSpeed; |
||
| 52 | |||
| 53 | if ($isRoundingUpEnabled) { |
||
| 54 | return ceil($rawTimeToRead); |
||
| 55 | } else { |
||
| 56 | return (int)round($rawTimeToRead); |
||
| 57 | } |
||
| 58 | } |
||
| 59 | } |
||
| 60 | } |