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

ElementRepository::getAll()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 6
c 1
b 0
f 1
nc 2
nop 0
dl 0
loc 11
ccs 0
cts 9
cp 0
crap 6
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