Completed
Push — master ( 410005...efdb94 )
by Bernhard
04:50
created

RecursiveDirectoryIterator::__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4286
cc 3
eloc 4
nc 4
nop 2
crap 3
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 10
    public function __construct($path, $flags = 0)
42
    {
43 10
        parent::__construct($path, $flags);
44
45
        // Normalize slashes on Windows
46 9
        $this->normalizeKey = '\\' === DIRECTORY_SEPARATOR && !($flags & self::KEY_AS_FILENAME);
47 9
        $this->normalizeCurrent = '\\' === DIRECTORY_SEPARATOR && ($flags & self::CURRENT_AS_PATHNAME);
48 9
    }
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