1 | <?php |
||
17 | class Compiler |
||
18 | { |
||
19 | /** |
||
20 | * @var ClassDefinition[] |
||
21 | */ |
||
22 | protected $classes = []; |
||
23 | |||
24 | /** |
||
25 | * @var TraitDefinition[] |
||
26 | */ |
||
27 | protected $traits = []; |
||
28 | |||
29 | /** |
||
30 | * @var FunctionDefinition[] |
||
31 | */ |
||
32 | protected $functions = []; |
||
33 | |||
34 | /** |
||
35 | * @param ClassDefinition $class |
||
36 | */ |
||
37 | 52 | public function addClass(ClassDefinition $class) |
|
41 | |||
42 | /** |
||
43 | * @param TraitDefinition $class |
||
44 | */ |
||
45 | 1 | public function addTrait(TraitDefinition $class) |
|
49 | |||
50 | /** |
||
51 | * @param FunctionDefinition $function |
||
52 | */ |
||
53 | 6 | public function addFunction(FunctionDefinition $function) |
|
57 | |||
58 | /** |
||
59 | * @param Context $context |
||
60 | */ |
||
61 | 52 | public function compile(Context $context) |
|
|
|||
62 | { |
||
63 | 52 | $context->scopePointer = null; |
|
64 | |||
65 | /** |
||
66 | * @todo Implement class map... |
||
67 | */ |
||
68 | 52 | foreach ($this->classes as $class) { |
|
69 | 52 | $extends = $class->getExtendsClass(); |
|
70 | 52 | if ($extends) { |
|
71 | 2 | if (isset($this->classes[$extends])) { |
|
72 | $class->setExtendsClassDefinition($this->classes[$extends]); |
||
73 | } else { |
||
74 | 2 | if (class_exists($extends, true)) { |
|
75 | 2 | $class->setExtendsClassDefinition( |
|
76 | 2 | new RuntimeClassDefinition( |
|
77 | 2 | new ReflectionClass( |
|
78 | $extends |
||
79 | 2 | ) |
|
80 | 2 | ) |
|
81 | 2 | ); |
|
82 | 2 | } |
|
83 | } |
||
84 | 2 | } |
|
85 | 52 | } |
|
86 | |||
87 | 52 | foreach ($this->functions as $function) { |
|
88 | /** |
||
89 | * @todo Configuration |
||
90 | * |
||
91 | * Ignore functions compiling from vendor |
||
92 | */ |
||
93 | 6 | $checkVendor = strpos($function->getFilepath(), './vendor'); |
|
94 | 6 | if ($checkVendor !== false && $checkVendor < 3) { |
|
95 | continue; |
||
96 | } |
||
97 | |||
98 | 6 | $function->compile($context); |
|
99 | 52 | } |
|
100 | |||
101 | 52 | foreach ($this->traits as $trait) { |
|
102 | /** |
||
103 | * @todo Configuration |
||
104 | * |
||
105 | * Ignore traits compiling from vendor |
||
106 | */ |
||
107 | 1 | $checkVendor = strpos($trait->getFilepath(), './vendor'); |
|
108 | 1 | if ($checkVendor !== false && $checkVendor < 3) { |
|
109 | continue; |
||
110 | } |
||
111 | |||
112 | 1 | $trait->compile($context); |
|
113 | 52 | } |
|
114 | |||
115 | 52 | foreach ($this->classes as $class) { |
|
116 | /** |
||
117 | * @todo Configuration |
||
118 | * |
||
119 | * Ignore Classes compiling from vendor |
||
120 | */ |
||
121 | 52 | $checkVendor = strpos($class->getFilepath(), './vendor'); |
|
122 | 52 | if ($checkVendor !== false && $checkVendor < 3) { |
|
123 | continue; |
||
124 | } |
||
125 | |||
126 | 52 | $class->compile($context); |
|
127 | 52 | } |
|
128 | 52 | } |
|
129 | |||
130 | /** |
||
131 | * Try to find function with $namespace from pre-compiled function(s) |
||
132 | * |
||
133 | * @param string $name |
||
134 | * @param string|null $namespace |
||
135 | * @return bool|FunctionDefinition |
||
136 | */ |
||
137 | 13 | public function getFunctionNS($name, $namespace = null) |
|
147 | |||
148 | /** |
||
149 | * @param string $name |
||
150 | * @return ClassDefinition|null |
||
151 | */ |
||
152 | 6 | public function getClass($name) |
|
153 | { |
||
154 | 6 | if (isset($this->classes[$name])) { |
|
155 | return $this->classes[$name]; |
||
156 | } |
||
157 | |||
158 | 6 | return null; |
|
159 | } |
||
160 | |||
161 | /** |
||
162 | * @param string $name |
||
163 | * @return TraitDefinition|null |
||
164 | */ |
||
165 | public function getTrait($name) |
||
173 | |||
174 | /** |
||
175 | * Try to find function from pre-compiled function(s) |
||
176 | * |
||
177 | * @param string $name |
||
178 | * @return bool|FunctionDefinition |
||
179 | */ |
||
180 | 1 | public function getFunction($name) |
|
190 | |||
191 | /** |
||
192 | * @return FunctionDefinition[] |
||
193 | */ |
||
194 | public function getFunctions() |
||
198 | |||
199 | /** |
||
200 | * @return ClassDefinition[] |
||
201 | */ |
||
202 | public function getClasses() |
||
206 | } |
||
207 |
A high number of execution paths generally suggests many nested conditional statements and make the code less readible. This can usually be fixed by splitting the method into several smaller methods.
You can also find more information in the “Code” section of your repository.