Conditions | 4 |
Paths | 4 |
Total Lines | 21 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 12 |
CRAP Score | 4 |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
36 | 5 | public function transform($input, array $arguments) |
|
37 | { |
||
38 | // I should have two arguments: old format / new format |
||
39 | 5 | if (count($arguments) !== 1) { |
|
40 | 2 | throw new TransformationException('Rule NormalizeURL Expects exactly 1 argument'); |
|
41 | } |
||
42 | 3 | $protocol = $arguments[0]; |
|
43 | |||
44 | 3 | if (strpos($protocol, '://')) { |
|
45 | 1 | throw new TransformationException('Protocol must be specified without "://"'); |
|
46 | } |
||
47 | |||
48 | // Transform it |
||
49 | 2 | $pattern = '|^(?!'.$protocol.')(.+)$|'; |
|
50 | 2 | preg_match($pattern, $input, $matches); |
|
51 | 2 | if (!empty($matches)) { |
|
52 | 1 | $input = $protocol.'://'.$input; |
|
53 | 1 | } |
|
54 | |||
55 | 2 | return $input; |
|
56 | } |
||
57 | } |
||
58 |