RecursiveDirectoryIterator   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 0

Test Coverage

Coverage 88.24%

Importance

Changes 6
Bugs 1 Features 1
Metric Value
wmc 8
c 6
b 1
f 1
lcom 3
cbo 0
dl 0
loc 60
ccs 15
cts 17
cp 0.8824
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getChildren() 0 4 1
A __construct() 0 8 3
A key() 0 10 2
A current() 0 10 2
1
<?php
2
3
/*
4
 * This file is part of the webmozart/glob package.
5
 *
6
 * (c) Bernhard Schussek <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Webmozart\Glob\Iterator;
13
14
/**
15
 * Recursive directory iterator that is working during recursive iteration.
16
 *
17
 * Recursive iteration is broken on PHP < 5.5.23 and on PHP 5.6 < 5.6.7.
18
 *
19
 * @since  1.0
20
 * @since  3.0 Removed support for seek(), added \RecursiveDirectoryIterator
21
 *             base class, adapted API to match \RecursiveDirectoryIterator
22
 * @since  3.1 Slashes are normalized to forward slashes on Windows
23
 *
24
 * @author Bernhard Schussek <[email protected]>
25
 */
26
class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator
27
{
28
    /**
29
     * @var bool
30
     */
31
    private $normalizeKey;
32
33
    /**
34
     * @var bool
35
     */
36
    private $normalizeCurrent;
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 12
    public function __construct($path, $flags = 0)
42
    {
43 12
        parent::__construct($path, $flags);
44
45
        // Normalize slashes on Windows
46 11
        $this->normalizeKey = '\\' === DIRECTORY_SEPARATOR && !($flags & self::KEY_AS_FILENAME);
47 11
        $this->normalizeCurrent = '\\' === DIRECTORY_SEPARATOR && ($flags & self::CURRENT_AS_PATHNAME);
48 11
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 6
    public function getChildren()
54
    {
55 6
        return new static($this->getPathname(), $this->getFlags());
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61 9
    public function key()
62
    {
63 9
        $key = parent::key();
64
65 9
        if ($this->normalizeKey) {
66
            $key = str_replace('\\', '/', $key);
67
        }
68
69 9
        return $key;
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75 9
    public function current()
76
    {
77 9
        $current = parent::current();
78
79 9
        if ($this->normalizeCurrent) {
80
            $current = str_replace('\\', '/', $current);
81
        }
82
83 9
        return $current;
84
    }
85
}
86