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

AliasManager   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 73.32%

Importance

Changes 0
Metric Value
dl 0
loc 66
ccs 11
cts 15
cp 0.7332
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getNamespace() 0 4 1
A setNamespace() 0 4 1
A isClassImported() 0 8 2
A add() 0 4 1
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