4
4
* PHP_CodeCoverage_Report_Crap4j
5
5
*
6
6
* @author oker <[email protected] >
7
+ * @author pepov <[email protected] >
7
8
*/
8
9
class PHP_CodeCoverage_Report_Crap4j
9
10
{
10
- private $ treshHold = 30 ;
11
+ private $ treshHold = 30 ;
11
12
12
13
/**
13
14
* @param PHP_CodeCoverage $coverage
@@ -27,15 +28,15 @@ public function process(PHP_CodeCoverage $coverage, $target = NULL, $name = NULL
27
28
$ root ->appendChild ($ project );
28
29
$ root ->appendChild ($ document ->createElement ('timestamp ' , date ('Y-m-d H:i:s ' , (int )$ _SERVER ['REQUEST_TIME ' ])));
29
30
30
- $ stats = $ document ->createElement ('stats ' );
31
+ $ stats = $ document ->createElement ('stats ' );
31
32
$ methodsNode = $ document ->createElement ('methods ' );
32
33
33
34
$ files = $ coverage ->getSummary ();
34
35
35
- $ fullMethodCount = 0 ;
36
- $ fullCrapMethodCount = 0 ;
37
- $ fullCrapLoad = 0 ;
38
- $ fullCrap = 0 ;
36
+ $ fullMethodCount = 0 ;
37
+ $ fullCrapMethodCount = 0 ;
38
+ $ fullCrapLoad = 0 ;
39
+ $ fullCrap = 0 ;
39
40
40
41
foreach ($ files as $ filename => $ data ) {
41
42
@@ -77,34 +78,34 @@ public function process(PHP_CodeCoverage $coverage, $target = NULL, $name = NULL
77
78
78
79
foreach ($ _class ['methods ' ] as $ methodName => $ method ) {
79
80
80
- $ methodCount = 0 ;
81
- $ methodLines = 0 ;
82
- $ methodLinesCovered = 0 ;
83
- $ this ->methodsDetails ($ method , $ ignoredLines , $ files , $ filename , $ classStatistics , $ lines , $ methodCount , $ methodLines , $ methodLinesCovered );
81
+ $ methodCount = 0 ;
82
+ $ methodLines = 0 ;
83
+ $ methodLinesCovered = 0 ;
84
+ $ this ->methodsDetails ($ method , $ ignoredLines , $ files , $ filename , $ classStatistics , $ lines , $ methodCount , $ methodLines , $ methodLinesCovered );
84
85
85
- $ fullMethodCount ++;
86
+ $ fullMethodCount ++;
86
87
87
88
$ coveragePercent = PHP_CodeCoverage_Util::percent (
88
89
$ methodLinesCovered ,
89
90
$ methodLines
90
91
);
91
92
$ crap = PHP_CodeCoverage_Util::crap ($ method ['ccn ' ], $ coveragePercent );
92
- $ fullCrap += $ crap ;
93
+ $ fullCrap += $ crap ;
93
94
94
- if ($ crap >= $ this ->treshHold ) {
95
- $ fullCrapMethodCount ++;
96
- }
95
+ if ($ crap >= $ this ->treshHold ) {
96
+ $ fullCrapMethodCount ++;
97
+ }
97
98
98
- $ crapLoad = $ this ->getCrapLoad ($ crap , $ method ['ccn ' ], $ coveragePercent );
99
+ $ crapLoad = $ this ->getCrapLoad ($ crap , $ method ['ccn ' ], $ coveragePercent );
99
100
100
- $ fullCrapLoad += $ crapLoad ;
101
+ $ fullCrapLoad += $ crapLoad ;
101
102
102
103
$ methodNode = $ document ->createElement ('method ' );
103
104
104
105
$ methodNode ->appendChild ($ document ->createElement ('package ' , '' ));
105
106
$ methodNode ->appendChild ($ document ->createElement ('className ' , $ className ));
106
107
$ methodNode ->appendChild ($ document ->createElement ('methodName ' , $ methodName ));
107
- $ methodNode ->appendChild ($ document ->createElement ('methodSignature ' , htmlspecialchars ($ method ['signature ' ])));
108
+ $ methodNode ->appendChild ($ document ->createElement ('methodSignature ' , htmlspecialchars ($ method ['signature ' ])));
108
109
$ methodNode ->appendChild ($ document ->createElement ('fullMethod ' , htmlspecialchars ($ method ['signature ' ])));
109
110
$ methodNode ->appendChild ($ document ->createElement ('crap ' , $ this ->roundValue ($ crap )));
110
111
$ methodNode ->appendChild ($ document ->createElement ('complexity ' , $ method ['ccn ' ]));
@@ -125,14 +126,14 @@ public function process(PHP_CodeCoverage $coverage, $target = NULL, $name = NULL
125
126
126
127
$ stats ->appendChild ($ document ->createElement ('name ' , 'Method Crap Stats ' ));
127
128
128
- $ stats ->appendChild ($ document ->createElement ('methodCount ' , $ fullMethodCount ));
129
- $ stats ->appendChild ($ document ->createElement ('crapMethodCount ' , $ fullCrapMethodCount ));
129
+ $ stats ->appendChild ($ document ->createElement ('methodCount ' , $ fullMethodCount ));
130
+ $ stats ->appendChild ($ document ->createElement ('crapMethodCount ' , $ fullCrapMethodCount ));
130
131
$ stats ->appendChild ($ document ->createElement ('crapLoad ' , round ($ fullCrapLoad )));
131
- $ stats ->appendChild ($ document ->createElement ('totalCrap ' , $ fullCrap ));
132
- $ stats ->appendChild ($ document ->createElement ('crapMethodPercent ' , $ this ->roundValue (100 * $ fullCrapMethodCount / $ fullMethodCount )));
132
+ $ stats ->appendChild ($ document ->createElement ('totalCrap ' , $ fullCrap ));
133
+ $ stats ->appendChild ($ document ->createElement ('crapMethodPercent ' , $ this ->roundValue (100 * $ fullCrapMethodCount / $ fullMethodCount )));
133
134
134
135
$ root ->appendChild ($ stats );
135
- $ root ->appendChild ($ methodsNode );
136
+ $ root ->appendChild ($ methodsNode );
136
137
137
138
if ($ target !== NULL ) {
138
139
if (!is_dir (dirname ($ target ))) {
@@ -145,57 +146,57 @@ public function process(PHP_CodeCoverage $coverage, $target = NULL, $name = NULL
145
146
}
146
147
}
147
148
148
- private function methodsDetails ($ method , $ ignoredLines , $ files , $ filename , $ classStatistics , $ lines , &$ methodCount , &$ methodLines , &$ methodLinesCovered )
149
- {
150
- for ($ i = $ method ['startLine ' ];
151
- $ i <= $ method ['endLine ' ];
152
- $ i ++) {
153
- if (isset ($ ignoredLines [$ i ])) {
154
- continue ;
155
- }
156
-
157
- $ add = TRUE ;
158
- $ count = 0 ;
159
-
160
- if (isset ($ files [$ filename ][$ i ])) {
161
- if ($ files [$ filename ][$ i ] != -2 ) {
162
- $ classStatistics ['statements ' ]++;
163
- $ methodLines ++;
164
- }
165
-
166
- if (is_array ($ files [$ filename ][$ i ])) {
167
- $ classStatistics ['coveredStatements ' ]++;
168
- $ methodLinesCovered ++;
169
- $ count = count ($ files [$ filename ][$ i ]);
170
- }
171
-
172
- else if ($ files [$ filename ][$ i ] == -2 ) {
173
- $ add = FALSE ;
174
- }
175
- } else {
176
- $ add = FALSE ;
177
- }
178
-
179
- $ methodCount = max ($ methodCount , $ count );
180
-
181
- if ($ add ) {
182
- $ lines [$ i ] = array (
183
- 'count ' => $ count ,
184
- 'type ' => 'stmt '
185
- );
186
- }
187
- }
188
- }
189
-
190
- public function getCrapLoad ($ crapValue , $ cyclomaticComplexity , $ coveragePercent )
191
- {
192
- $ crapLoad = 0 ;
193
- if ($ crapValue > $ this ->treshHold ) {
194
- $ crapLoad += $ cyclomaticComplexity * (1.0 - $ coveragePercent / 100 );
195
- $ crapLoad += $ cyclomaticComplexity / $ this ->treshHold ;
196
- }
197
- return $ crapLoad ;
198
- }
149
+ private function methodsDetails ($ method , $ ignoredLines , $ files , $ filename , $ classStatistics , $ lines , &$ methodCount , &$ methodLines , &$ methodLinesCovered )
150
+ {
151
+ for ($ i = $ method ['startLine ' ];
152
+ $ i <= $ method ['endLine ' ];
153
+ $ i ++) {
154
+ if (isset ($ ignoredLines [$ i ])) {
155
+ continue ;
156
+ }
157
+
158
+ $ add = TRUE ;
159
+ $ count = 0 ;
160
+
161
+ if (isset ($ files [$ filename ][$ i ])) {
162
+ if ($ files [$ filename ][$ i ] != -2 ) {
163
+ $ classStatistics ['statements ' ]++;
164
+ $ methodLines ++;
165
+ }
166
+
167
+ if (is_array ($ files [$ filename ][$ i ])) {
168
+ $ classStatistics ['coveredStatements ' ]++;
169
+ $ methodLinesCovered ++;
170
+ $ count = count ($ files [$ filename ][$ i ]);
171
+ }
172
+
173
+ else if ($ files [$ filename ][$ i ] == -2 ) {
174
+ $ add = FALSE ;
175
+ }
176
+ } else {
177
+ $ add = FALSE ;
178
+ }
179
+
180
+ $ methodCount = max ($ methodCount , $ count );
181
+
182
+ if ($ add ) {
183
+ $ lines [$ i ] = array (
184
+ 'count ' => $ count ,
185
+ 'type ' => 'stmt '
186
+ );
187
+ }
188
+ }
189
+ }
190
+
191
+ public function getCrapLoad ($ crapValue , $ cyclomaticComplexity , $ coveragePercent )
192
+ {
193
+ $ crapLoad = 0 ;
194
+ if ($ crapValue > $ this ->treshHold ) {
195
+ $ crapLoad += $ cyclomaticComplexity * (1.0 - $ coveragePercent / 100 );
196
+ $ crapLoad += $ cyclomaticComplexity / $ this ->treshHold ;
197
+ }
198
+ return $ crapLoad ;
199
+ }
199
200
200
201
private function roundValue ($ value )
201
202
{
0 commit comments