DefaultPropertyComparator::compare()   B
last analyzed

Complexity

Conditions 7
Paths 33

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 7

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 8.8333
c 0
b 0
f 0
cc 7
nc 33
nop 2
crap 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