PathSegmentRegistry   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getPathSegment() 0 16 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
/**
15
 * Provides a centralized repository of path components.
16
 *
17
 * Note that this is not used by the document manager itself, but
18
 * is a useful utility for implementors.
19
 *
20
 * TODO: Move this class to somewhere more appropriate
21
 */
22
class PathSegmentRegistry
23
{
24
    /**
25
     * @var array
26
     */
27
    private $pathSegments;
28
29
    /**
30
     * @param array Array of roles to pathSegments
31
     */
32
    public function __construct(array $pathSegments = [])
33
    {
34
        $this->pathSegments = $pathSegments;
35
    }
36
37
    /**
38
     * Return the configured named path segment.
39
     *
40
     * @param string $name Name of path segment
41
     *
42
     * @throws \InvalidArgumentException
43
     *
44
     * @return string The path segment
45
     */
46
    public function getPathSegment($name)
47
    {
48
        if (!isset($this->pathSegments[$name])) {
49
            throw new \InvalidArgumentException(
50
                sprintf(
51
                    'Unknown path segment "%s". Known path segments: "%s"',
52
                    $name,
53
                    implode('", "', array_keys($this->pathSegments))
54
                )
55
            );
56
        }
57
58
        $name = $this->pathSegments[$name];
59
60
        return $name;
61
    }
62
}
63