UseClass::hasAlias()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4286
cc 2
eloc 3
nc 2
nop 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of the ClassGeneration package.
5
 *
6
 * (c) Antonio Spinelli <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ClassGeneration;
13
14
use ClassGeneration\Element\ElementAbstract;
15
use ClassGeneration\Element\ElementInterface;
16
17
/**
18
 * Use ClassGeneration
19
 * @author Antonio Spinelli <[email protected]>
20
 */
21
class UseClass extends ElementAbstract implements UseInterface
22
{
23
24
    /**
25
     * The class name.
26
     * @var string
27
     */
28
    protected $className;
29
30
    /**
31
     * The alias for class name.
32
     * @var string
33
     */
34
    protected $alias;
35
36
    /**
37
     * @inheritdoc
38
     */
39 7
    public function init()
40
    {
41 7
    }
42
43
    /**
44
     * @inheritdoc
45
     * @return PhpClassInterface
46
     */
47 1
    public function getParent()
48
    {
49 1
        return $this->parent;
50
    }
51
52
    /**
53
     * @inheritdoc
54
     * @return UseInterface
55
     */
56 1
    public function setParent(ElementInterface $parent)
57
    {
58 1
        if (!$parent instanceof PhpClassInterface) {
59 1
            throw new \InvalidArgumentException('Only accept instances from ClassGeneration\PhpClassInterface');
60
        }
61
62 1
        return parent::setParent($parent);
63
    }
64
65
    /**
66
     * @inheritdoc
67
     */
68 2
    public function setAlias($alias)
69
    {
70 2
        $this->alias = (string)$alias;
71
72 2
        return $this;
73
    }
74
75
    /**
76
     * Gets the alias name.
77
     * @return string
78
     */
79 4
    public function getAlias()
80
    {
81 4
        return $this->alias;
82
    }
83
84
    /**
85
     * @inheritdoc
86
     */
87 4
    public function hasAlias()
88
    {
89 4
        $alias = $this->getAlias();
90
91 4
        return (!is_null($alias) && !empty($alias));
92
    }
93
94
    /**
95
     * @inheritdoc
96
     */
97 4
    public function setClassName($className)
98
    {
99 4
        $this->className = (string)$className;
100
101 4
        return $this;
102
    }
103
104
    /**
105
     * @inheritdoc
106
     */
107 4
    public function getClassName()
108
    {
109 4
        return $this->className;
110
    }
111
112
    /**
113
     * @inheritdoc
114
     */
115 4
    public function toString()
116
    {
117
118
        $implements = 'use '
119 4
            . $this->getClassName()
120 4
            . ($this->hasAlias() ? ' as ' . $this->getAlias() : '')
121 4
            . ';' . PHP_EOL;
122
123 4
        return $implements;
124
    }
125
}
126