Completed
Push — master ( df58f2...bfcb35 )
by Andreas
03:05
created

NaturalFileSorter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * Sorts files naturally.
4
 *
5
 * @copyright 2014-2018 Institute of Legal Medicine, Medical University of Innsbruck
6
 * @author Nikola Vrlazic <[email protected]>
7
 * @author Andreas Erhard <[email protected]>
8
 * @license LGPL-3.0-only
9
 * @link http://www.gerichtsmedizin.at/
10
 *
11
 * @package pdftk
12
 */
13
14
namespace Gmi\Toolkit\Pdftk\Util;
15
16
use SplFileInfo;
17
18
/**
19
 * Sort different types of files from array (natural sorting, case insensitive).
20
 */
21
class NaturalFileSorter implements FileSorterInterface
22
{
23
    /**
24
     * @var ClosureFileSorter;
25
     */
26
    private $sorter;
27
28
    /**
29
     * Constructor.
30
     */
31
    public function __construct()
32
    {
33 6
        $naturalSorter = function (SplFileInfo $a, SplFileInfo $b) {
34 1
            return strnatcasecmp($a->getRealPath(), $b->getRealPath());
35 6
        };
36
37 6
        $this->sorter = new ClosureFileSorter($naturalSorter);
38 6
    }
39
40
    /**
41
     * Sort files using natural order.
42
     *
43
     * @param SplFileInfo[] $fileInfos
44
     *
45
     * @return SplFileInfo[]
46
     */
47 1
    public function sort(array $fileInfos)
48
    {
49 1
        return $this->sorter->sort($fileInfos);
50
    }
51
}
52