We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Total Complexity | 9 |
Total Lines | 41 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
29 | trait ComparisonHelper |
||
30 | { |
||
31 | /** |
||
32 | * Tries to convert a value into something that can be compared with PHP operators. |
||
33 | * |
||
34 | * @param mixed $value |
||
35 | * |
||
36 | * @return mixed |
||
37 | */ |
||
38 | 102 | private function toComparable($value) |
|
39 | { |
||
40 | 102 | if ($value instanceof Countable) { |
|
41 | 10 | return $value->count(); |
|
42 | } |
||
43 | |||
44 | 102 | if ($value instanceof DateTimeInterface || !is_string($value) || is_numeric($value) || empty($value)) { |
|
45 | 72 | return $value; |
|
46 | } |
||
47 | |||
48 | 48 | if (1 === mb_strlen($value)) { |
|
49 | 18 | return $value; |
|
50 | } |
||
51 | |||
52 | try { |
||
53 | 35 | return new DateTimeImmutable($value); |
|
54 | 3 | } catch (Exception $e) { |
|
55 | 3 | return $value; |
|
56 | } |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * Returns whether the values can be compared or not. |
||
61 | * |
||
62 | * @param mixed $left |
||
63 | * @param mixed $right |
||
64 | * |
||
65 | * @return bool |
||
66 | */ |
||
67 | 100 | private function isAbleToCompareValues($left, $right) |
|
70 | } |
||
71 | } |
||
72 |