ClassDefinition   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 159
Duplicated Lines 0 %

Test Coverage

Coverage 94.29%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 29
c 2
b 0
f 0
dl 0
loc 159
ccs 33
cts 35
cp 0.9429
rs 10
wmc 17

14 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A getNamespace() 0 3 1
A addProperty() 0 5 1
A setNamespace() 0 3 1
A setExtends() 0 3 1
A getExtends() 0 3 1
A getMethods() 0 3 1
A addMethod() 0 7 2
A getUseStatements() 0 3 1
A getComments() 0 3 1
A addComment() 0 7 2
A setName() 0 3 1
A addUseStatement() 0 7 2
A getProperties() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 *  This file is part of the Micro framework package.
7
 *
8
 *  (c) Stanislau Komar <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace Micro\Library\DTO\ClassDef;
15
16
use Micro\Library\DTO\Helper\ClassMetadataHelperInterface;
17
18
class ClassDefinition
19
{
20
    /**
21
     * @var string
22
     */
23
    private string $extends = ClassMetadataHelperInterface::PROPERTY_TYPE_ABSTRACT_CLASS;
24
25
    /**
26
     * @var string
27
     */
28
    private string $namespace = '';
29
30
    /**
31
     * @var string
32
     */
33
    private string $name = '';
34
35
    /**
36
     * @var array<string, string|null>
37
     */
38
    private array $useStatements = [];
39
40
    /**
41
     * @var array<PropertyDefinition>
42
     */
43
    private array $properties = [];
44
45
    /**
46
     * @var array<MethodDefinition>
47
     */
48
    private array $methods = [];
49
50
    /**
51
     * @var array<string>
52
     */
53
    private array $comments = [];
54
55
    /**
56
     * @return string
57
     */
58 1
    public function getExtends(): string
59
    {
60 1
        return $this->extends;
61
    }
62
63
    /**
64
     * @param string $extends
65
     */
66
    public function setExtends(string $extends): void
67
    {
68
        $this->extends = $extends;
69
    }
70
71
    /**
72
     * @return string
73
     */
74 3
    public function getNamespace(): string
75
    {
76 3
        return $this->namespace;
77
    }
78
79
    /**
80
     * @param string $namespace
81
     */
82 3
    public function setNamespace(string $namespace): void
83
    {
84 3
        $this->namespace = $namespace;
85
    }
86
87
    /**
88
     * @return string
89
     */
90 3
    public function getName(): string
91
    {
92 3
        return $this->name;
93
    }
94
95
    /**
96
     * @param string $name
97
     */
98 3
    public function setName(string $name): void
99
    {
100 3
        $this->name = $name;
101
    }
102
103
    /**
104
     * @return PropertyDefinition[]
105
     */
106 1
    public function getProperties(): iterable
107
    {
108 1
        return $this->properties;
109
    }
110
111
    /**
112
     * @param PropertyDefinition $propertyDefinition
113
     *
114
     * @return $this
115
     */
116 3
    public function addProperty(PropertyDefinition $propertyDefinition): self
117
    {
118 3
        $this->properties[] = $propertyDefinition;
119
120 3
        return $this;
121
    }
122
123
    /**
124
     * @return MethodDefinition[]
125
     */
126 1
    public function getMethods(): iterable
127
    {
128 1
        return $this->methods;
129
    }
130
131 1
    public function addMethod(MethodDefinition $methodDefinition): self
132
    {
133 1
        if (!\in_array($methodDefinition, $this->methods)) {
134 1
            $this->methods[] = $methodDefinition;
135
        }
136
137 1
        return $this;
138
    }
139
140
    /**
141
     * @return string[]
142
     */
143 1
    public function getComments(): iterable
144
    {
145 1
        return $this->comments;
146
    }
147
148
    /**
149
     * @param string $comment
150
     *
151
     * @return $this
152
     */
153 3
    public function addComment(string $comment): self
154
    {
155 3
        if (!\in_array($comment, $this->comments)) {
156 3
            $this->comments[] = $comment;
157
        }
158
159 3
        return $this;
160
    }
161
162
    /**
163
     * @return array<string, null>|array<string, string>
164
     */
165 1
    public function getUseStatements(): array
166
    {
167 1
        return $this->useStatements;
168
    }
169
170 1
    public function addUseStatement(string $useStatement, string $alias = null): self
171
    {
172 1
        if (!\array_key_exists($useStatement, $this->useStatements)) {
173 1
            $this->useStatements[$useStatement] = $alias;
174
        }
175
176 1
        return $this;
177
    }
178
}
179