| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace ProxyManager\ProxyGenerator\LazyLoadingValueHolder\MethodGenerator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Laminas\Code\Generator\Exception\InvalidArgumentException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Laminas\Code\Generator\PropertyGenerator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Laminas\Code\Reflection\MethodReflection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use ProxyManager\Generator\MethodGenerator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use ProxyManager\Generator\Util\ProxiedMethodReturnExpression; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use function implode; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use function var_export; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * Method decorator for lazy loading value holder objects | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | class LazyLoadingMethodInterceptor extends MethodGenerator | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * @throws InvalidArgumentException | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 22 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 23 |  |  |     public static function generateMethod( | 
            
                                                        
            
                                    
            
            
                | 24 | 2 |  |         MethodReflection $originalMethod, | 
            
                                                        
            
                                    
            
            
                | 25 |  |  |         PropertyGenerator $initializerProperty, | 
            
                                                        
            
                                    
            
            
                | 26 |  |  |         PropertyGenerator $valueHolderProperty | 
            
                                                        
            
                                    
            
            
                | 27 |  |  |     ) : self { | 
            
                                                        
            
                                    
            
            
                | 28 |  |  |         /** @var self $method */ | 
            
                                                        
            
                                    
            
            
                | 29 |  |  |         $method            = static::fromReflectionWithoutBodyAndDocBlock($originalMethod); | 
            
                                                        
            
                                    
            
            
                | 30 | 2 |  |         $initializerName   = $initializerProperty->getName(); | 
            
                                                        
            
                                    
            
            
                | 31 | 2 |  |         $valueHolderName   = $valueHolderProperty->getName(); | 
            
                                                        
            
                                    
            
            
                | 32 | 2 |  |         $parameters        = $originalMethod->getParameters(); | 
            
                                                        
            
                                    
            
            
                | 33 | 2 |  |         $methodName        = $originalMethod->getName(); | 
            
                                                        
            
                                    
            
            
                | 34 | 2 |  |         $initializerParams = []; | 
            
                                                        
            
                                    
            
            
                | 35 | 2 |  |         $forwardedParams   = []; | 
            
                                                        
            
                                    
            
            
                | 36 | 2 |  |  | 
            
                                                        
            
                                    
            
            
                | 37 |  |  |         foreach ($parameters as $parameter) { | 
            
                                                        
            
                                    
            
            
                | 38 | 2 |  |             $parameterName       = $parameter->getName(); | 
            
                                                        
            
                                    
            
            
                | 39 | 1 |  |             $variadicPrefix      = $parameter->isVariadic() ? '...' : ''; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 40 | 1 |  |             $initializerParams[] = var_export($parameterName, true) . ' => $' . $parameterName; | 
            
                                                        
            
                                    
            
            
                | 41 | 1 |  |             $forwardedParams[]   = $variadicPrefix . '$' . $parameterName; | 
            
                                                        
            
                                    
            
            
                | 42 | 1 |  |         } | 
            
                                                        
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 44 |  |  |         $method->setBody( | 
            
                                                        
            
                                    
            
            
                | 45 | 2 |  |             '$this->' . $initializerName | 
            
                                                        
            
                                    
            
            
                | 46 | 2 |  |             . ' && $this->' . $initializerName | 
            
                                                        
            
                                    
            
            
                | 47 | 2 |  |             . '->__invoke($this->' . $valueHolderName . ', $this, ' . var_export($methodName, true) | 
            
                                                        
            
                                    
            
            
                | 48 | 2 |  |             . ', array(' . implode(', ', $initializerParams) . '), $this->' . $initializerName . ");\n\n" | 
            
                                                        
            
                                    
            
            
                | 49 | 2 |  |             . ProxiedMethodReturnExpression::generate( | 
            
                                                        
            
                                    
            
            
                | 50 | 2 |  |                 '$this->' . $valueHolderName . '->' . $methodName . '(' . implode(', ', $forwardedParams) . ')', | 
            
                                                        
            
                                    
            
            
                | 51 | 2 |  |                 $originalMethod | 
            
                                                        
            
                                    
            
            
                | 52 | 2 |  |             ) | 
            
                                                        
            
                                    
            
            
                | 53 |  |  |         ); | 
            
                                                        
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 55 |  |  |         return $method; | 
            
                                                        
            
                                    
            
            
                | 56 | 2 |  |     } | 
            
                                                        
            
                                    
            
            
                | 57 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 58 |  |  |  | 
            
                        
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.