| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Automattic\Jetpack\Analyzer\Invocations; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use PhpParser\NodeVisitorAbstract; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use PhpParser\Node; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | class Visitor extends NodeVisitorAbstract { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | 	private $invocations; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | 	private $file_path; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | 	public function __construct( $file_path, $invocations ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | 		$this->file_path   = $file_path; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | 		$this->invocations = $invocations; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | 	public function enterNode( Node $node ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | 		if ( $node instanceof Node\Expr\New_ ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 			$this->invocations->add( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 				new New_( $this->file_path, $node->getLine(), $this->node_to_class_name( $node->class ) ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 			); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 		} elseif ( $node instanceof Node\Expr\StaticCall ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 			// TODO - args | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 			$this->invocations->add( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 				new Static_Call( $this->file_path, $node->getLine(), $this->node_to_class_name( $node->class ), $node->name->name ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 			); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 		} elseif ( $node instanceof Node\Expr\StaticPropertyFetch ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 			$this->invocations->add( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 				new Static_Property( $this->file_path, $node->getLine(), $this->node_to_class_name( $node->class ), $node->name->name ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 			); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 		} elseif ( $node instanceof Node\Expr\FuncCall ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 			// TODO - args | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 			if ( $node->name instanceof Node\Expr\Variable ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 				$function_name = '$' . $node->name->name; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 				$function_name = implode( '\\', $node->name->parts ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 			$this->invocations->add( new Function_Call( $this->file_path, $node->getLine(), $function_name ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 			// print_r( $node ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 	public function leaveNode( Node $node ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 48 |  |  | 	private function node_to_class_name( $node ) { | 
            
                                                        
            
                                    
            
            
                | 49 |  |  | 		if ( $node instanceof Node\Expr\Variable | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 50 |  |  | 			|| $node instanceof Node\Stmt\Class_ ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 51 |  |  | 			$class_name = $node->name; | 
            
                                                        
            
                                    
            
            
                | 52 |  |  | 		} elseif ( $node instanceof Node\Name ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 53 |  |  | 			$class_name = '\\' . implode( '\\', $node->parts ); | 
            
                                                        
            
                                    
            
            
                | 54 |  |  | 		} elseif ( $node instanceof Node\Expr\PropertyFetch ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 55 |  |  | 			$class_name = '$' . $node->var->name . '->' . $node->name->name; | 
            
                                                        
            
                                    
            
            
                | 56 |  |  | 		} else { | 
            
                                                        
            
                                    
            
            
                | 57 |  |  | 			$class_name = $node->toCodeString(); | 
            
                                                        
            
                                    
            
            
                | 58 |  |  | 		} | 
            
                                                        
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 60 |  |  | 		return $class_name; | 
            
                                                        
            
                                    
            
            
                | 61 |  |  | 	} | 
            
                                                        
            
                                    
            
            
                | 62 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 63 |  |  |  | 
            
                        
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.