LoaderContainer   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 4 1
A has() 0 4 1
A __construct() 0 5 1
A register() 0 6 1
A registerAll() 0 7 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\container;
13
14
use Collections\Map;
15
use Collections\Pair;
16
use holyshared\fixture\Container;
17
use holyshared\fixture\FixtureLoader;
18
19
20
final class LoaderContainer implements Container
21
{
22
23
    /**
24
     * @var \Collections\Map
25
     */
26
    private $loaders;
27
28
    /**
29
     * @param FixtureLoader[] $loaders
30
     */
31
    public function __construct(array $loaders = [])
32
    {
33
        $this->loaders = new Map();
34
        $this->registerAll($loaders);
35
    }
36
37
    /**
38
     * Get the loader of fixture
39
     *
40
     * @param string $name
41
     * @return \holyshared\fixture\FixtureLoader
42
     */
43
    public function get($name)
44
    {
45
        return $this->loaders->get($name);
46
    }
47
48
    /**
49
     * @param string $name
50
     * @return bool
51
     */
52
    public function has($name)
53
    {
54
        return $this->loaders->containsKey($name);
55
    }
56
57
    /**
58
     * Register the loader of fixture
59
     *
60
     * @param \holyshared\fixture\FixtureLoader $loader
61
     * @return holyshared\fixture\container\LoaderContainer
62
     */
63
    public function register(FixtureLoader $loader)
64
    {
65
        $value = new Pair($loader->getName(), $loader);
66
        $this->loaders->add($value);
67
        return $this;
68
    }
69
70
    /**
71
     * Register all the loader of fixture
72
     *
73
     * @param \holyshared\fixture\FixtureLoader[] $loaders
74
     * @return holyshared\fixture\container\LoaderContainer
75
     */
76
    public function registerAll(array $loaders = [])
77
    {
78
        foreach ($loaders as $loader) {
79
            $this->register($loader);
80
        }
81
        return $this;
82
    }
83
84
}
85