MacConstraint::validate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 6
rs 10
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 MacConstraint implements Constraint
9
{
10
    public static function validate(string $value): ValidationResult
11
    {
12
        if (filter_var($value, FILTER_VALIDATE_MAC)) {
13
            return new SuccessfulValidationResult();
14
        } else {
15
            return new ValidationResult(false, 'The given value must by a valid MAC address.');
16
        }
17
    }
18
}
19