Passed
Push — master ( f360f0...1bc594 )
by Bruno
06:10
created

Validator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 16
ccs 6
cts 7
cp 0.8571
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A factory() 0 10 3
1
<?php declare(strict_types=1);
2
3
namespace Formularium;
4
5
use Formularium\Exception\ClassNotFoundException;
6
use Formularium\Exception\ValidatorException;
7
8
/**
9
 * Abstract base classe to validate data in composition to the validation in
10
 * datatypes.
11
 */
12
class Validator
13
{
14
    /**
15
     * Factory.
16
     *
17
     */
18 7
    public static function factory(string $validatorName): ValidatorInterface
19
    {
20 7
        $class = "\\Formularium\\Validator\\$validatorName";
21 7
        if (!class_exists($class)) {
22 5
            $class = "$validatorName";
23 5
            if (!class_exists($class)) {
24
                throw new ClassNotFoundException("Invalid datatype validator $validatorName");
25
            }
26
        }
27 7
        return new $class();
28
    }
29
}
30