1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* PHP version 7.1 |
4
|
|
|
* |
5
|
|
|
* This source file is subject to the license that is bundled with this package in the file LICENSE. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace PhUml\Code; |
9
|
|
|
|
10
|
|
|
class Summary |
11
|
|
|
{ |
12
|
|
|
private $interfaceCount; |
13
|
|
|
private $classCount; |
14
|
|
|
private $publicFunctionCount; |
15
|
|
|
private $publicAttributeCount; |
16
|
|
|
private $publicTypedAttributes; |
17
|
|
|
private $protectedFunctionCount; |
18
|
|
|
private $protectedAttributeCount; |
19
|
|
|
private $protectedTypedAttributes; |
20
|
|
|
private $privateFunctionCount; |
21
|
|
|
private $privateAttributeCount; |
22
|
|
|
private $privateTypedAttributes; |
23
|
|
|
|
24
|
9 |
|
public function __construct() |
25
|
|
|
{ |
26
|
9 |
|
$this->interfaceCount = 0; |
27
|
9 |
|
$this->classCount = 0; |
28
|
9 |
|
$this->publicFunctionCount = 0; |
29
|
9 |
|
$this->publicAttributeCount = 0; |
30
|
9 |
|
$this->publicTypedAttributes = 0; |
31
|
9 |
|
$this->protectedFunctionCount = 0; |
32
|
9 |
|
$this->protectedAttributeCount = 0; |
33
|
9 |
|
$this->protectedTypedAttributes = 0; |
34
|
9 |
|
$this->privateFunctionCount = 0; |
35
|
9 |
|
$this->privateAttributeCount = 0; |
36
|
9 |
|
$this->privateTypedAttributes = 0; |
37
|
9 |
|
} |
38
|
|
|
|
39
|
9 |
|
public function from(Structure $structure): void |
40
|
|
|
{ |
41
|
9 |
|
foreach ($structure->definitions() as $definition) { |
42
|
9 |
|
if ($definition instanceof InterfaceDefinition) { |
43
|
3 |
|
$this->interfaceCount++; |
44
|
|
|
} |
45
|
9 |
|
if ($definition instanceof ClassDefinition) { |
46
|
9 |
|
$this->classCount++; |
47
|
9 |
|
$this->attributesSummary($definition); |
48
|
|
|
} |
49
|
9 |
|
$this->methodsSummary($definition); |
50
|
|
|
} |
51
|
9 |
|
} |
52
|
|
|
|
53
|
9 |
|
private function attributesSummary(ClassDefinition $definition): void |
54
|
|
|
{ |
55
|
9 |
|
foreach ($definition->attributes as $attribute) { |
56
|
9 |
|
switch ($attribute->modifier) { |
57
|
3 |
|
case 'public': |
58
|
6 |
|
$this->publicAttributeCount++; |
59
|
6 |
|
if ($attribute->type->isPresent()) { |
60
|
3 |
|
$this->publicTypedAttributes++; |
61
|
|
|
} |
62
|
6 |
|
break; |
63
|
3 |
|
case 'protected': |
64
|
6 |
|
$this->protectedAttributeCount++; |
65
|
6 |
|
if ($attribute->type->isPresent()) { |
66
|
3 |
|
$this->protectedTypedAttributes++; |
67
|
|
|
} |
68
|
6 |
|
break; |
69
|
3 |
|
case 'private': |
70
|
9 |
|
$this->privateAttributeCount++; |
71
|
9 |
|
if ($attribute->type->isPresent()) { |
72
|
3 |
|
$this->privateTypedAttributes++; |
73
|
|
|
} |
74
|
9 |
|
break; |
75
|
|
|
} |
76
|
|
|
} |
77
|
9 |
|
} |
78
|
|
|
|
79
|
9 |
|
private function methodsSummary(Definition $definition): void |
80
|
|
|
{ |
81
|
9 |
|
foreach ($definition->functions as $function) { |
82
|
9 |
|
switch ($function->modifier) { |
83
|
3 |
|
case 'public': |
84
|
9 |
|
$this->publicFunctionCount++; |
85
|
9 |
|
break; |
86
|
3 |
|
case 'protected': |
87
|
3 |
|
$this->protectedFunctionCount++; |
88
|
3 |
|
break; |
89
|
3 |
|
case 'private': |
90
|
9 |
|
$this->privateFunctionCount++; |
91
|
9 |
|
break; |
92
|
|
|
} |
93
|
|
|
} |
94
|
9 |
|
} |
95
|
|
|
|
96
|
9 |
|
public function interfaceCount(): int |
97
|
|
|
{ |
98
|
9 |
|
return $this->interfaceCount; |
99
|
|
|
} |
100
|
|
|
|
101
|
9 |
|
public function classCount(): int |
102
|
|
|
{ |
103
|
9 |
|
return $this->classCount; |
104
|
|
|
} |
105
|
|
|
|
106
|
9 |
|
public function publicFunctionCount(): int |
107
|
|
|
{ |
108
|
9 |
|
return $this->publicFunctionCount; |
109
|
|
|
} |
110
|
|
|
|
111
|
9 |
|
public function publicAttributeCount(): int |
112
|
|
|
{ |
113
|
9 |
|
return $this->publicAttributeCount; |
114
|
|
|
} |
115
|
|
|
|
116
|
3 |
|
public function publicTypedAttributes(): int |
117
|
|
|
{ |
118
|
3 |
|
return $this->publicTypedAttributes; |
119
|
|
|
} |
120
|
|
|
|
121
|
9 |
|
public function protectedFunctionCount(): int |
122
|
|
|
{ |
123
|
9 |
|
return $this->protectedFunctionCount; |
124
|
|
|
} |
125
|
|
|
|
126
|
9 |
|
public function protectedAttributeCount(): int |
127
|
|
|
{ |
128
|
9 |
|
return $this->protectedAttributeCount; |
129
|
|
|
} |
130
|
|
|
|
131
|
3 |
|
public function protectedTypedAttributes(): int |
132
|
|
|
{ |
133
|
3 |
|
return $this->protectedTypedAttributes; |
134
|
|
|
} |
135
|
|
|
|
136
|
9 |
|
public function privateFunctionCount(): int |
137
|
|
|
{ |
138
|
9 |
|
return $this->privateFunctionCount; |
139
|
|
|
} |
140
|
|
|
|
141
|
9 |
|
public function privateAttributeCount(): int |
142
|
|
|
{ |
143
|
9 |
|
return $this->privateAttributeCount; |
144
|
|
|
} |
145
|
|
|
|
146
|
3 |
|
public function privateTypedAttributes(): int |
147
|
|
|
{ |
148
|
3 |
|
return $this->privateTypedAttributes; |
149
|
|
|
} |
150
|
|
|
|
151
|
9 |
|
public function functionCount(): int |
152
|
|
|
{ |
153
|
9 |
|
return $this->publicFunctionCount + $this->protectedFunctionCount + $this->privateFunctionCount; |
154
|
|
|
} |
155
|
|
|
|
156
|
9 |
|
public function attributeCount(): int |
157
|
|
|
{ |
158
|
9 |
|
return $this->publicAttributeCount + $this->protectedAttributeCount + $this->privateAttributeCount; |
159
|
|
|
} |
160
|
|
|
|
161
|
9 |
|
public function typedAttributeCount(): int |
162
|
|
|
{ |
163
|
9 |
|
return $this->publicTypedAttributes + $this->protectedTypedAttributes + $this->privateTypedAttributes; |
164
|
|
|
} |
165
|
|
|
|
166
|
9 |
|
public function attributesPerClass(): float |
167
|
|
|
{ |
168
|
9 |
|
return round($this->attributeCount() / $this->classCount, 2); |
169
|
|
|
} |
170
|
|
|
|
171
|
9 |
|
public function functionsPerClass(): float |
172
|
|
|
{ |
173
|
9 |
|
return round($this->functionCount() / $this->classCount, 2); |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
|