| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | namespace TheCodingMachine\PHPStan\Rules\TypeHints; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use PHPStan\Analyser\Scope; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use PHPStan\Broker\Broker; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use PHPStan\Reflection\ParametersAcceptor; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use PHPStan\Reflection\ParametersAcceptorSelector; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use PHPStan\Reflection\ParametersAcceptorWithPhpDocs; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use PHPStan\Reflection\Php\PhpParameterReflection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Roave\BetterReflection\Reflection\ReflectionFunction; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Roave\BetterReflection\Reflection\ReflectionFunctionAbstract; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Roave\BetterReflection\Reflection\ReflectionMethod; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Roave\BetterReflection\Reflection\ReflectionParameter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use PhpParser\Node; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | class MissingTypeHintInFunctionRule extends AbstractMissingTypeHintRule | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     public function getNodeType(): string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         return Node\Stmt\Function_::class; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     public function isReturnIgnored(Node $node): bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     protected function getReflection(Node\FunctionLike $function, Scope $scope, Broker $broker) : ParametersAcceptorWithPhpDocs | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $functionName = $function->name->name; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         if (isset($function->namespacedName)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |             $functionName = (string) $function->namespacedName; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $functionNameName = new Node\Name($functionName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         if (!$broker->hasCustomFunction($functionNameName, null)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             throw new \RuntimeException("Cannot find function '$functionName'"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $functionReflection = $broker->getCustomFunction($functionNameName, null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         /** @var \PHPStan\Reflection\ParametersAcceptorWithPhpDocs $parametersAcceptor */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $parametersAcceptor = ParametersAcceptorSelector::selectSingle($functionReflection->getVariants()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         return $parametersAcceptor; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 46 |  |  |     protected function shouldSkip(Node\FunctionLike $function, Scope $scope): bool | 
            
                                                        
            
                                    
            
            
                | 47 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 48 |  |  |         return false; | 
            
                                                        
            
                                    
            
            
                | 49 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 50 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 51 |  |  |  |