Completed
Pull Request — master (#174)
by Danny
04:17
created

AliasManager::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author Patsura Dmitry https://github.com/ovr <[email protected]>
4
 */
5
6
namespace PHPSA;
7
8
class AliasManager
9
{
10
    /**
11
     * Current namespace, but this can be null
12
     * @var string|null
13
     */
14
    protected $namespace;
15
16
    /**
17
     * @var string[] a list of imported namespaces
18
     */
19
    protected $aliases = array();
20
21
    /**
22
     * @param string|null $namespace
23
     */
24 28
    public function __construct($namespace = null)
25
    {
26 28
        $this->namespace = $namespace;
27 28
    }
28
29
    /**
30
     * Checks whether a namespace was imported via use statement.
31
     *
32
     * @param string $classNS
33
     * @return bool
34
     */
35
    public function isClassImported($classNS)
36
    {
37
        if (isset($this->aliases[$classNS])) {
38
            return true;
39
        }
40
41
        return false;
42
    }
43
44
    /**
45
     * Imports a namespace as an alias via use statement.
46
     *
47
     * @param string $namespace
48
     */
49 1
    public function add($namespace)
50
    {
51 1
        $this->aliases[] = $namespace;
52 1
    }
53
54
    /**
55
     * Gets the current namespace.
56
     *
57
     * @return null|string
58
     */
59 27
    public function getNamespace()
60
    {
61 27
        return $this->namespace;
62
    }
63
64
    /**
65
     * Sets the current namespace.
66
     *
67
     * @param null|string $namespace
68
     */
69 27
    public function setNamespace($namespace)
70
    {
71 27
        $this->namespace = $namespace;
72 27
    }
73
}
74