SortedFileIterator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 4
dl 0
loc 25
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A compare() 0 3 1
A __construct() 0 6 2
1
<?php
2
3
/**
4
 * SortedIterator.php
5
 *
6
 * This class sorts files alphabetically by name.
7
 *
8
 * @package jaxon-core
9
 * @author Thierry Feuzeu <[email protected]>
10
 * @copyright 2024 Thierry Feuzeu <[email protected]>
11
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
12
 * @link https://github.com/jaxon-php/jaxon-core
13
 */
14
15
namespace Jaxon\Plugin\Request\CallableClass;
16
17
use RecursiveDirectoryIterator;
18
use RecursiveIteratorIterator;
19
use SplHeap;
20
21
use function strcmp;
22
23
class SortedFileIterator extends SplHeap
24
{
25
    /**
26
     * @param string $sDirectory
27
     */
28
    public function __construct(string $sDirectory)
29
    {
30
        $itFile = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($sDirectory));
31
        foreach($itFile as $xFile)
32
        {
33
            $this->insert($xFile);
34
        }
35
    }
36
37
    /**
38
     * Compare elements in order to place them correctly in the heap
39
     *
40
     * @param mixed $xFile1
41
     * @param mixed $xFile2
42
     *
43
     * @return int
44
     */
45
    public function compare($xFile1, $xFile2): int
46
    {
47
        return strcmp($xFile2->getRealPath(), $xFile1->getRealPath());
48
    }
49
}
50