Completed
Push — master ( f083aa...b6d504 )
by Nielsen
01:53
created

CacheUtilsTrait::streamSafeGlob()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 9
cts 9
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 4
nop 2
crap 4
1
<?php
2
3
namespace Ezcache\Cache;
4
5
/**
6
 * Trait CacheUtilsTrait
7
 */
8
trait CacheUtilsTrait {
9
10
    /**
11
     * Glob that is safe with streams (vfs for example)
12
     *
13
     * @param string $directory the directory
14
     * @param string $filePattern the file pattern
15
     *
16
     * @return array containing match files
17
     */
18 1
    public function streamSafeGlob($directory, $filePattern) : array {
19 1
        $files = scandir($directory);
20 1
        $found = [];
21
22 1
        foreach ($files as $filename) {
23 1
            if (in_array($filename, ['.', '..'])) {
24 1
                continue;
25
            }
26
27 1
            if (fnmatch($filePattern, $filename)) {
28 1
                $found[] = "{$directory}/{$filename}";
29
            }
30
        }
31
32 1
        return $found;
33
    }
34
}