Completed
Push — develop ( 8bd504...58ca2f )
by Freddie
09:29
created

NameDatabaseValidation   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

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
    /**
18
     * @var string
19
     */
20
    private $name;
21
22 23
    public function __construct(string $name)
23
    {
24 23
        $this->name = $name;
25 23
    }
26
27 23
    public function validate(): void
28
    {
29 23
        $validator = new NameDatabaseValidator();
30
31 23
        $violations = $validator->validate($this->name);
32
33 23
        if (\count($violations)) {
34 12
            throw new DatabaseValidationException(
35 12
                \sprintf('Database name [%1$s] invalid', $this->name)
36
            );
37
        }
38 11
    }
39
}
40