AliasDefinition::aliasFromNamespace()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
/**
3
 * This file is part of the Stack package.
4
 *
5
 * (c) Andrzej Kostrzewa <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Stack\DI\Definition;
12
13
/**
14
 * Defines an alias from an entry to another.
15
 *
16
 * @author Andrzej Kostrzewa <[email protected]>
17
 */
18
class AliasDefinition
19
{
20
    /**
21
     * Entry name.
22
     *
23
     * @var string|null
24
     */
25
    private $name;
26
27
    /**
28
     * Name of the target entry.
29
     *
30
     * @var string|null
31
     */
32
    private $targetName;
33
34
    /**
35
     * AliasDefinition constructor.
36
     *
37
     * @param string|null $name       Entry name
38
     * @param string|null $targetName Name of the target entry
39
     */
40
    public function __construct($name = null, $targetName = null)
41
    {
42
        $this->name       = $name;
43
        $this->targetName = $targetName;
44
    }
45
46
    /**
47
     * Extract name from target entry.
48
     *
49
     * @param string $targetName
50
     */
51
    public function aliasFromNamespace($targetName)
52
    {
53
        $name             = explode('\\', $targetName);
54
        $name             = end($name);
55
        $this->name       = strtolower($name);
56
        $this->targetName = $targetName;
57
    }
58
59
    /**
60
     * @return string|null Entry name
61
     */
62
    public function getName()
63
    {
64
        return $this->name;
65
    }
66
67
    /**
68
     * @return string|null Name of the target entry
69
     */
70
    public function getTargetName()
71
    {
72
        return $this->targetName;
73
    }
74
}
75