AlphaSorter   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 0
dl 0
loc 26
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A sort() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Datapp\TableauExport\Sorter;
6
7
use Datapp\TableauExport\Sorter\SorterInterface;
8
9
/**
10
 * @author Manuel Dimmler
11
 */
12
class AlphaSorter implements SorterInterface
13
{
14
15
    const ASC = 1;
16
    const DESC = -1;
17
18
    /** @var int */
19
    private $sorting;
20
21 1
    public function __construct(int $sorting = self::ASC)
22
    {
23 1
        $this->sorting = ((int) ($sorting >= 0)) * 2 - 1;
24 1
    }
25
26
    /**
27
     * @param array<string, string> $data
28
     * @return array<string, string>
0 ignored issues
show
Documentation introduced by
The doc-type array<string, could not be parsed: Expected ">" at position 5, but found "end of type". (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
29
     */
30 1
    public function sort(array $data): array
31
    {
32 1
        uksort($data, function (string $a, string $b): int {
33 1
            return strcmp($a, $b) * $this->sorting;
34 1
        });
35 1
        return $data;
36
    }
37
}
38