DefaultMethodComparator   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
c 0
b 0
f 0
lcom 0
cbo 1
dl 0
loc 22
ccs 8
cts 8
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B compare() 0 14 9
1
<?php
2
declare(strict_types=1);
3
4
namespace gossi\codegen\generator\comparator;
5
6
use gossi\codegen\model\PhpMethod;
7
use phootwork\lang\Comparator;
8
9
/**
10
 * Default property comparator
11
 *
12
 * Orders them by static first, then visibility and last by property name
13
 */
14
class DefaultMethodComparator implements Comparator {
15
16
	/**
17
	 * @param PhpMethod $a
18
	 * @param PhpMethod $b
19
	 */
20 3
	public function compare($a, $b) {
21 3
		if ($a->isStatic() !== $isStatic = $b->isStatic()) {
22 2
			return $isStatic ? 1 : -1;
23
		}
24
25 3
		if (($aV = $a->getVisibility()) !== $bV = $b->getVisibility()) {
26 2
			$aV = 'public' === $aV ? 3 : ('protected' === $aV ? 2 : 1);
27 2
			$bV = 'public' === $bV ? 3 : ('protected' === $bV ? 2 : 1);
28
29 2
			return $aV > $bV ? -1 : 1;
30
		}
31
32 2
		return strcasecmp($a->getName(), $b->getName());
33
	}
34
35
}
36