| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Automattic\Jetpack\Analyzer\Declarations; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use PhpParser\NodeVisitorAbstract; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use PhpParser\Node; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | class Visitor extends NodeVisitorAbstract { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | 	private $current_class; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | 	private $declarations; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | 	private $current_relative_path; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | 	public function __construct( $current_relative_path, $declarations ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | 		$this->current_relative_path = $current_relative_path; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | 		$this->declarations = $declarations; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | 		$this->current_class = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 	public function enterNode( Node $node ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 		if ( $node instanceof Node\Stmt\Class_ ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 			$namespaced_name = '\\' . implode( '\\', $node->namespacedName->parts ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 			$this->current_class = $namespaced_name; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 			$this->declarations->add( new Class_( $this->current_relative_path, $node->getLine(), $namespaced_name ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 			return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 		if ( $node instanceof Node\Stmt\Property && $node->isPublic() ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 			$this->declarations->add( new Class_Property( $this->current_relative_path, $node->getLine(), $this->current_class, $node->props[0]->name->name, $node->isStatic() ) ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 			return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 		if ( $node instanceof Node\Stmt\ClassMethod && $node->isPublic() ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 			// ClassMethods are also listed inside interfaces, which means current_class is null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 			// so we ignore these | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 			if ( ! $this->current_class ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 				return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 			$method = new Class_Method( $this->current_relative_path, $node->getLine(), $this->current_class, $node->name->name, $node->isStatic() ); | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 41 |  | View Code Duplication | 			foreach ( $node->getParams() as $param ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 				$method->add_param( $param->var->name, $param->default, $param->type, $param->byRef, $param->variadic ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 			$this->declarations->add( $method ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 			return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 		if ( $node instanceof Node\Stmt\Function_ ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 			$function = new Function_( $this->current_relative_path, $node->getLine(), $node->name->name ); | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 50 |  | View Code Duplication | 			foreach ( $node->getParams() as $param ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 				$function->add_param( $param->var->name, $param->default, $param->type, $param->byRef, $param->variadic ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 			$this->declarations->add( $function  ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 			return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 58 |  |  | 	public function leaveNode( Node $node ) { | 
            
                                                        
            
                                    
            
            
                | 59 |  |  | 		if ( $node instanceof Node\Stmt\Class_ ) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 60 |  |  | 			$this->current_class = null; | 
            
                                                        
            
                                    
            
            
                | 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.