Completed
Push — master ( c1a156...8cadde )
by Kirill
08:14
created

DocumentSystem   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 76.47%

Importance

Changes 0
Metric Value
dl 0
loc 34
ccs 13
cts 17
cp 0.7647
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 6

1 Method

Rating   Name   Duplication   Size   Complexity  
B resolve() 0 27 6
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\SDL\Compiler\System\Provider;
11
12
use Railt\Parser\Ast\RuleInterface;
13
use Railt\Reflection\Contracts\Definition;
14
use Railt\Reflection\Contracts\Definition\TypeDefinition;
15
use Railt\Reflection\Contracts\Document;
16
use Railt\Reflection\Contracts\Invocation\DirectiveInvocation;
17
use Railt\SDL\Compiler\System\System;
18
use Railt\SDL\Exception\TypeConflictException;
19
20
/**
21
 * Class DocumentSystem
22
 */
23
class DocumentSystem extends System
24
{
25
    /**
26
     * @param Definition|\Railt\Reflection\Document $document
27
     * @param RuleInterface $ast
28
     */
29 119
    public function resolve(Definition $document, RuleInterface $ast): void
30
    {
31 119
        if ($document instanceof Document) {
32 119
            foreach ($ast as $child) {
33 119
                $this->deferred(function () use ($document, $child) {
34 119
                    $definition = $this->process->build($child, $document);
35
36 119
                    if ($definition instanceof TypeDefinition) {
37 119
                        $this->deferred(function () use ($definition, $document) {
38 119
                            if ($document->getDictionary()->has($definition->getName())) {
39
                                throw $this->redeclareException($definition);
40
                            }
41
42 119
                            $document->withDefinition($definition);
43 119
                        });
44
                    }
45
46
47 119
                    if ($definition instanceof DirectiveInvocation) {
48
                        $this->complete(function () use ($definition, $document) {
49
                            $document->withDirective($definition);
50
                        });
51
                    }
52 119
                });
53
            }
54
        }
55 119
    }
56
}
57