@@ -72,6 +72,145 @@ public function render(PHP_CodeCoverage_Report_Node_Directory $node, $file, $tit
72
72
73
73
$ this ->setCommonTemplateVariables ($ template , $ title );
74
74
75
+ $ items = $ this ->renderItem ($ node , TRUE );
76
+
77
+ foreach ($ node ->getDirectories () as $ item ) {
78
+ $ items .= $ this ->renderItem ($ item );
79
+ }
80
+
81
+ foreach ($ node ->getFiles () as $ item ) {
82
+ $ items .= $ this ->renderItem ($ item );
83
+ }
84
+
85
+ $ template ->setVar (
86
+ array (
87
+ 'id ' => PHP_CodeCoverage_Util::nodeToId ($ node ),
88
+ 'items ' => $ items
89
+ )
90
+ );
91
+
75
92
$ template ->renderTo ($ file );
76
93
}
94
+
95
+ /**
96
+ * @param PHP_CodeCoverage_Report_Node $item
97
+ * @param boolean $total
98
+ * @return string
99
+ */
100
+ protected function renderItem (PHP_CodeCoverage_Report_Node $ item , $ total = FALSE )
101
+ {
102
+ $ template = new Text_Template (
103
+ $ this ->templatePath . 'directory_item.html '
104
+ );
105
+
106
+ if ($ total ) {
107
+ $ icon = '' ;
108
+ $ itemClass = 'coverDirectory ' ;
109
+ $ name = 'Total ' ;
110
+ } else {
111
+ $ name = sprintf (
112
+ '<a href="%s.html">%s</a> ' ,
113
+ PHP_CodeCoverage_Util::nodeToId ($ item ),
114
+ $ item ->getName ()
115
+ );
116
+
117
+ if ($ item instanceof PHP_CodeCoverage_Report_Node_Directory) {
118
+ $ icon = '<img alt="directory" src="directory.png"/> ' ;
119
+ $ itemClass = 'coverDirectory ' ;
120
+ } else {
121
+ $ icon = '<img alt="file" src="file.png"/> ' ;
122
+ $ itemClass = 'coverFile ' ;
123
+ }
124
+ }
125
+
126
+ $ numClasses = $ item ->getNumClasses ();
127
+ $ testedClassesPercent = floor ($ item ->getTestedClassesPercent (FALSE ));
128
+
129
+ if ($ numClasses > 0 ) {
130
+ list ($ classesColor , $ classesLevel ) = $ this ->getColorLevel (
131
+ $ testedClassesPercent
132
+ );
133
+
134
+ $ classesNumber = $ item ->getNumTestedClasses () . ' / ' . $ numClasses ;
135
+ } else {
136
+ $ classesColor = 'snow ' ;
137
+ $ classesLevel = 'None ' ;
138
+ $ classesNumber = ' ' ;
139
+ }
140
+
141
+ $ numMethods = $ item ->getNumMethods ();
142
+ $ testedMethodsPercent = floor ($ item ->getTestedMethodsPercent (FALSE ));
143
+
144
+ if ($ numMethods > 0 ) {
145
+ list ($ methodsColor , $ methodsLevel ) = $ this ->getColorLevel (
146
+ $ testedMethodsPercent
147
+ );
148
+
149
+ $ methodsNumber = $ item ->getNumTestedMethods () . ' / ' . $ numMethods ;
150
+ } else {
151
+ $ methodsColor = 'snow ' ;
152
+ $ methodsLevel = 'None ' ;
153
+ $ methodsNumber = ' ' ;
154
+ }
155
+
156
+ $ linesExecutedPercent = floor ($ item ->getLineExecutedPercent (FALSE ));
157
+
158
+ list ($ linesColor , $ linesLevel ) = $ this ->getColorLevel (
159
+ $ linesExecutedPercent
160
+ );
161
+
162
+ $ template ->setVar (
163
+ array (
164
+ 'itemClass ' => $ itemClass ,
165
+ 'icon ' => $ icon ,
166
+ 'name ' => $ name ,
167
+ 'lines_color ' => $ linesColor ,
168
+ 'lines_executed_width ' => $ linesExecutedPercent ,
169
+ 'lines_not_executed_width ' => 100 - $ linesExecutedPercent ,
170
+ 'lines_executed_percent ' => $ item ->getLineExecutedPercent (),
171
+ 'lines_level ' => $ linesLevel ,
172
+ 'num_executed_lines ' => $ item ->getNumExecutedLines (),
173
+ 'num_executable_lines ' => $ item ->getNumExecutableLines (),
174
+ 'methods_color ' => $ methodsColor ,
175
+ 'methods_tested_width ' => $ testedMethodsPercent ,
176
+ 'methods_not_tested_width ' => 100 - $ testedMethodsPercent ,
177
+ 'methods_tested_percent ' => $ item ->getTestedMethodsPercent (),
178
+ 'methods_level ' => $ methodsLevel ,
179
+ 'methods_number ' => $ methodsNumber ,
180
+ 'classes_color ' => $ classesColor ,
181
+ 'classes_tested_width ' => $ testedClassesPercent ,
182
+ 'classes_not_tested_width ' => 100 - $ testedClassesPercent ,
183
+ 'classes_tested_percent ' => $ item ->getTestedClassesPercent (),
184
+ 'classes_level ' => $ classesLevel ,
185
+ 'classes_number ' => $ classesNumber
186
+ )
187
+ );
188
+
189
+ return $ template ->render ();
190
+ }
191
+
192
+ /**
193
+ * @param integer $percent
194
+ * @return array
195
+ */
196
+ protected function getColorLevel ($ percent )
197
+ {
198
+ if ($ percent < $ this ->lowUpperBound ) {
199
+ $ color = 'scarlet_red ' ;
200
+ $ level = 'Lo ' ;
201
+ }
202
+
203
+ else if ($ percent >= $ this ->lowUpperBound &&
204
+ $ percent < $ this ->highLowerBound ) {
205
+ $ color = 'butter ' ;
206
+ $ level = 'Med ' ;
207
+ }
208
+
209
+ else {
210
+ $ color = 'chameleon ' ;
211
+ $ level = 'Hi ' ;
212
+ }
213
+
214
+ return array ($ color , $ level );
215
+ }
77
216
}
0 commit comments