FileLoaderResolver   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 4
c 1
b 1
f 0
lcom 1
cbo 0
dl 0
loc 45
ccs 9
cts 9
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A registerLoader() 0 4 1
A hasLoader() 0 4 1
A resolveLoader() 0 8 2
1
<?php
2
3
/*
4
 * This file is part of the AsmTranslationLoaderBundle package.
5
 *
6
 * (c) Marc Aschmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Asm\TranslationLoaderBundle\Translation;
13
14
use Symfony\Component\Translation\Loader\LoaderInterface;
15
16
/**
17
 * Translation loader resolver.
18
 *
19
 * @author Christian Flothmann <[email protected]>
20
 */
21
class FileLoaderResolver
22
{
23
    /**
24
     * @var LoaderInterface[]
25
     */
26
    private $loaders = array();
27
28
    /**
29
     * @param LoaderInterface $loader    The translation loader
30
     * @param string          $extension The file extension
31
     */
32 14
    public function registerLoader(LoaderInterface $loader, $extension)
33
    {
34 14
        $this->loaders[$extension] = $loader;
35 14
    }
36
37
    /**
38
     * Checks whether or not a translation loader for a file extension is registered.
39
     *
40
     * @param string $extension The file extension
41
     *
42
     * @return boolean True if such a loader is registered, false otherwise
43
     */
44 14
    public function hasLoader($extension)
45
    {
46 14
        return isset($this->loaders[$extension]);
47
    }
48
49
    /**
50
     * Resolves the translation loader for a file extension.
51
     *
52
     * @param string $extension The file extension
53
     *
54
     * @return LoaderInterface The resolved loader or null if no loader is
55
     *                         associated with the given extension
56
     */
57 14
    public function resolveLoader($extension)
58
    {
59 14
        if ($this->hasLoader($extension)) {
60 13
            return $this->loaders[$extension];
61
        }
62
63 1
        return null;
64
    }
65
}
66