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

ClosureFileSorter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 6
dl 0
loc 41
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A sort() 0 5 1
A getClosure() 0 3 1
1
<?php
2
/**
3
 * Sorts files using a closure.
4
 *
5
 * @copyright 2014-2018 Institute of Legal Medicine, Medical University of Innsbruck
6
 * @author Andreas Erhard <[email protected]>
7
 * @license LGPL-3.0-only
8
 * @link http://www.gerichtsmedizin.at/
9
 *
10
 * @package pdftk
11
 */
12
13
namespace Gmi\Toolkit\Pdftk\Util;
14
15
use Closure;
16
use SplFileInfo;
17
18
/**
19
 * Sort different types of files using a closure for the actual sorting.
20
 */
21
class ClosureFileSorter implements FileSorterInterface
22
{
23
    /**
24
     * @var Closure
25
     */
26
    private $closure;
27
28
    /**
29
     * Constructor.
30
     *
31
     * @param Closure $closure Anoymous function which can be used by uasort().
32
     */
33 7
    public function __construct(Closure $closure)
34
    {
35 7
        $this->closure = $closure;
36 7
    }
37
38
    /**
39
     * Sort files using natural order.
40
     *
41
     * @param SplFileInfo[] $fileInfos
42
     *
43
     * @return SplFileInfo[]
44
     */
45 2
    public function sort(array $fileInfos)
46
    {
47 2
        uasort($fileInfos, $this->closure);
48
49 2
        return array_values($fileInfos);
50
    }
51
52
    /**
53
     * Returns the closure.
54
     *
55
     * This method is not part of the FileSorterInterface, but can be used for testing/debugging.
56
     *
57
     * @return Closure
58
     */
59 1
    public function getClosure()
60
    {
61 1
        return $this->closure;
62
    }
63
}
64