@@ -207,8 +207,9 @@ private function generateProxyClass(
207207 $ methods = $ this ->getProxyableMethods ($ reflection );
208208 $ methodsCode = $ this ->generateProxyMethods ($ methods );
209209
210- return "
211- class {$ proxyClassName } extends {$ originalClassName } {
210+ return <<<CODE
211+
212+ class $ proxyClassName extends $ originalClassName {
212213 private object \$wrappedInstance;
213214 private array \$prefixInterceptors;
214215 private array \$suffixInterceptors;
@@ -218,8 +219,9 @@ public function __construct(object \$wrappedInstance, array \$prefixInterceptors
218219 \$this->prefixInterceptors = \$prefixInterceptors;
219220 \$this->suffixInterceptors = \$suffixInterceptors;
220221 }
221- {$ methodsCode }
222- } " ;
222+ $ methodsCode
223+ }
224+ CODE ;
223225 }
224226
225227 /**
@@ -241,15 +243,17 @@ private function generateProxyMethod(ReflectionMethod $method): string
241243 $ methodName = $ method ->getName ();
242244 [$ paramsList , $ argsList ] = $ this ->buildMethodParameters ($ method );
243245 [$ returnType , $ isVoid ] = $ this ->getMethodReturnType ($ method );
246+ $ methodBody = $ this ->generateMethodBody ($ methodName , $ argsList , $ isVoid );
247+
248+ return <<<CODE
244249
245- $ code = "\n public function {$ methodName }( {$ paramsList }) {$ returnType } { \n" ;
246- $ code .= " if (isset( \$this->prefixInterceptors[' {$ methodName }'])) { \n" ;
247- $ code .= " ( \$this->prefixInterceptors[' {$ methodName }'])(); \n" ;
248- $ code .= " } \n" ;
249- $ code .= $ this ->generateMethodBody ($ methodName , $ argsList , $ isVoid );
250- $ code .= " } \n" ;
250+ public function $ methodName( $ paramsList) $ returnType {
251+ if (isset( \$this->prefixInterceptors[' $ methodName'])) {
252+ ( \$this->prefixInterceptors[' $ methodName'])();
253+ }
254+ $ methodBody }
251255
252- return $ code ;
256+ CODE ;
253257 }
254258
255259 private function generateMethodBody (string $ methodName , string $ argsList , bool $ isVoid ): string
@@ -261,26 +265,29 @@ private function generateMethodBody(string $methodName, string $argsList, bool $
261265
262266 private function generateVoidMethodBody (string $ methodName , string $ argsList ): string
263267 {
264- $ code = " \$this->wrappedInstance-> {$ methodName }( {$ argsList }); \n" ;
265- $ code .= " if (isset( \$this->suffixInterceptors[' {$ methodName }'])) { \n" ;
266- $ code .= " \$returnValue = null; \n" ;
267- $ code .= " ( \$this->suffixInterceptors[' {$ methodName }']) " ;
268- $ code .= "(null, null, null, func_get_args(), \$returnValue); \n" ;
269- $ code .= " } \n" ;
270-
271- return $ code ;
268+ return <<<CODE
269+ \$this->wrappedInstance-> $ methodName( $ argsList);
270+
271+ if (isset( \$this->suffixInterceptors[' $ methodName'])) {
272+ \$returnValue = null;
273+ ( \$this->suffixInterceptors[' $ methodName'])(null, null, null, func_get_args(), \$returnValue);
274+ }
275+
276+ CODE ;
272277 }
273278
274279 private function generateNonVoidMethodBody (string $ methodName , string $ argsList ): string
275280 {
276- $ code = " \$returnValue = \$this->wrappedInstance-> {$ methodName }( {$ argsList }); \n" ;
277- $ code .= " if (isset( \$this->suffixInterceptors[' {$ methodName }'])) { \n" ;
278- $ code .= " ( \$this->suffixInterceptors[' {$ methodName }']) " ;
279- $ code .= "(null, null, null, func_get_args(), \$returnValue); \n" ;
280- $ code .= " } \n" ;
281- $ code .= " return \$returnValue; \n" ;
282-
283- return $ code ;
281+ return <<<CODE
282+ \$returnValue = \$this->wrappedInstance-> $ methodName( $ argsList);
283+
284+ if (isset( \$this->suffixInterceptors[' $ methodName'])) {
285+ ( \$this->suffixInterceptors[' $ methodName'])(null, null, null, func_get_args(), \$returnValue);
286+ }
287+
288+ return \$returnValue;
289+
290+ CODE ;
284291 }
285292
286293 // Method parameter handling
0 commit comments