Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
6 / 6 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
FilterVarValidateUrl | |
100.00% |
6 / 6 |
|
100.00% |
5 / 5 |
5 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
requirePath | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isPathRequired | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
requireQuery | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isQueryRequired | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * @author: Doug Wilbourne (dougwilbourne@gmail.com) |
5 | */ |
6 | declare(strict_types=1); |
7 | |
8 | namespace pvc\filtervar; |
9 | |
10 | /** |
11 | * Class FilterVarValidateUrl |
12 | * |
13 | * Since php 8.0, requiring scheme (e.g. the protocol, the "http" part of http://www.somewhere.com) and requiring |
14 | * hostname ("www.somewhere.com") have been removed because scheme and hostname have always been required. It is |
15 | * possible to configure web servers so that if the scheme is missing, the server will assume a scheme (usually http). |
16 | * |
17 | * If you look at the documentation for FILTER_VALIDATE_URL, you will see a flag called FILTER_NULL_ON_FAILURE, which |
18 | * is meant to tell filter_var to return null instead of false. This class does not support that - the validate method |
19 | * returns a pure boolean. |
20 | */ |
21 | class FilterVarValidateUrl extends FilterVarValidate |
22 | { |
23 | /** |
24 | * @throws err\InvalidFilterException |
25 | */ |
26 | public function __construct() |
27 | { |
28 | $this->setFilter(FILTER_VALIDATE_URL); |
29 | $this->setLabel('url'); |
30 | } |
31 | |
32 | /** |
33 | * requirePath |
34 | */ |
35 | public function requirePath(): void |
36 | { |
37 | $this->addFlag(FILTER_FLAG_PATH_REQUIRED); |
38 | } |
39 | |
40 | /** |
41 | * isPathRequired |
42 | * @return bool |
43 | */ |
44 | public function isPathRequired(): bool |
45 | { |
46 | return in_array(FILTER_FLAG_PATH_REQUIRED, $this->getFlags()); |
47 | } |
48 | |
49 | /** |
50 | * requireQuery |
51 | */ |
52 | public function requireQuery(): void |
53 | { |
54 | $this->addFlag(FILTER_FLAG_QUERY_REQUIRED); |
55 | } |
56 | |
57 | /** |
58 | * isQueryRequired |
59 | * @return bool |
60 | */ |
61 | public function isQueryRequired(): bool |
62 | { |
63 | return in_array(FILTER_FLAG_QUERY_REQUIRED, $this->getFlags()); |
64 | } |
65 | } |