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

DefaultPropertyComparator   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 0
cbo 1
dl 0
loc 18
ccs 6
cts 6
cp 1
rs 10

1 Method

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