AbstractSorter   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 92.31%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 32
ccs 12
cts 13
cp 0.9231
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setSortOrder() 0 4 1
A setStrategy() 0 4 1
A __construct() 0 4 2
A sort() 0 7 2
1
<?php
2
3
namespace Ninja\Sorter;
4
5
use Ninja\Sorter\Comparator\UnicodeCIComparator;
0 ignored issues
show
Bug introduced by
The type Ninja\Sorter\Comparator\UnicodeCIComparator was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Ninja\Sorter\Strategy\SimpleSortStrategy;
7
use Ninja\Sorter\Strategy\StrategyInterface;
8
9
abstract class AbstractSorter implements SorterInterface
10
{
11 3
    public function __construct(private ?StrategyInterface $strategy = null)
12
    {
13 3
        if ($this->strategy === null) {
14 3
            $this->strategy = new SimpleSortStrategy(new UnicodeCIComparator());
15
        }
16
    }
17
18 1
    public function setStrategy(StrategyInterface $strategy): static
19
    {
20 1
        $this->strategy = $strategy;
21 1
        return $this;
22
    }
23
24 1
    public function setSortOrder(int $order): static
25
    {
26 1
        $this->strategy?->setOrder($order);
27 1
        return $this;
28
    }
29
30 3
    /**
31
     * @param array<string|int, mixed> $collection
32 3
     * @return array<string|int, mixed>
33
     */
34
    public function sort(array $collection): array
35
    {
36 3
        if (!$this->strategy) {
37
            throw new \RuntimeException('Strategy was not defined');
38
        }
39
40
        return $this->strategy->sort($collection);
41
    }
42
}
43