Completed
Push — feature/back-compat-7.5 ( 9186e7 )
by
unknown
23:17 queued 14:42
created

Class_Property_Moved::find_invocation_warnings()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
cc 5
nc 3
nop 2
dl 10
loc 10
rs 9.6111
c 0
b 0
f 0
1
<?php
2
3
namespace Automattic\Jetpack\Analyzer\Differences;
4
5
use Automattic\Jetpack\Analyzer\PersistentList\Item as PersistentListItem;
6
use Automattic\Jetpack\Analyzer\Invocations\Static_Property;
7
use Automattic\Jetpack\Analyzer\Warnings\Warning; // TODO - subclasses?
8
9 View Code Duplication
class Class_Property_Moved extends PersistentListItem implements Invocation_Warner {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
	public $old_declaration;
11
	public $new_declaration;
12
13
	function __construct( $old_declaration, $new_declaration ) {
14
		$this->old_declaration = $old_declaration;
15
		$this->new_declaration = $new_declaration;
16
	}
17
18
	function to_csv_array() {
19
		return array(
20
			$this->type(),
21
			$this->old_declaration->path,
22
			$this->old_declaration->line,
23
			$this->old_declaration->display_name(),
24
		);
25
	}
26
27
	public function type() {
28
		return 'property_moved';
29
	}
30
31
	public function find_invocation_warnings( $invocation, $warnings ) {
32
		if ( $invocation instanceof Static_Property ) {
33
			// check if it's using this missing property
34
			if ( $invocation->class_name === $this->old_declaration->class_name
35
				&& $invocation->prop_name === $this->old_declaration->prop_name
36
				&& $this->old_declaration->static ) {
37
				$warnings->add( new Warning( $this->type(), $invocation->path, $invocation->line, 'Class static property ' . $this->old_declaration->display_name() . ' was moved from ' . $this->old_declaration->path . ' to ' . $this->new_declaration->path ) );
38
			}
39
		}
40
	}
41
}
42