| Conditions | 8 |
| Paths | 7 |
| Total Lines | 37 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 15 | public static function parseDate($date, $from = 'Y-m-d', $to = 'obj') |
||
| 16 | { |
||
| 17 | if (!is_string($from)) { |
||
| 18 | throw new InvalidArgumentException('Formato de entrada inválido'); |
||
| 19 | } |
||
| 20 | |||
| 21 | if (!is_string($to)) { |
||
| 22 | throw new InvalidArgumentException('Formato de saída inválido'); |
||
| 23 | } |
||
| 24 | |||
| 25 | if ($date instanceof DateTime && $to === 'obj') { |
||
| 26 | return $date; |
||
| 27 | } |
||
| 28 | |||
| 29 | if ($date instanceof DateTime) { |
||
| 30 | return $date->format($to); |
||
| 31 | } |
||
| 32 | |||
| 33 | $dateObject = DateTime::createFromFormat($from, $date); |
||
| 34 | |||
| 35 | if ($to === 'obj') { |
||
| 36 | return $dateObject; |
||
| 37 | } |
||
| 38 | |||
| 39 | if (is_string($to)) { |
||
| 40 | return $dateObject->format($to); |
||
| 41 | } |
||
| 42 | |||
| 43 | throw new InvalidArgumentException( |
||
| 44 | sprintf( |
||
| 45 | 'Não foi possível converter a data "%s" do formato "%s" para o formato "%s"', |
||
| 46 | $date, |
||
| 47 | $from, |
||
| 48 | $to |
||
| 49 | ) |
||
| 50 | ); |
||
| 51 | } |
||
| 52 | } |
||
| 53 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.