Completed
Pull Request — master (#28)
by Jamal
03:34
created

LoaderCollection   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 4 2
A has() 0 4 1
A add() 0 8 2
1
<?php
2
3
namespace Majora\Framework\Loader;
4
5
/**
6
 * Class LoaderCollection
7
 */
8
class LoaderCollection
9
{
10
    /**
11
     * @var array
12
     */
13
    private $loaders;
14
    
15
    /**
16
     * Get a loader.
17
     *
18
     * @param $alias
19
     * @return array|null
20
     */
21
    public function get($alias)
22
    {
23
        return isset($this->loaders[$alias]) ? $this->loaders[$alias] : null;
24
    }
25
26
    /**
27
     * Test if a loader exists.
28
     *
29
     * @param $alias
30
     * @return bool
31
     */
32
    public function has($alias)
33
    {
34
        return isset($this->loaders[$alias]);
35
    }
36
37
    /**
38
     * Add a new loader.
39
     *
40
     * @param $alias
41
     * @param LoaderInterface $loader
42
     */
43
    public function add($alias, LoaderInterface $loader)
44
    {
45
        if ($this->has($alias)) {
46
            throw new \RuntimeException(sprintf('Alias "%s" already used by another loader', $alias));
47
        }
48
49
        $this->loaders[$alias] = $loader;
50
    }
51
}