| Conditions | 3 |
| Paths | 3 |
| Total Lines | 25 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 12 |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 11 | public static function toString($interval) |
||
| 12 | { |
||
| 13 | |||
| 14 | if ($interval === null) { |
||
| 15 | return null; |
||
| 16 | } |
||
| 17 | |||
| 18 | $dateParts = array_filter([ |
||
| 19 | 'Y' => $interval->y, |
||
| 20 | 'M' => $interval->m, |
||
| 21 | 'D' => $interval->d, |
||
| 22 | ]); |
||
| 23 | $result = 'P' . implode(array_map(fn($v, $k) => $v . $k, $dateParts, array_keys($dateParts))); |
||
| 24 | |||
| 25 | $timeParts = array_filter([ |
||
| 26 | 'H' => $interval->h, |
||
| 27 | 'M' => $interval->i, |
||
| 28 | 'S' => $interval->s, |
||
| 29 | 'F' => $interval->f, |
||
| 30 | ]); |
||
| 31 | if ($timeParts) { |
||
|
|
|||
| 32 | $result .= 'T' . implode(array_map(fn($v, $k) => $v . $k, $timeParts, array_keys($timeParts))); |
||
| 33 | } |
||
| 34 | |||
| 35 | return $result; |
||
| 36 | } |
||
| 38 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.