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

ElementRepository   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getAll() 0 11 2
A getOneByEncodedPath() 0 9 3
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