NamespaceRegistry   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getPrefix() 0 11 2
1
<?php
2
3
/*
4
 * This file is part of Sulu.
5
 *
6
 * (c) MASSIVE ART WebServices GmbH
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 Sulu\Component\DocumentManager;
13
14
use Sulu\Component\DocumentManager\Exception\DocumentManagerException;
15
16
/**
17
 * Central registry of roles to namespaces.
18
 */
19
class NamespaceRegistry
20
{
21
    private $roleMap = [];
22
23
    /**
24
     * @param array $roleMap
25
     */
26
    public function __construct(array $roleMap)
27
    {
28
        $this->roleMap = $roleMap;
29
    }
30
31
    /**
32
     * Return the namespace alias for the given role, e.g. "localized_content" => "lcont".
33
     *
34
     * @param $role
35
     *
36
     * @throws DocumentManagerException
37
     *
38
     * @return string
39
     */
40
    public function getPrefix($role)
41
    {
42
        if (!array_key_exists($role, $this->roleMap)) {
43
            throw new DocumentManagerException(sprintf(
44
                'Trying to get non-existant namespace alias role "%s", known roles: "%s"',
45
                $role, implode('", "', array_keys($this->roleMap))
46
            ));
47
        }
48
49
        return $this->roleMap[$role];
50
    }
51
}
52