ComparableComparator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 17
ccs 6
cts 6
cp 1
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A compare() 0 8 2
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the Phootwork package.
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 *
7
 * @license MIT License
8
 * @copyright Thomas Gossmann
9
 */
10
namespace phootwork\lang;
11
12
use InvalidArgumentException;
13
14
/**
15
 * Class ComparableComparator
16
 *
17
 * Comparator for objects implementing phootwork\lang\Comparable interface.
18
 *
19
 * @author Thomas Gossmann
20
 */
21
class ComparableComparator implements Comparator {
22
	/**
23
	 * @param mixed $a
24
	 * @param mixed $b
25
	 *
26
	 * @throws InvalidArgumentException If the objects don't implement phootwork\lang\Comparable interface.
27
	 *
28
	 * @return int
29
	 */
30 5
	public function compare(mixed $a, mixed $b): int {
31 5
		if (! $a instanceof Comparable) {
32 1
			throw new InvalidArgumentException(
33 1
				"ComparableComparator can compare only objects implementing phootwork\lang\Comparable interface"
34 1
			);
35
		}
36
37 4
		return $a->compareTo($b);
38
	}
39
}
40