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

ValidatorFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 0
loc 27
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B fromName() 0 24 2
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