IpConstraint   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 8
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 8
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 6 2
1
<?php
2
3
namespace Startwind\Forrest\Command\Parameters\Validation\Constraint;
4
5
use Startwind\Forrest\Command\Parameters\Validation\SuccessfulValidationResult;
6
use Startwind\Forrest\Command\Parameters\Validation\ValidationResult;
7
8
class IpConstraint implements Constraint
9
{
10
    public static function validate(string $value): ValidationResult
11
    {
12
        if (filter_var($value, FILTER_VALIDATE_IP)) {
13
            return new SuccessfulValidationResult();
14
        } else {
15
            return new ValidationResult(false, 'The given value must by a valid IP address.');
16
        }
17
    }
18
}
19