1 | <?php |
||
25 | class Exporter |
||
26 | { |
||
27 | /** |
||
28 | * Get PHP code string from a closure of function as string |
||
29 | * |
||
30 | * @param array<string,array|string|integer> $context current compile context |
||
31 | * @param object $closure Closure object |
||
32 | * |
||
33 | * @return string |
||
34 | * |
||
35 | * @expect 'function($a) {return;}' when input array('flags' => array('standalone' => 0)), function ($a) {return;} |
||
36 | * @expect 'function($a) {return;}' when input array('flags' => array('standalone' => 0)), function ($a) {return;} |
||
37 | */ |
||
38 | 80 | protected static function closure($context, $closure) |
|
49 | |||
50 | /** |
||
51 | * Export required custom helper functions |
||
52 | * |
||
53 | * @param array<string,array|string|integer> $context current compile context |
||
54 | * |
||
55 | * @return string |
||
56 | */ |
||
57 | 717 | public static function helpers($context) |
|
73 | |||
74 | /** |
||
75 | * Replace SafeString class with alias class name |
||
76 | * |
||
77 | * @param array<string,array|string|integer> $context current compile context |
||
78 | * @param string $str the PHP code to be replaced |
||
79 | * |
||
80 | * @return string |
||
81 | */ |
||
82 | 580 | protected static function replaceSafeString($context, $str) |
|
86 | |||
87 | /** |
||
88 | * Get methods from ReflectionClass |
||
89 | * |
||
90 | * @param array<string,array|string|integer> $context current compile context |
||
91 | * @param \ReflectionClass $class instance of the ReflectionClass |
||
92 | * |
||
93 | * @return array |
||
94 | */ |
||
95 | 513 | public static function getClassMethods($context, $class) |
|
106 | |||
107 | /** |
||
108 | * Get statics code from ReflectionClass |
||
109 | * |
||
110 | * @param \ReflectionClass $class instance of the ReflectionClass |
||
111 | * |
||
112 | * @return string |
||
113 | */ |
||
114 | 336 | public static function getClassStatics($class) |
|
124 | |||
125 | |||
126 | |||
127 | |||
128 | |||
129 | /** |
||
130 | * Get metadata from ReflectionObject |
||
131 | * |
||
132 | * @param object $refobj instance of the ReflectionObject |
||
133 | * |
||
134 | * @return array |
||
135 | */ |
||
136 | 580 | public static function getMeta($refobj) |
|
151 | |||
152 | /** |
||
153 | * Export SafeString class as string |
||
154 | * |
||
155 | * @param array<string,array|string|integer> $context current compile context |
||
156 | * |
||
157 | * @return string |
||
158 | */ |
||
159 | 336 | public static function safestring($context) |
|
167 | |||
168 | /** |
||
169 | * Export StringObject class as string |
||
170 | * |
||
171 | * @param array<string,array|string|integer> $context current compile context |
||
172 | * |
||
173 | * @return string |
||
174 | */ |
||
175 | 380 | public static function stringobject($context) |
|
176 | { |
||
177 | 380 | if ($context['flags']['standalone'] == 0) { |
|
178 | 380 | return 'use \\LightnCandy\\StringObject as StringObject;'; |
|
179 | } |
||
180 | 373 | $class = new \ReflectionClass('\\LightnCandy\\StringObject'); |
|
181 | 373 | $meta = static::getMeta($class); |
|
182 | 373 | return "if (!class_exists(\"StringObject\")) {\n{$meta['code']}}\n"; |
|
183 | } |
||
184 | |||
185 | /** |
||
186 | * Export required standalone Runtime methods |
||
187 | * |
||
188 | * @param array<string,array|string|integer> $context current compile context |
||
189 | * |
||
190 | * @return string |
||
191 | */ |
||
192 | 513 | public static function runtime($context) |
|
221 | |||
222 | /** |
||
223 | * Export Runtime constants |
||
224 | * |
||
225 | * @param array<string,array|string|integer> $context current compile context |
||
226 | * |
||
227 | * @return string |
||
228 | */ |
||
229 | 717 | public static function constants($context) |
|
244 | |||
245 | /** |
||
246 | * Scan for required standalone functions |
||
247 | * |
||
248 | * @param array<string,array|string|integer> $context current compile context |
||
249 | * @param string $code patched PHP code string of the method |
||
250 | * @param string $ocode original PHP code string of the method |
||
251 | * |
||
252 | * @return array<string|array> list of converted code and children array |
||
253 | */ |
||
254 | 513 | protected static function scanDependency($context, $code, $ocode) |
|
275 | } |
||
276 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.