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

NaturalFileSorter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 6
dl 0
loc 29
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A sort() 0 3 1
A __construct() 0 7 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