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)); |
|
|
|
|
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
|
|
|
|
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.