SimpleCollator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 8
c 2
b 0
f 0
dl 0
loc 25
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 3
A create() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Budgegeria\IntlSort\ComparatorFactory;
6
7
use Budgegeria\IntlSort\Collator\Collator;
8
use Budgegeria\IntlSort\Comparator\CollatorConstructor;
9
use Budgegeria\IntlSort\Comparator\Comparable;
10
use Budgegeria\IntlSort\Exception\IntlSortException;
11
12
use function class_exists;
13
use function class_implements;
14
use function in_array;
15
16
class SimpleCollator implements Factory
17
{
18
    /** @var class-string<CollatorConstructor> $classname */
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<CollatorConstructor> at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<CollatorConstructor>.
Loading history...
19
    private $classname;
20
21
    /** @psalm-param class-string<CollatorConstructor> $classname */
22 3
    public function __construct(string $classname)
23
    {
24 3
        if (! class_exists($classname)) {
25 1
            throw IntlSortException::classDoesNotExist($classname);
26
        }
27
28
        /** @var array<string> $interfaces */
29 2
        $interfaces = class_implements($classname);
30
31 2
        if (! in_array(CollatorConstructor::class, $interfaces, true)) {
32 1
            throw IntlSortException::doesNotImplementComparable($classname);
33
        }
34
35 1
        $this->classname = $classname;
36
    }
37
38 1
    public function create(Collator $collator): Comparable
39
    {
40 1
        return new $this->classname($collator);
41
    }
42
}
43