Completed
Push — fix/15025-map-block-infinite-s... ( 9a8b21...52d6c3 )
by
unknown
63:16 queued 56:01
created

Function_Deprecated   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 72
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 72
loc 72
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 2

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() 7 7 2

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
 * Function Deprecated Checker.
4
 *
5
 * @package automattic/jetpack-analyzer
6
 */
7
8
namespace Automattic\Jetpack\Analyzer\Differences;
9
10
use Automattic\Jetpack\Analyzer\PersistentList\Item as PersistentListItem;
11
use Automattic\Jetpack\Analyzer\Invocations\Function_Call;
12
use Automattic\Jetpack\Analyzer\Warnings\Warning; // TODO - subclasses?
13
14
/**
15
 * Class Function_Deprecated
16
 */
17 View Code Duplication
class Function_Deprecated 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...
18
	/**
19
	 * Old declaration.
20
	 *
21
	 * @var object
22
	 */
23
	public $old_declaration;
24
25
	/**
26
	 * New declaration.
27
	 *
28
	 * @var object
29
	 */
30
	public $new_declaration;
31
32
	/**
33
	 * Function_Moved constructor.
34
	 *
35
	 * @param object $old_declaration Old declaration.
36
	 * @param object $new_declaration New declaration.
37
	 */
38
	public function __construct( $old_declaration, $new_declaration ) {
39
		$this->old_declaration = $old_declaration;
40
		$this->new_declaration = $new_declaration;
41
	}
42
43
	/**
44
	 * Return array of declaration items.
45
	 *
46
	 * @return array
47
	 */
48
	public function to_csv_array() {
49
		return array(
50
			$this->type(),
51
			$this->old_declaration->path,
52
			$this->old_declaration->line,
53
			$this->old_declaration->display_name(),
54
		);
55
	}
56
57
	/**
58
	 * Returns type of issue discovered.
59
	 *
60
	 * @return string 'function_deprecated'
61
	 */
62
	public function type() {
63
		return 'function_deprecated';
64
	}
65
66
	/**
67
	 * Returns the display name of the issue.
68
	 *
69
	 * @return mixed
70
	 */
71
	public function display_name() {
72
		return $this->old_declaration->display_name();
73
	}
74
75
	/**
76
	 * Find warnings.
77
	 *
78
	 * @param object $invocation Invocation.
79
	 * @param object $warnings Warnings.
80
	 */
81
	public function find_invocation_warnings( $invocation, $warnings ) {
82
		if ( $invocation->depends_on( $this->old_declaration ) ) {
83
			$warnings->add(
84
				new Warning( $this->type(), $invocation->path, $invocation->line, 'Function ' . $this->old_declaration->display_name() . ' is deprecated ' . $this->old_declaration->path . ' line ' . $this->old_declaration->line, $this->old_declaration )
85
			);
86
		}
87
	}
88
}
89