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

ElementRepository::getOneByEncodedPath()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 4
c 1
b 0
f 1
nc 3
nop 1
dl 0
loc 9
ccs 0
cts 8
cp 0
crap 12
rs 10
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