rhertogh /
yii2-oauth2-server
| 1 | <?php |
||
| 2 | |||
| 3 | namespace rhertogh\Yii2Oauth2Server\helpers; |
||
| 4 | |||
| 5 | class DateIntervalHelper |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * @param \DateInterval|null $interval |
||
| 9 | * @return string|null |
||
| 10 | */ |
||
| 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) { |
||
|
0 ignored issues
–
show
|
|||
| 32 | $result .= 'T' . implode(array_map(fn($v, $k) => $v . $k, $timeParts, array_keys($timeParts))); |
||
| 33 | } |
||
| 34 | |||
| 35 | return $result; |
||
| 36 | } |
||
| 37 | } |
||
| 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.