Conditions | 4 |
Paths | 4 |
Total Lines | 21 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Tests | 10 |
CRAP Score | 4 |
Changes | 0 |
1 | <?php |
||
36 | 6 | public function transform($input, array $arguments) |
|
37 | { |
||
38 | // I should have two arguments: old format / new format |
||
39 | 6 | if (count($arguments) !== 2) { |
|
40 | 2 | throw new TransformationException('Rule Date Expects exactly 2 arguments'); |
|
41 | } |
||
42 | |||
43 | // Validate the date with the format provided |
||
44 | 4 | $dateTime = \DateTime::createFromFormat($arguments[0], $input); |
|
45 | 4 | if ($dateTime === false) { |
|
46 | 1 | throw new TransformationException("Input ($input) or format ({$arguments[0]}) is not valid"); |
|
47 | } |
||
48 | |||
49 | // Transform it |
||
50 | 3 | $output = $dateTime->format($arguments[1]); |
|
51 | 3 | if (strlen($output) === 0) { |
|
52 | 1 | throw new TransformationException('Output format seems not valid. Returned date is empty'); |
|
53 | } |
||
54 | |||
55 | 2 | return $output; |
|
56 | } |
||
57 | } |
||
58 |