Completed
Push — try/code-signature-diff ( 9050e5...a2c3d7 )
by
unknown
268:47 queued 260:32
created

Class_Method_Missing   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
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() 0 3 1
A to_csv_array() 0 8 1
A type() 0 3 1
A display_name() 0 3 1
A find_invocation_warnings() 0 12 5
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
class Class_Method_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 'method_missing';
27
	}
28
29
	public function display_name() {
30
		return $this->declaration->display_name();
31
	}
32
33
	public function find_invocation_warnings( $invocation, $warnings ) {
34
		if ( $invocation instanceof Static_Call ) {
35
			// check if it's instantiating this missing class
36
			// echo "Checking " . $invocation->class_name . " matches " . $this->declaration->class_name . "\n";
37
			// echo "... and " . $invocation->method_name . " matches " . $this->declaration->name . ", and invocation is static\n";
38
			if ( $invocation->class_name === $this->declaration->class_name
39
				&& $invocation->method_name === $this->declaration->name
40
				&& $this->declaration->static ) {
41
				$warnings->add( new Warning( $invocation->path, $invocation->line, "Class static method" . $this->declaration->display_name() . " is missing") );
42
			}
43
		}
44
	}
45
}