Passed
Push — master ( b1f105...c36d1c )
by Claudio
02:11
created

Asc::sort()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Budgegeria\IntlSort\Sorter;
6
7
use Budgegeria\IntlSort\Exception\IntlSortException;
8
use Collator;
9
10
final class Asc implements Sorter
11
{
12
    /**
13
     * @var Collator
14
     */
15
    private $collator;
16
17
    /**
18
     * @var int A Collator::SORT_* sort flag
19
     */
20
    private $sortType;
21
22 2
    public function __construct(Collator $collator, int $sortType)
23
    {
24 2
        $this->collator = $collator;
25 2
        $this->sortType = $sortType;
26 2
    }
27
28
    /**
29
     * {@inheritDoc}
30
     */
31 2
    public function sort(array $values) : array
32
    {
33 2
        if (! $this->collator->asort($values, $this->sortType)) {
34 1
            throw IntlSortException::errorOnSort();
35
        }
36
37 1
        return $values;
38
    }
39
}