CacheLoader   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 48
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getName() 0 4 1
A load() 0 11 2
1
<?php
2
3
/**
4
 * This file is part of file-fixture.
5
 *
6
 * (c) Noritaka Horio <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace holyshared\fixture\loader;
13
14
use holyshared\fixture\FixtureLoader;
15
use Collections\Map;
16
use Collections\Pair;
17
18
19
final class CacheLoader implements FixtureLoader
20
{
21
22
    /**
23
     * @var \holyshared\fixture\FixtureLoader
24
     */
25
    private $loader;
26
27
    /**
28
     * @var \Collections\Map
29
     */
30
    private $caches;
31
32
    /**
33
     * Create a new cache loader
34
     *
35
     * @param \holyshared\fixture\FixtureLoader
36
     */
37
    public function __construct(FixtureLoader $loader)
38
    {
39
        $this->loader = $loader;
40
        $this->caches = new Map();
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function getName()
47
    {
48
        return $this->loader->getName();
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function load($path, array $arguments = [])
55
    {
56
        if ($this->caches->containsKey($path) === false) {
57
            $content = $this->loader->load($path, $arguments);
58
59
            $value = new Pair($path, $content);
60
            $this->caches->add($value);
61
        }
62
63
        return $this->caches->get($path);
64
    }
65
66
}
67