Conditions | 5 |
Paths | 4 |
Total Lines | 16 |
Code Lines | 8 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
27 | public static function filter($value, bool $allowNull = false) |
||
28 | { |
||
29 | if ($allowNull === true && $value === null) { |
||
30 | return null; |
||
31 | } |
||
32 | |||
33 | if (!is_string($value)) { |
||
34 | throw new FilterException("Value '" . var_export($value, true) . "' is not a string"); |
||
35 | } |
||
36 | |||
37 | $filteredUrl = filter_var($value, FILTER_VALIDATE_URL); |
||
38 | if ($filteredUrl === false) { |
||
39 | throw new FilterException("Value '{$value}' is not a valid url"); |
||
40 | } |
||
41 | |||
42 | return $filteredUrl; |
||
43 | } |
||
45 |