Completed
Push — add/analyzer-class-const ( 1ca9f2 )
by
unknown
170:16 queued 161:57
created

Class_Const_Moved::to_csv_array()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 8
rs 10
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_Const;
7
use Automattic\Jetpack\Analyzer\Warnings\Warning; // TODO - subclasses?
8
9
class Class_Const_Moved extends PersistentListItem implements Invocation_Warner {
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_Const ) {
33
			// check if it's using this missing property
34
			if ( $invocation->class_name === $this->old_declaration->class_name
35
				&& $invocation->const_name === $this->old_declaration->const_name ) {
36
				$warnings->add( new Warning( $this->type(), $invocation->path, $invocation->line, 'Class const ' . $this->old_declaration->display_name() . ' was moved from ' . $this->old_declaration->path . ' to ' . $this->new_declaration->path, $this->old_declaration ) );
37
			}
38
		}
39
	}
40
}
41