NameUserValidation   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 8
c 2
b 0
f 0
dl 0
loc 18
rs 10
ccs 9
cts 9
cp 1
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A validate() 0 9 2
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of FlexPHP.
4
 *
5
 * (c) Freddie Gar <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace FlexPHP\Database\Validations;
11
12
use FlexPHP\Database\Exception\NameUserValidationException;
13
use FlexPHP\Database\Validators\NameUserValidator;
14
15
final class NameUserValidation implements ValidationInterface
16
{
17
    private string $name;
18
19 119
    public function __construct(string $name)
20
    {
21 119
        $this->name = $name;
22 119
    }
23
24 119
    public function validate(): void
25
    {
26 119
        $validator = new NameUserValidator();
27
28 119
        $violations = $validator->validate($this->name);
29
30 119
        if (\count($violations) > 0) {
31 12
            throw new NameUserValidationException(
32 12
                \sprintf("%1\$s:\n%2\$s", $this->name, $violations->get(0)->getPropertyPath())
33
            );
34
        }
35 107
    }
36
}
37