Completed
Push — master ( 55b21a...aec22b )
by Thomas
06:20
created

DefaultMethodComparator::compare()   B

Complexity

Conditions 9
Paths 35

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 9

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 7.756
cc 9
eloc 8
nc 35
nop 2
crap 9
1
<?php
2
namespace gossi\codegen\generator\comparator;
3
4
use gossi\codegen\model\PhpMethod;
5
use phootwork\lang\Comparator;
6
7
/**
8
 * Default property comparator
9
 *
10
 * Orders them by static first, then visibility and last by property name
11
 */
12
class DefaultMethodComparator implements Comparator {
13
14
	/**
15
	 * @param PhpMethod $a
16
	 * @param PhpMethod $b
17
	 */
18 3
	public function compare($a, $b) {
19 3
		if ($a->isStatic() !== $isStatic = $b->isStatic()) {
20 2
			return $isStatic ? 1 : -1;
21
		}
22
		
23 3
		if (($aV = $a->getVisibility()) !== $bV = $b->getVisibility()) {
24 2
			$aV = 'public' === $aV ? 3 : ('protected' === $aV ? 2 : 1);
25 2
			$bV = 'public' === $bV ? 3 : ('protected' === $bV ? 2 : 1);
26
		
27 2
			return $aV > $bV ? -1 : 1;
28
		}
29
		
30 2
		return strcasecmp($a->getName(), $b->getName());
31
	}
32
33
}