DefaultMethodComparator::compare()   B
last analyzed

Complexity

Conditions 9
Paths 35

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 9

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 8.0555
c 0
b 0
f 0
cc 9
nc 35
nop 2
crap 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