|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use PhUml\Code\ClassDefinition; |
|
4
|
|
|
use PhUml\Code\InterfaceDefinition; |
|
5
|
|
|
|
|
6
|
|
|
class plStatisticsProcessor extends plProcessor |
|
7
|
|
|
{ |
|
8
|
|
|
private $information; |
|
9
|
|
|
public $options; |
|
10
|
|
|
|
|
11
|
6 |
|
public function __construct() |
|
12
|
|
|
{ |
|
13
|
6 |
|
$this->options = new plProcessorOptions(); |
|
14
|
6 |
|
$this->information = array(); |
|
15
|
6 |
|
} |
|
16
|
|
|
|
|
17
|
3 |
|
public function name(): string |
|
18
|
|
|
{ |
|
19
|
3 |
|
return 'Statistics'; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
15 |
|
public function getInputType(): string |
|
23
|
|
|
{ |
|
24
|
15 |
|
return 'application/phuml-structure'; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
9 |
|
public function getOutputType(): string |
|
28
|
|
|
{ |
|
29
|
9 |
|
return 'text/plain'; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function process($input) |
|
33
|
|
|
{ |
|
34
|
|
|
// Initialize the values |
|
35
|
|
|
$this->information['interfaceCount'] = 0; |
|
36
|
|
|
$this->information['classCount'] = 0; |
|
37
|
|
|
$this->information['publicFunctionCount'] = 0; |
|
38
|
|
|
$this->information['publicAttributeCount'] = 0; |
|
39
|
|
|
$this->information['publicTypedAttributes'] = 0; |
|
40
|
|
|
$this->information['protectedFunctionCount'] = 0; |
|
41
|
|
|
$this->information['protectedAttributeCount'] = 0; |
|
42
|
|
|
$this->information['protectedTypedAttributes'] = 0; |
|
43
|
|
|
$this->information['privateFunctionCount'] = 0; |
|
44
|
|
|
$this->information['privateAttributeCount'] = 0; |
|
45
|
|
|
$this->information['privateTypedAttributes'] = 0; |
|
46
|
|
|
|
|
47
|
|
|
// Loop through the classes and interfaces |
|
48
|
|
|
foreach ($input->definitions() as $definition) { |
|
49
|
|
|
if ($definition instanceof InterfaceDefinition) { |
|
50
|
|
|
$this->information['interfaceCount']++; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
if ($definition instanceof ClassDefinition) { |
|
54
|
|
|
$this->information['classCount']++; |
|
55
|
|
|
|
|
56
|
|
|
foreach ($definition->attributes as $attribute) { |
|
57
|
|
|
switch ($attribute->modifier) { |
|
58
|
|
|
case 'public': |
|
59
|
|
|
$this->information['publicAttributeCount']++; |
|
60
|
|
|
if ($attribute->type->isPresent()) { |
|
61
|
|
|
$this->information['publicTypedAttributes']++; |
|
62
|
|
|
} |
|
63
|
|
|
break; |
|
64
|
|
|
case 'protected': |
|
65
|
|
|
$this->information['protectedAttributeCount']++; |
|
66
|
|
|
if ($attribute->type->isPresent()) { |
|
67
|
|
|
$this->information['protectedTypedAttributes']++; |
|
68
|
|
|
} |
|
69
|
|
|
break; |
|
70
|
|
|
case 'private': |
|
71
|
|
|
$this->information['privateAttributeCount']++; |
|
72
|
|
|
if ($attribute->type->isPresent()) { |
|
73
|
|
|
$this->information['privateTypedAttributes']++; |
|
74
|
|
|
} |
|
75
|
|
|
break; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
foreach ($definition->functions as $function) { |
|
81
|
|
|
switch ($function->modifier) { |
|
82
|
|
|
case 'public': |
|
83
|
|
|
$this->information['publicFunctionCount']++; |
|
84
|
|
|
break; |
|
85
|
|
|
case 'protected': |
|
86
|
|
|
$this->information['protectedFunctionCount']++; |
|
87
|
|
|
break; |
|
88
|
|
|
case 'private': |
|
89
|
|
|
$this->information['privateFunctionCount']++; |
|
90
|
|
|
break; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
$this->information['functionCount'] = $this->information['publicFunctionCount'] + $this->information['protectedFunctionCount'] + $this->information['privateFunctionCount']; |
|
96
|
|
|
$this->information['attributeCount'] = $this->information['publicAttributeCount'] + $this->information['protectedAttributeCount'] + $this->information['privateAttributeCount']; |
|
97
|
|
|
$this->information['typedAttributeCount'] = $this->information['publicTypedAttributes'] + $this->information['protectedTypedAttributes'] + $this->information['privateTypedAttributes']; |
|
98
|
|
|
$this->information['attributesPerClass'] = round($this->information['attributeCount'] / $this->information['classCount'], 2); |
|
99
|
|
|
$this->information['functionsPerClass'] = round($this->information['functionCount'] / $this->information['classCount'], 2); |
|
100
|
|
|
|
|
101
|
|
|
// Generate the needed text output |
|
102
|
|
|
return <<<END |
|
103
|
|
|
Phuml generated statistics |
|
104
|
|
|
========================== |
|
105
|
|
|
|
|
106
|
|
|
General statistics |
|
107
|
|
|
------------------ |
|
108
|
|
|
|
|
109
|
|
|
Classes: {$this->information['classCount']} |
|
110
|
|
|
Interfaces: {$this->information['interfaceCount']} |
|
111
|
|
|
|
|
112
|
|
|
Attributes: {$this->information['attributeCount']} ({$this->information['typedAttributeCount']} are typed) |
|
113
|
|
|
* private: {$this->information['privateAttributeCount']} |
|
114
|
|
|
* protected: {$this->information['protectedAttributeCount']} |
|
115
|
|
|
* public: {$this->information['publicAttributeCount']} |
|
116
|
|
|
|
|
117
|
|
|
Functions: {$this->information['functionCount']} |
|
118
|
|
|
* private: {$this->information['privateFunctionCount']} |
|
119
|
|
|
* protected: {$this->information['protectedFunctionCount']} |
|
120
|
|
|
* public: {$this->information['publicFunctionCount']} |
|
121
|
|
|
|
|
122
|
|
|
Average statistics |
|
123
|
|
|
------------------ |
|
124
|
|
|
|
|
125
|
|
|
Attributes per class: {$this->information['attributesPerClass']} |
|
126
|
|
|
Functions per class: {$this->information['functionsPerClass']} |
|
127
|
|
|
|
|
128
|
|
|
END; |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|