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

ElementRepository::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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