| Conditions | 9 |
| Paths | 13 |
| Total Lines | 35 |
| Code Lines | 22 |
| Lines | 9 |
| Ratio | 25.71 % |
| Tests | 22 |
| CRAP Score | 9.0066 |
| Changes | 0 | ||
| 1 | <?php |
||
| 44 | 21 | protected function normalize(&$value) |
|
| 45 | { |
||
| 46 | 21 | if (!parent::normalize($value)) { |
|
| 47 | return false; |
||
| 48 | } |
||
| 49 | 21 | if ($value === null) { |
|
| 50 | 2 | return true; |
|
| 51 | } |
||
| 52 | |||
| 53 | 19 | if ($value instanceof \DateTime) { |
|
| 54 | 12 | return true; |
|
| 55 | } |
||
| 56 | |||
| 57 | 14 | View Code Duplication | if (is_object($value)) { |
| 58 | 3 | if (method_exists($value, 'toString')) { |
|
| 59 | 1 | $value = $value->toString(); |
|
| 60 | 3 | } elseif (method_exists($value, '__toString')) { |
|
| 61 | 1 | $value = (string)$value; |
|
| 62 | 1 | } else { |
|
| 63 | 1 | return false; |
|
| 64 | } |
||
| 65 | 2 | } |
|
| 66 | |||
| 67 | 13 | if (!is_string($value)) { |
|
| 68 | 4 | return false; |
|
| 69 | } |
||
| 70 | |||
| 71 | 9 | $format = $this->getConfig('format'); |
|
| 72 | 9 | if ($format) { |
|
| 73 | 1 | $value = \DateTime::createFromFormat($format, $value); |
|
| 74 | 1 | } else { |
|
| 75 | 8 | $value = new \DateTime($value); |
|
| 76 | } |
||
| 77 | 8 | return true; |
|
| 78 | } |
||
| 79 | |||
| 91 |
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.