Conditions | 7 |
Paths | 5 |
Total Lines | 21 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
29 | public static function filter($value, $allowNull = false) |
||
30 | { |
||
31 | if ($allowNull !== false && $allowNull !== true) { |
||
32 | throw new \InvalidArgumentException('$allowNull was not a boolean value'); |
||
33 | } |
||
34 | |||
35 | if ($allowNull === true && $value === null) { |
||
36 | return null; |
||
37 | } |
||
38 | |||
39 | if (!is_string($value)) { |
||
40 | throw new \Exception("Value '" . var_export($value, true) . "' is not a string"); |
||
41 | } |
||
42 | |||
43 | $filteredUrl = filter_var($value, FILTER_VALIDATE_URL); |
||
44 | if ($filteredUrl === false) { |
||
45 | throw new \Exception("Value '{$value}' is not a valid url"); |
||
46 | } |
||
47 | |||
48 | return $filteredUrl; |
||
49 | } |
||
50 | } |
||
51 |