| Conditions | 7 |
| Paths | 7 |
| Total Lines | 22 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 15 |
| CRAP Score | 7 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 15 | 2 | public static function toOrdinal($value): string |
|
| 16 | { |
||
| 17 | 2 | if (!is_numeric($value)) { |
|
| 18 | 1 | throw new \InvalidArgumentException('Value must be numeric.'); |
|
| 19 | } |
||
| 20 | |||
| 21 | 1 | if (fmod($value, 1) !== 0.00) { |
|
|
|
|||
| 22 | 1 | return $value; |
|
| 23 | } |
||
| 24 | |||
| 25 | 1 | if (\in_array($value % 100, [11, 12, 13], true)) { |
|
| 26 | 1 | return $value . 'th'; |
|
| 27 | } |
||
| 28 | 1 | switch ($value % 10) { |
|
| 29 | 1 | case 1: |
|
| 30 | 1 | return $value . 'st'; |
|
| 31 | 1 | case 2: |
|
| 32 | 1 | return $value . 'nd'; |
|
| 33 | 1 | case 3: |
|
| 34 | 1 | return $value . 'rd'; |
|
| 35 | default: |
||
| 36 | 1 | return $value . 'th'; |
|
| 37 | } |
||
| 54 |