Locator::locate()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 10
nc 6
nop 1
dl 0
loc 16
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
namespace AmaTeam\Image\Projection\Filesystem;
4
5
use League\Flysystem\FilesystemInterface;
6
7
class Locator
8
{
9
    /**
10
     * @var FilesystemInterface
11
     */
12
    private $filesystem;
13
14
    /**
15
     * @param FilesystemInterface $filesystem
16
     */
17
    public function __construct(FilesystemInterface $filesystem)
18
    {
19
        $this->filesystem = $filesystem;
20
    }
21
22
    /**
23
     * @param Pattern $pattern
24
     * @return array
25
     */
26
    public function locate(Pattern $pattern)
27
    {
28
        $root = $pattern->getFixedPart();
29
        // todo: quick hack instead of proper solution
30
        if ($pattern->isFixed()) {
31
            $root = dirname($root);
32
        }
33
        $entries = [];
34
        foreach ($this->filesystem->listContents($root, true) as $entry) {
35
            if (!$pattern->matches($entry['path'])) {
36
                continue;
37
            }
38
            $entry['parameters'] = $pattern->getParameters($entry['path']);
39
            $entries[] = $entry;
40
        }
41
        return $entries;
42
    }
43
}
44