Passed
Push — master ( 4017d9...9757db )
by Dev
10:15
created

ElementRepository::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PiedWeb\CMSBundle\Extension\TemplateEditor;
4
5
use Symfony\Component\Finder\Finder;
6
7
class ElementRepository
8
{
9
    protected $templateDir;
10
11
    public function __construct($templateDir)
12
    {
13
        $this->templateDir = $templateDir;
14
    }
15
16
    public function getAll(): array
17
    {
18
        $finder = new Finder();
19
        $finder->files()->in($this->templateDir);
20
        $elements = [];
21
22
        foreach ($finder as $file) {
23
            $elements[] = new Element($this->templateDir, $file);
24
        }
25
26
        return $elements;
27
    }
28
29
    public function getOneByEncodedPath($path): ?Element
30
    {
31
        foreach ($this->getAll() as $element) {
32
            if ($element->getEncodedPath() == $path) {
33
                return $element;
34
            }
35
        }
36
37
        return null;
38
    }
39
}
40