DefaultPropertyComparator   A
last analyzed

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