Passed
Branch master (3e058b)
by Allan
02:59
created

FileSystemUtils   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 13
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A collectPathsRecursively() 0 22 3
1
<?php
2
/**
3
 * Copyright © Vaimo Group. All rights reserved.
4
 * See LICENSE_VAIMO.txt for license details.
5
 */
6
namespace Vaimo\ComposerChangelogs\Utils;
7
8
class FileSystemUtils
9
{
10
    public function collectPathsRecursively($rootPath, $pattern)
11
    {
12
        if (!is_dir($rootPath)) {
13
            return array();
14
        }
15
        
16
        $directoryIterator = new \RecursiveDirectoryIterator($rootPath);
17
        $recursiveIterator = new \RecursiveIteratorIterator($directoryIterator);
18
19
        $filesIterator = new \RegexIterator(
20
            $recursiveIterator,
21
            $pattern,
22
            \RecursiveRegexIterator::GET_MATCH
23
        );
24
25
        $files = array();
26
27
        foreach ($filesIterator as $info) {
28
            $files[] = reset($info);
29
        }
30
31
        return $files;
32
    }
33
}
34