Completed
Push — renovate/glob-7.x ( 697d78...f7fc07 )
by
unknown
18:21 queued 12:01
created

Visitor::enterNode()   C

Complexity

Conditions 13
Paths 10

Size

Total Lines 47

Duplication

Lines 8
Ratio 17.02 %

Importance

Changes 0
Metric Value
cc 13
nc 10
nop 1
dl 8
loc 47
rs 6.6166
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Automattic\Jetpack\Analyzer\Declarations;
4
5
use PhpParser\NodeVisitorAbstract;
6
use PhpParser\Node;
7
use Automattic\Jetpack\Analyzer\Utils;
8
9
class Visitor extends NodeVisitorAbstract {
10
	private $current_class;
11
	private $declarations;
12
	private $current_relative_path;
13
14
	public function __construct( $current_relative_path, $declarations ) {
15
		$this->current_relative_path = $current_relative_path;
16
		$this->declarations          = $declarations;
17
		$this->current_class         = null;
18
	}
19
20
	public function enterNode( Node $node ) {
21
22
		if ( $node instanceof Node\Stmt\Class_ ) {
0 ignored issues
show
Bug introduced by
The class PhpParser\Node\Stmt\Class_ does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to 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 require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
23
			$namespaced_name     = '\\' . implode( '\\', $node->namespacedName->parts );
24
			$this->current_class = $namespaced_name;
25
26
			$this->declarations->add( new Class_( $this->current_relative_path, $node->getLine(), $namespaced_name ) );
27
			return;
28
		}
29
30
		if ( $node instanceof Node\Stmt\Property && $node->isPublic() ) {
0 ignored issues
show
Bug introduced by
The class PhpParser\Node\Stmt\Property does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to 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 require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
31
			$this->declarations->add( new Class_Property( $this->current_relative_path, $node->getLine(), $this->current_class, $node->props[0]->name->name, $node->isStatic() ) );
32
			return;
33
		}
34
35
		if ( $node instanceof Node\Stmt\ClassConst && $node->isPublic() ) {
0 ignored issues
show
Bug introduced by
The class PhpParser\Node\Stmt\ClassConst does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to 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 require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
36
			foreach( $node->consts as $const ) {
37
				$this->declarations->add( new Class_Const( $this->current_relative_path, $node->getLine(), $this->current_class, $const->name->name ) );
38
			}
39
			return;
40
		}
41
42
		if ( $node instanceof Node\Stmt\ClassMethod && $node->isPublic() ) {
0 ignored issues
show
Bug introduced by
The class PhpParser\Node\Stmt\ClassMethod does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to 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 require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
43
			// ClassMethods are also listed inside interfaces, which means current_class is null
44
			// so we ignore these
45
			if ( ! $this->current_class ) {
46
				return;
47
			}
48
			$method = new Class_Method( $this->current_relative_path, $node->getLine(), $this->current_class, $node->name->name, $node->isStatic() );
49 View Code Duplication
			foreach ( $node->getParams() as $param ) {
50
				$param_default = Utils::get_param_default_as_string( $param->default, $this->current_class );
51
				$method->add_param( $param->var->name, $param_default, $param->type, $param->byRef, $param->variadic );
52
			}
53
			$this->declarations->add( $method );
54
			return;
55
		}
56
57
		if ( $node instanceof Node\Stmt\Function_ ) {
0 ignored issues
show
Bug introduced by
The class PhpParser\Node\Stmt\Function_ does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to 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 require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
58
			$function = new Function_( $this->current_relative_path, $node->getLine(), $node->name->name );
59 View Code Duplication
			foreach ( $node->getParams() as $param ) {
60
				$param_default = Utils::get_param_default_as_string( $param->default, $this->current_class );
61
				$function->add_param( $param->var->name, $param_default, $param->type, $param->byRef, $param->variadic );
62
			}
63
			$this->declarations->add( $function );
64
			return;
65
		}
66
	}
67
68
	public function leaveNode( Node $node ) {
69
		if ( $node instanceof Node\Stmt\Class_ ) {
0 ignored issues
show
Bug introduced by
The class PhpParser\Node\Stmt\Class_ does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to 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 require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
70
			$this->current_class = null;
71
		}
72
	}
73
}
74