ZoneNameValidator::validate()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 6
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 10
rs 10
1
<?php
2
3
/*
4
 * This file is part of the CwdPowerDNS Client
5
 *
6
 * (c) 2018 cwd.at GmbH <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Cwd\PowerDNSClient\Validator;
15
16
use Symfony\Component\Validator\Constraint;
17
use Symfony\Component\Validator\ConstraintValidator;
18
19
class ZoneNameValidator extends ConstraintValidator
20
{
21
    public function validate($value, Constraint $constraint): void
22
    {
23
        if (null === $value || '' === $value) {
24
            return;
25
        }
26
27
        if ('.' !== substr($value, -1)) {
28
            $this->context->buildViolation($constraint->message)
29
                ->setParameter('{{ string }}', $value)
30
                ->addViolation();
31
        }
32
    }
33
}
34