Completed
Pull Request — master (#109)
by Simone
03:59 queued 01:43
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
namespace Sensorario\Resources\Validators;
4
5
use Egulias\EmailValidator\EmailValidator;
6
use Egulias\EmailValidator\Validation\DNSCheckValidation;
7
use Egulias\EmailValidator\Validation\MultipleValidationWithAnd;
8
use Egulias\EmailValidator\Validation\RFCValidation;
9
use Sensorario\Resources\Validators\Interfaces\Validator;
10
11
class ValidatorFactory
12
{
13
    public static function fromName($name) : Validator
14
    {
15
        $validatorClass = 'Sensorario'
16
            .'\\Resources'
17
            .'\\Validators'
18
            .'\\Validators'
19
            .'\\' . $name;
20
21
        if ('RightType' == $name) {
22
            $validator = new EmailValidator();
23
24
            $multipleValidations = new MultipleValidationWithAnd([
25
                new RFCValidation(),
26
                new DNSCheckValidation()
27
            ]);
28
29
            return new $validatorClass(
30
                $validator,
31
                $multipleValidations
32
            );
33
        }
34
35
        return new $validatorClass();
36
    }
37
}
38