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

Class_Const_Missing::find_invocation_warnings()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 3
nop 2
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_Missing extends PersistentListItem implements Invocation_Warner {
10
	public $declaration;
11
12
	function __construct( $declaration ) {
13
		$this->declaration = $declaration;
14
	}
15
16
	function to_csv_array() {
17
		return array(
18
			$this->type(),
19
			$this->declaration->path,
20
			$this->declaration->line,
21
			$this->declaration->display_name(),
22
		);
23
	}
24
25
	public function type() {
26
		return 'class_const_missing';
27
	}
28
29
	public function find_invocation_warnings( $invocation, $warnings ) {
30
		if ( $invocation instanceof Static_Const ) {
31
			if ( $invocation->class_name === $this->declaration->class_name
32
				&& $invocation->const_name === $this->declaration->const_name) {
33
				$warnings->add( new Warning( $this->type(), $invocation->path, $invocation->line, 'Class constant ' . $this->declaration->display_name() . ' is missing', $this->declaration ) );
34
			}
35
		}
36
	}
37
}
38