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

Repository   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 5
c 2
b 0
f 2
lcom 1
cbo 3
dl 0
loc 28
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A findByPath() 0 7 2
A read() 0 9 2
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