Completed
Push — master ( 3bba38...f9f96f )
by Dev
04:14
created

ElementRepository   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 13
c 1
b 0
f 1
dl 0
loc 32
ccs 0
cts 22
cp 0
rs 10
wmc 6

3 Methods

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