Test Failed
Push — master ( 6bac61...6350a6 )
by Kirill
03:02
created

Builder::run()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 6
nop 2
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
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\Backend;
11
12
use Psr\Log\LoggerAwareInterface;
13
use Psr\Log\LoggerAwareTrait;
14
use Railt\Io\Readable;
15
use Railt\Reflection\Contracts\Document as DocumentInterface;
16
use Railt\Reflection\Contracts\Reflection;
17
use Railt\Reflection\Document;
18
use Railt\SDL\Backend\Context\GlobalContext;
19
20
/**
21
 * Class Builder
22
 */
23
class Builder implements LoggerAwareInterface
24
{
25
    use LoggerAwareTrait;
26
27
    /**
28
     * @var GlobalContext
29
     */
30
    private $context;
31
32
    /**
33
     * @var Reflection
34
     */
35
    private $root;
36
37
    /**
38
     * Process constructor.
39
     * @param Reflection $root
40
     */
41
    public function __construct(Reflection $root)
42
    {
43
        $this->root = $root;
44
        $this->context = new GlobalContext();
45
        $this->exportTypes($root);
46
    }
47
48
    /**
49
     * @param Reflection $reflection
50
     */
51
    private function exportTypes(Reflection $reflection): void
52
    {
53
        foreach ($reflection->getDocuments() as $document) {
54
            $context = $this->context->fromDocument($document);
55
56
            foreach ($document->getDefinitions() as $type) {
57
                $context->create($type);
58
            }
59
        }
60
    }
61
62
    /**
63
     * @param Readable $file
64
     * @param iterable $opcodes
65
     * @return Document|DocumentInterface
66
     */
67
    public function run(Readable $file, iterable $opcodes): Document
68
    {
69
        $context = $this->context->fromDocument(new Document($this->root, $file));
0 ignored issues
show
Compatibility introduced by
$this->root of type object<Railt\Reflection\Contracts\Reflection> is not a sub-type of object<Railt\Reflection\Reflection>. It seems like you assume a concrete implementation of the interface Railt\Reflection\Contracts\Reflection to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
70
71
        if ($this->logger) {
72
            $this->logger->debug(\sprintf('Create %s', $context->getDocument()));
73
        }
74
75
        foreach ($opcodes as $code) {
76
            if ($this->logger) {
77
                $this->logger->debug(\sprintf('> %s', $code));
78
            }
79
        }
80
81
        return $context->getDocument();
82
    }
83
}
84