Test Setup Failed
Push — master ( 1595cb...050b68 )
by Kirill
21:00
created

Factory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 11
dl 0
loc 44
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A match() 0 3 1
A assert() 0 7 3
A __construct() 0 4 2
1
<?php
2
3
/**
4
 * This file is part of Railt package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Railt\SDL\Validator;
13
14
use GraphQL\Contracts\TypeSystem\DefinitionInterface;
15
16
/**
17
 * Class Factory
18
 */
19
class Factory implements ValidatorInterface
20
{
21
    /**
22
     * @var string[]|ValidatorInterface[]
23
     */
24
    private const DEFAULT_VALIDATORS = [
25
        SchemaValidator::class,
26
    ];
27
28
    /**
29
     * @var array|ValidatorInterface[]
30
     */
31
    private array $validators = [];
32
33
    /**
34
     * Factory constructor.
35
     */
36
    public function __construct()
37
    {
38
        foreach (self::DEFAULT_VALIDATORS as $class) {
39
            $this->validators[] = new $class($this);
40
        }
41
    }
42
43
    /**
44
     * @param DefinitionInterface $type
45
     * @return bool
46
     */
47
    public function match(DefinitionInterface $type): bool
48
    {
49
        return true;
50
    }
51
52
    /**
53
     * @param DefinitionInterface $type
54
     * @return void
55
     */
56
    public function assert(DefinitionInterface $type): void
57
    {
58
        foreach ($this->validators as $validator) {
59
            if ($validator->match($type)) {
60
                $validator->assert($type);
61
62
                return;
63
            }
64
        }
65
    }
66
}
67