1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/** |
3
|
|
|
* This source file is subject to the license that is bundled with this package in the file LICENSE. |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace PhUml\Code; |
7
|
|
|
|
8
|
|
|
use PhUml\Code\Modifiers\Visibility; |
|
|
|
|
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* It creates a summary of the classes, interfaces, methods, and properties of a codebase |
12
|
|
|
* |
13
|
|
|
* The summary of a `Structure` does not include counts of constants |
14
|
|
|
*/ |
15
|
|
|
final class Summary |
16
|
|
|
{ |
17
|
|
|
/** @noRector \Rector\Php81\Rector\Property\ReadOnlyPropertyRector */ |
18
|
|
|
private int $interfaceCount; |
19
|
|
|
|
20
|
|
|
/** @noRector \Rector\Php81\Rector\Property\ReadOnlyPropertyRector */ |
21
|
|
|
private int $classCount; |
22
|
|
|
|
23
|
|
|
private int $publicFunctionCount; |
24
|
|
|
|
25
|
|
|
private int $publicPropertyCount; |
26
|
|
|
|
27
|
|
|
private int $publicTypedProperties; |
28
|
|
|
|
29
|
|
|
private int $protectedFunctionCount; |
30
|
|
|
|
31
|
|
|
private int $protectedPropertyCount; |
32
|
|
|
|
33
|
|
|
private int $protectedTypedProperties; |
34
|
|
|
|
35
|
|
|
private int $privateFunctionCount; |
36
|
|
|
|
37
|
|
|
private int $privatePropertyCount; |
38
|
|
|
|
39
|
|
|
private int $privateTypedProperties; |
40
|
|
|
|
41
|
9 |
|
public static function from(Codebase $codebase): Summary |
42
|
|
|
{ |
43
|
9 |
|
return new Summary($codebase); |
44
|
|
|
} |
45
|
|
|
|
46
|
9 |
|
private function __construct(Codebase $codebase) |
47
|
|
|
{ |
48
|
9 |
|
$this->interfaceCount = 0; |
49
|
9 |
|
$this->classCount = 0; |
50
|
9 |
|
$this->publicFunctionCount = 0; |
51
|
9 |
|
$this->publicPropertyCount = 0; |
52
|
9 |
|
$this->publicTypedProperties = 0; |
53
|
9 |
|
$this->protectedFunctionCount = 0; |
54
|
9 |
|
$this->protectedPropertyCount = 0; |
55
|
9 |
|
$this->protectedTypedProperties = 0; |
56
|
9 |
|
$this->privateFunctionCount = 0; |
57
|
9 |
|
$this->privatePropertyCount = 0; |
58
|
9 |
|
$this->privateTypedProperties = 0; |
59
|
9 |
|
foreach ($codebase->definitions() as $definition) { |
60
|
7 |
|
if ($definition instanceof InterfaceDefinition) { |
61
|
4 |
|
$this->interfaceCount++; |
62
|
|
|
} |
63
|
7 |
|
if ($definition instanceof ClassDefinition) { |
64
|
7 |
|
$this->classCount++; |
65
|
7 |
|
$this->propertiesSummary($definition); |
66
|
|
|
} |
67
|
7 |
|
$this->methodsSummary($definition); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
7 |
|
private function propertiesSummary(ClassDefinition $definition): void |
72
|
|
|
{ |
73
|
|
|
// Properties count |
74
|
7 |
|
$this->publicPropertyCount += $definition->countPropertiesByVisibility(Visibility::PUBLIC); |
75
|
7 |
|
$this->protectedPropertyCount += $definition->countPropertiesByVisibility(Visibility::PROTECTED); |
76
|
7 |
|
$this->privatePropertyCount += $definition->countPropertiesByVisibility(Visibility::PRIVATE); |
77
|
|
|
|
78
|
|
|
// Typed properties count |
79
|
7 |
|
$this->publicTypedProperties += $definition->countTypedPropertiesByVisibility(Visibility::PUBLIC); |
80
|
7 |
|
$this->protectedTypedProperties += $definition->countTypedPropertiesByVisibility(Visibility::PROTECTED); |
81
|
7 |
|
$this->privateTypedProperties += $definition->countTypedPropertiesByVisibility(Visibility::PRIVATE); |
82
|
|
|
} |
83
|
|
|
|
84
|
7 |
|
private function methodsSummary(Definition $definition): void |
85
|
|
|
{ |
86
|
7 |
|
$this->publicFunctionCount += $definition->countMethodsByVisibility(Visibility::PUBLIC); |
87
|
7 |
|
$this->protectedFunctionCount += $definition->countMethodsByVisibility(Visibility::PROTECTED); |
88
|
7 |
|
$this->privateFunctionCount += $definition->countMethodsByVisibility(Visibility::PRIVATE); |
89
|
|
|
} |
90
|
|
|
|
91
|
6 |
|
public function interfaceCount(): int |
92
|
|
|
{ |
93
|
6 |
|
return $this->interfaceCount; |
94
|
|
|
} |
95
|
|
|
|
96
|
6 |
|
public function classCount(): int |
97
|
|
|
{ |
98
|
6 |
|
return $this->classCount; |
99
|
|
|
} |
100
|
|
|
|
101
|
6 |
|
public function publicFunctionCount(): int |
102
|
|
|
{ |
103
|
6 |
|
return $this->publicFunctionCount; |
104
|
|
|
} |
105
|
|
|
|
106
|
6 |
|
public function publicPropertyCount(): int |
107
|
|
|
{ |
108
|
6 |
|
return $this->publicPropertyCount; |
109
|
|
|
} |
110
|
|
|
|
111
|
2 |
|
public function publicTypedProperties(): int |
112
|
|
|
{ |
113
|
2 |
|
return $this->publicTypedProperties; |
114
|
|
|
} |
115
|
|
|
|
116
|
6 |
|
public function protectedFunctionCount(): int |
117
|
|
|
{ |
118
|
6 |
|
return $this->protectedFunctionCount; |
119
|
|
|
} |
120
|
|
|
|
121
|
6 |
|
public function protectedPropertyCount(): int |
122
|
|
|
{ |
123
|
6 |
|
return $this->protectedPropertyCount; |
124
|
|
|
} |
125
|
|
|
|
126
|
3 |
|
public function protectedTypedProperties(): int |
127
|
|
|
{ |
128
|
3 |
|
return $this->protectedTypedProperties; |
129
|
|
|
} |
130
|
|
|
|
131
|
6 |
|
public function privateFunctionCount(): int |
132
|
|
|
{ |
133
|
6 |
|
return $this->privateFunctionCount; |
134
|
|
|
} |
135
|
|
|
|
136
|
6 |
|
public function privatePropertyCount(): int |
137
|
|
|
{ |
138
|
6 |
|
return $this->privatePropertyCount; |
139
|
|
|
} |
140
|
|
|
|
141
|
2 |
|
public function privateTypedProperties(): int |
142
|
|
|
{ |
143
|
2 |
|
return $this->privateTypedProperties; |
144
|
|
|
} |
145
|
|
|
|
146
|
7 |
|
public function functionCount(): int |
147
|
|
|
{ |
148
|
7 |
|
return $this->publicFunctionCount + $this->protectedFunctionCount + $this->privateFunctionCount; |
149
|
|
|
} |
150
|
|
|
|
151
|
7 |
|
public function propertiesCount(): int |
152
|
|
|
{ |
153
|
7 |
|
return $this->publicPropertyCount + $this->protectedPropertyCount + $this->privatePropertyCount; |
154
|
|
|
} |
155
|
|
|
|
156
|
6 |
|
public function typedPropertiesCount(): int |
157
|
|
|
{ |
158
|
6 |
|
return $this->publicTypedProperties + $this->protectedTypedProperties + $this->privateTypedProperties; |
159
|
|
|
} |
160
|
|
|
|
161
|
7 |
|
public function propertiesPerClass(): float |
162
|
|
|
{ |
163
|
7 |
|
if ($this->classCount === 0) { |
164
|
2 |
|
return 0; |
165
|
|
|
} |
166
|
|
|
|
167
|
5 |
|
return round($this->propertiesCount() / $this->classCount, 2); |
168
|
|
|
} |
169
|
|
|
|
170
|
7 |
|
public function functionsPerClass(): float |
171
|
|
|
{ |
172
|
7 |
|
if ($this->classCount === 0) { |
173
|
2 |
|
return 0; |
174
|
|
|
} |
175
|
|
|
|
176
|
5 |
|
return round($this->functionCount() / $this->classCount, 2); |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths