NameDatabaseValidation   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
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 validate() 0 9 2
A __construct() 0 3 1
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\DatabaseValidationException;
13
use FlexPHP\Database\Validators\NameDatabaseValidator;
14
15
final class NameDatabaseValidation implements ValidationInterface
16
{
17
    private string $name;
18
19 25
    public function __construct(string $name)
20
    {
21 25
        $this->name = $name;
22 25
    }
23
24 25
    public function validate(): void
25
    {
26 25
        $validator = new NameDatabaseValidator();
27
28 25
        $violations = $validator->validate($this->name);
29
30 25
        if (\count($violations) > 0) {
31 12
            throw new DatabaseValidationException(
32 12
                \sprintf('Database name [%1$s] invalid', $this->name)
33
            );
34
        }
35 13
    }
36
}
37