Passed
Push — master ( 9e7e6b...999440 )
by Dedipyaman
01:53
created

IPAddressValidator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 11
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 8 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Phypes\Validator;
5
6
use Phypes\Error\TypeError\TypeError;
7
use Phypes\Error\TypeError\TypeErrorCode;
8
use Phypes\Result;
9
10
class IPAddressValidator extends AbstractValidator
11
{
12
13
    public function validate($type, $options = []): Result
14
    {
15
        if (filter_var($type, FILTER_VALIDATE_IP)) {
16
17
            return $this->success();
18
        }
19
        $errors = new TypeError(TypeErrorCode::IP_INVALID, 'The provided IP address is invalid');
20
        return $this->failure($errors);
21
    }
22
}