| Conditions | 5 |
| Paths | 3 |
| Total Lines | 16 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 8 |
| CRAP Score | 5.0342 |
| Changes | 0 | ||
| 1 | <?php |
||
| 46 | 8 | public function validate($input) : bool |
|
| 47 | { |
||
| 48 | 8 | $input = (string) $input; |
|
| 49 | // check by regular expression |
||
| 50 | 8 | if (preg_match("/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*$/i", $input) |
|
| 51 | 8 | && preg_match("/^.{1,253}$/", $input) |
|
| 52 | 8 | && preg_match("/^[^\.]{1,63}(\.[^\.]{1,63})*$/", $input)) { |
|
| 53 | // check by DNS record |
||
| 54 | 4 | if ($this->checkDns) { |
|
| 55 | return checkdnsrr($input, "A"); |
||
| 56 | } else { |
||
| 57 | 4 | return true; |
|
| 58 | } |
||
| 59 | } |
||
| 60 | 4 | return false; |
|
| 61 | } |
||
| 62 | } |
||
| 63 |