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

CacheUtilsTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 27
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A streamSafeGlob() 0 16 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
}