Test Setup Failed
Branch master (c77351)
by Simone
02:28
created

ValidatorFactory::fromName()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
cc 2
eloc 15
nc 2
nop 1
1
<?php
2
3
/**
4
 * This file is part of sensorario/resources repository
5
 *
6
 * (c) Simone Gentili <[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
namespace Sensorario\Resources\Validators;
13
14
use Egulias\EmailValidator\EmailValidator;
15
use Egulias\EmailValidator\Validation\DNSCheckValidation;
16
use Egulias\EmailValidator\Validation\MultipleValidationWithAnd;
17
use Egulias\EmailValidator\Validation\RFCValidation;
18
use Sensorario\Resources\Validators\Interfaces\Validator;
19
20
class ValidatorFactory
21
{
22
    public static function fromName($name) : Validator
23
    {
24
        $validatorClass = 'Sensorario'
25
            .'\\Resources'
26
            .'\\Validators'
27
            .'\\Validators'
28
            .'\\' . $name;
29
30
        if ('RightType' == $name) {
31
            $validator = new EmailValidator();
32
33
            $multipleValidations = new MultipleValidationWithAnd([
34
                new RFCValidation(),
35
                new DNSCheckValidation()
36
            ]);
37
38
            return new $validatorClass(
39
                $validator,
40
                $multipleValidations
41
            );
42
        }
43
44
        return new $validatorClass();
45
    }
46
}
47