1 | <?php |
||
26 | class FunctionProxy extends AbstractProxy |
||
27 | { |
||
28 | |||
29 | /** |
||
30 | * List of advices for functions |
||
31 | * |
||
32 | * @var array |
||
33 | */ |
||
34 | protected static $functionAdvices = []; |
||
35 | |||
36 | /** |
||
37 | * Name for the current namespace |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | protected $namespace = ''; |
||
42 | |||
43 | /** |
||
44 | * Source code for functions |
||
45 | * |
||
46 | * @var array Name of the function => source code for it |
||
47 | */ |
||
48 | protected $functionsCode = []; |
||
49 | |||
50 | /** |
||
51 | * Constructs functions stub class from namespace Reflection |
||
52 | * |
||
53 | * @param ReflectionFileNamespace $namespace Reflection of namespace |
||
54 | * @param array $advices List of function advices |
||
55 | * |
||
56 | * @throws \InvalidArgumentException for invalid classes |
||
57 | */ |
||
58 | public function __construct(ReflectionFileNamespace $namespace, array $advices = []) |
||
72 | |||
73 | /** |
||
74 | * Returns a joinpoint for specific function in the namespace |
||
75 | * |
||
76 | * @param string $joinPointName Special joinpoint name |
||
77 | * @param string $namespace Name of the namespace |
||
78 | * |
||
79 | * @return FunctionInvocation |
||
80 | */ |
||
81 | public static function getJoinPoint($joinPointName, $namespace) |
||
99 | |||
100 | /** |
||
101 | * Inject advices for given trait |
||
102 | * |
||
103 | * NB This method will be used as a callback during source code evaluation to inject joinpoints |
||
104 | * |
||
105 | * @param string $namespace Aop child proxy class |
||
106 | * @param array|Advice[] $advices List of advices to inject into class |
||
107 | * |
||
108 | * @return void |
||
109 | */ |
||
110 | public static function injectJoinPoints($namespace, array $advices = []) |
||
114 | |||
115 | /** |
||
116 | * Override function with new body |
||
117 | * |
||
118 | * @param ReflectionFunction $function Function reflection |
||
119 | * @param string $body New body for function |
||
120 | * |
||
121 | * @return $this |
||
122 | */ |
||
123 | public function override(ReflectionFunction $function, $body) |
||
129 | |||
130 | /** |
||
131 | * {@inheritDoc} |
||
132 | */ |
||
133 | public function __toString() |
||
134 | { |
||
135 | $functionsCode = ( |
||
136 | "<?php\n" . // Start of file header |
||
137 | $this->namespace->getDocComment() . "\n" . // Doc-comment for file |
||
138 | 'namespace ' . // 'namespace' keyword |
||
139 | $this->namespace->getName() . // Name |
||
140 | ";\n" . // End of namespace name |
||
141 | join("\n", $this->functionsCode) // Function definitions |
||
142 | ); |
||
143 | |||
144 | return $functionsCode |
||
145 | // Inject advices on call |
||
146 | . PHP_EOL |
||
147 | . '\\' . __CLASS__ . "::injectJoinPoints('" |
||
148 | . $this->namespace->getName() . "'," |
||
149 | . var_export($this->advices, true) . ");"; |
||
150 | } |
||
151 | |||
152 | /** |
||
153 | * Creates a function code from Reflection |
||
154 | * |
||
155 | * @param ReflectionFunction $function Reflection for function |
||
156 | * @param string $body Body of function |
||
157 | * |
||
158 | * @return string |
||
159 | */ |
||
160 | protected function getOverriddenFunction(ReflectionFunction $function, $body) |
||
161 | { |
||
162 | static $inMemoryCache = []; |
||
163 | |||
164 | $functionName = $function->getName(); |
||
165 | if (isset($inMemoryCache[$functionName])) { |
||
166 | return $inMemoryCache[$functionName]; |
||
167 | } |
||
168 | |||
169 | $code = ( |
||
170 | preg_replace('/ {4}|\t/', '', $function->getDocComment()) . "\n" . // Original doc-comment |
||
171 | 'function ' . // 'function' keyword |
||
172 | ($function->returnsReference() ? '&' : '') . // By reference symbol |
||
173 | $functionName . // Function name |
||
174 | '(' . // Start of parameters |
||
175 | join(', ', $this->getParameters($function->getParameters())) . // List of parameters |
||
176 | ")\n" . // End of parameters |
||
177 | "{\n" . // Start of function body |
||
178 | $this->indent($body) . "\n" . // Body of function |
||
179 | "}\n" // End of function body |
||
180 | ); |
||
181 | |||
182 | $inMemoryCache[$functionName] = $code; |
||
183 | |||
184 | return $code; |
||
185 | } |
||
186 | |||
187 | /** |
||
188 | * Creates definition for trait method body |
||
189 | * |
||
190 | * @param ReflectionFunction $function Method reflection |
||
191 | * |
||
192 | * @return string new method body |
||
193 | */ |
||
194 | protected function getJoinpointInvocationBody(ReflectionFunction $function) |
||
235 | |||
236 | } |
||
237 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..