CacheUtilsTrait::streamSafeGlob()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 17
c 0
b 0
f 0
ccs 9
cts 9
cp 1
rs 9.2
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
    {
20 1
        $files = scandir($directory);
21 1
        $found = [];
22
23 1
        foreach ($files as $filename) {
24 1
            if (in_array($filename, ['.', '..'])) {
25 1
                continue;
26
            }
27
28 1
            if (fnmatch($filePattern, $filename)) {
29 1
                $found[] = "{$directory}/{$filename}";
30
            }
31
        }
32
33 1
        return $found;
34
    }
35
}
36