Completed
Pull Request — master (#29)
by Aleh
03:11
created

Repository::read()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
rs 9.6666
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
3
namespace Padawan\Framework\Project;
4
5
6
use Padawan\Framework\IO\Reader;
7
use Padawan\Domain\ProjectRepository;
8
use Padawan\Domain\Core\Project;
9
use Padawan\Domain\Core\Index;
10
11
/**
12
 * Class Repository
13
 */
14
class Repository implements ProjectRepository
15
{
16
    public function __construct(Persister $persister)
17
    {
18
        $this->persister = $persister;
19
        $this->pool = [];
20
    }
21
    public function findByPath($path)
22
    {
23
        if (!array_key_exists($path, $this->pool)) {
24
            $this->pool[$path] = $this->read($path);
25
        }
26
        return $this->pool[$path];
27
    }
28
29
    private function read($path)
30
    {
31
        $project = $this->persister->load($path);
32
        if (!empty($project)) {
33
            return $project;
34
        } else {
35
            return new Project(new Index, $path);
36
        }
37
    }
38
39
    private $pool;
40
    private $persister;
41
}
42