Completed
Push — master ( cc9f19...85e40f )
by Pavel
11s
created

FileLocator::locateAll()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 29
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 29
rs 8.439
c 1
b 0
f 0
cc 6
eloc 12
nc 5
nop 0
1
<?php
2
3
namespace App\Common\Config;
4
5
/**
6
 * FileLocator uses an array of pre-defined paths to find files.
7
 */
8
class FileLocator extends \Symfony\Component\Config\FileLocator
9
{
10
    /**
11
     * Returns an array of full paths to all locatable files
12
     *
13
     * @return array
14
     */
15
    public function locateAll()
16
    {
17
        $res = [];
18
19
        // no paths for files specified - no files to locate
20
        if (!is_array($this->paths)) {
21
            return $res;
22
        }
23
24
        // traverse over all paths specified for search in locator
25
        foreach ($this->paths as $path) {
26
            // fetch entries in each path
27
            $dir_entries = scandir($path);
28
            foreach ($dir_entries as $dir_entry) {
29
                // include paths to files into result set
30
                $filename = $path . DIRECTORY_SEPARATOR . $dir_entry;
31
                if (@is_file($filename) && @is_readable($filename)) {
32
                    $res[] = $filename;
33
                }
34
            }
35
        }
36
37
        // here $res is an array of paths to files
38
        // make files in res set unique
39
        $res = array_unique($res);
40
41
        // return array of file paths
42
        return $res;
43
    }
44
}
45