Locator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A locate() 0 16 4
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