Completed
Push — try/code-signature-diff ( 313026...01fa4f )
by
unknown
08:13
created

Class_Method_Moved   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 37
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 37
loc 37
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 3

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A to_csv_array() 8 8 1
A type() 3 3 1
A display_name() 3 3 1
A find_invocation_warnings() 10 10 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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_Call;
7
use Automattic\Jetpack\Analyzer\Warnings\Warning; // TODO - subclasses?
8
9 View Code Duplication
class Class_Method_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 'method_missing';
29
	}
30
31
	public function display_name() {
32
		return $this->declaration->display_name();
0 ignored issues
show
Bug introduced by
The property declaration does not seem to exist. Did you mean old_declaration?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
33
	}
34
35
	public function find_invocation_warnings( $invocation, $warnings ) {
36
		if ( $invocation instanceof Static_Call ) {
37
			// check if it's instantiating this missing class
38
			if ( $invocation->class_name === $this->old_declaration->class_name
39
				&& $invocation->method_name === $this->old_declaration->method_name
40
				&& $this->old_declaration->static ) {
41
				$warnings->add( new Warning( $invocation->path, $invocation->line, 'Class static method ' . $this->old_declaration->display_name() . ' was moved from ' . $this->old_declaration->path . ' to ' . $this->new_declaration->path ) );
42
			}
43
		}
44
	}
45
}
46