4646/**
4747 * Generates human readable output from an PHP_CodeCoverage object.
4848 *
49- * The output gets put into a text file our written to the cli
49+ * The output gets put into a text file our written to the CLI.
5050 *
5151 * @category PHP
5252 * @package CodeCoverage
@@ -66,19 +66,20 @@ class PHP_CodeCoverage_Report_Text
6666 protected $ showUncoveredFiles ;
6767
6868 protected $ colors = array (
69- 'green ' => "\x1b[30;42m " ,
70- 'yellow ' => "\x1b[30;43m " ,
71- 'red ' => "\x1b[37;41m " ,
72- 'header ' => "\x1b[47;40m " ,
73- 'reset ' => "\x1b[0m " ,
74- 'eol ' => "\x1b[2K " ,
69+ 'green ' => "\x1b[30;42m " ,
70+ 'yellow ' => "\x1b[30;43m " ,
71+ 'red ' => "\x1b[37;41m " ,
72+ 'header ' => "\x1b[47;40m " ,
73+ 'reset ' => "\x1b[0m " ,
74+ 'eol ' => "\x1b[2K " ,
7575 );
7676
77- public function __construct (PHPUnit_Util_Printer $ outputStream , $ title , $ lowUpperBound , $ highLowerBound , $ showUncoveredFiles ) {
78- $ this ->outputStream = $ outputStream ;
79- $ this ->title = $ title ;
80- $ this ->lowUpperBound = $ lowUpperBound ;
81- $ this ->highLowerBound = $ highLowerBound ;
77+ public function __construct (PHPUnit_Util_Printer $ outputStream , $ title , $ lowUpperBound , $ highLowerBound , $ showUncoveredFiles )
78+ {
79+ $ this ->outputStream = $ outputStream ;
80+ $ this ->title = $ title ;
81+ $ this ->lowUpperBound = $ lowUpperBound ;
82+ $ this ->highLowerBound = $ highLowerBound ;
8283 $ this ->showUncoveredFiles = $ showUncoveredFiles ;
8384 }
8485
@@ -88,34 +89,55 @@ public function __construct(PHPUnit_Util_Printer $outputStream, $title, $lowUppe
8889 * @param string $name
8990 * @return string
9091 */
91- public function process (PHP_CodeCoverage $ coverage , $ showColors = false )
92+ public function process (PHP_CodeCoverage $ coverage , $ showColors = FALSE )
9293 {
93- $ output = "" ;
94-
94+ $ output = '' ;
9595 $ packages = array ();
9696 $ report = $ coverage ->getReport ();
9797 unset($ coverage );
9898
99- $ colors = array ('header ' => '' , 'classes ' => '' , 'methods ' => '' , 'lines ' => '' , 'reset ' => '' , 'eol ' => '' );
100- if ($ showColors ) {
101- $ colors ['classes ' ] = $ this ->getCoverageColor ($ report ->getNumTestedClasses (), $ report ->getNumClasses ());
102- $ colors ['methods ' ] = $ this ->getCoverageColor ($ report ->getNumTestedMethods (), $ report ->getNumMethods ());
103- $ colors ['lines ' ] = $ this ->getCoverageColor ($ report ->getNumExecutedLines (), $ report ->getNumExecutableLines ());
104- $ colors ['reset ' ] = $ this ->colors ['reset ' ];
105- $ colors ['header ' ] = $ this ->colors ['header ' ];
106- $ colors ['eol ' ] = $ this ->colors ['eol ' ];
107- }
108-
109- $ output .= PHP_EOL . PHP_EOL . $ colors ['header ' ] . "Code Coverage Report " ;
110- if ($ this ->title ) {
99+ $ colors = array (
100+ 'header ' => '' ,
101+ 'classes ' => '' ,
102+ 'methods ' => '' ,
103+ 'lines ' => '' ,
104+ 'reset ' => '' ,
105+ 'eol ' => ''
106+ );
107+
108+ if ($ showColors ) {
109+ $ colors ['classes ' ] = $ this ->getCoverageColor (
110+ $ report ->getNumTestedClasses (),
111+ $ report ->getNumClasses ()
112+ );
113+ $ colors ['methods ' ] = $ this ->getCoverageColor (
114+ $ report ->getNumTestedMethods (),
115+ $ report ->getNumMethods ()
116+ );
117+ $ colors ['lines ' ] = $ this ->getCoverageColor (
118+ $ report ->getNumExecutedLines (),
119+ $ report ->getNumExecutableLines ()
120+ );
121+ $ colors ['reset ' ] = $ this ->colors ['reset ' ];
122+ $ colors ['header ' ] = $ this ->colors ['header ' ];
123+ $ colors ['eol ' ] = $ this ->colors ['eol ' ];
124+ }
125+
126+ $ output .= PHP_EOL . PHP_EOL .
127+ $ colors ['header ' ] . 'Code Coverage Report ' ;
128+
129+ if ($ this ->title ) {
111130 $ output .= 'for " ' . $ this ->title . '" ' ;
112131 }
113- $ output .= PHP_EOL . date (" Y-m-d H:i:s " , $ _SERVER ['REQUEST_TIME ' ]) . PHP_EOL ;
132+
133+ $ output .= PHP_EOL .
134+ date (' Y-m-d H:i:s ' , $ _SERVER ['REQUEST_TIME ' ]) .
135+ PHP_EOL ;
114136
115137 $ output .= PHP_EOL . ' Summary: ' . PHP_EOL . $ colors ['reset ' ]
116138 . $ colors ['classes ' ] . $ colors ['eol ' ] . ' Classes: ' . PHP_CodeCoverage_Util::percent ($ report ->getNumTestedClasses (), $ report ->getNumClasses (), TRUE )
117139 . ' ( ' . $ report ->getNumTestedClasses () . '/ ' . $ report ->getNumClasses () . ') ' . PHP_EOL . $ colors ['eol ' ]
118- . $ colors ['methods ' ] . $ colors ['eol ' ] . ' Methods: ' . PHP_CodeCoverage_Util::percent ($ report ->getNumTestedMethods (), $ report ->getNumMethods (), TRUE )
140+ . $ colors ['methods ' ] . $ colors ['eol ' ] . ' Methods: ' . PHP_CodeCoverage_Util::percent ($ report ->getNumTestedMethods (), $ report ->getNumMethods (), TRUE )
119141 . ' ( ' . $ report ->getNumTestedMethods () . '/ ' . $ report ->getNumMethods () . ') ' . PHP_EOL . $ colors ['eol ' ]
120142 . $ colors ['lines ' ] . $ colors ['eol ' ] . ' Lines: ' . PHP_CodeCoverage_Util::percent ($ report ->getNumExecutedLines (), $ report ->getNumExecutableLines (), TRUE )
121143 . ' ( ' . $ report ->getNumExecutedLines () . '/ ' . $ report ->getNumExecutableLines () . ') ' . PHP_EOL . $ colors ['reset ' ] . $ colors ['eol ' ];
@@ -187,34 +209,43 @@ public function process(PHP_CodeCoverage $coverage, $showColors = false)
187209
188210 if (!empty ($ class ['package ' ]['namespace ' ])) {
189211 $ namespace = '\\' . $ class ['package ' ]['namespace ' ] . ':: ' ;
190- } else if (!empty ($ class ['package ' ]['fullPackage ' ])) {
212+ }
213+
214+ else if (!empty ($ class ['package ' ]['fullPackage ' ])) {
191215 $ namespace = '@ ' . $ class ['package ' ]['fullPackage ' ] . ':: ' ;
192- } else {
216+ }
217+
218+ else {
193219 $ namespace = '' ;
194220 }
195221
196222 $ classCoverage [$ namespace . $ className ] = array (
197- 'namespace ' => $ namespace ,
198- 'className ' => $ className ,
199- 'methodsCovered ' => $ coveredMethods ,
200- 'methodCount ' => count ($ class ['methods ' ]),
223+ 'namespace ' => $ namespace ,
224+ 'className ' => $ className ,
225+ 'methodsCovered ' => $ coveredMethods ,
226+ 'methodCount ' => count ($ class ['methods ' ]),
201227 'statementsCovered ' => $ coveredClassStatements ,
202- 'statementCount ' => $ classStatements ,
203- );
228+ 'statementCount ' => $ classStatements ,
229+ );
204230 }
205231 }
232+
206233 ksort ($ classCoverage );
207234
208235 $ methodColor = '' ;
209- $ linesColor = '' ;
210- $ resetColor = '' ;
211- foreach ($ classCoverage as $ fullQualifiedPath => $ classInfo ) {
212- if ($ classInfo ['statementsCovered ' ] != 0 || $ this ->showUncoveredFiles ) {
213- if ($ showColors ) {
236+ $ linesColor = '' ;
237+ $ resetColor = '' ;
238+
239+ foreach ($ classCoverage as $ fullQualifiedPath => $ classInfo ) {
240+ if ($ classInfo ['statementsCovered ' ] != 0 ||
241+ $ this ->showUncoveredFiles ) {
242+
243+ if ($ showColors ) {
214244 $ methodColor = $ this ->getCoverageColor ($ classInfo ['methodsCovered ' ], $ classInfo ['methodCount ' ]);
215- $ linesColor = $ this ->getCoverageColor ($ classInfo ['statementsCovered ' ], $ classInfo ['statementCount ' ]);
216- $ resetColor = $ colors ['reset ' ];
245+ $ linesColor = $ this ->getCoverageColor ($ classInfo ['statementsCovered ' ], $ classInfo ['statementCount ' ]);
246+ $ resetColor = $ colors ['reset ' ];
217247 }
248+
218249 $ output .= PHP_EOL . $ fullQualifiedPath . PHP_EOL
219250 . ' ' . $ methodColor . 'Methods: ' . $ this ->printCoverageCounts ($ classInfo ['methodsCovered ' ], $ classInfo ['methodCount ' ], 2 ) . $ resetColor . ' '
220251 . ' ' . $ linesColor . 'Lines: ' . $ this ->printCoverageCounts ($ classInfo ['statementsCovered ' ], $ classInfo ['statementCount ' ], 3 ) . $ resetColor
@@ -223,25 +254,31 @@ public function process(PHP_CodeCoverage $coverage, $showColors = false)
223254 }
224255
225256 $ this ->outputStream ->write ($ output );
226- return ;
227-
228257 }
229258
230259 protected function getCoverageColor ($ numberOfCoveredElements , $ totalNumberOfElements ) {
231- $ coverage = PHP_CodeCoverage_Util::percent ($ numberOfCoveredElements , $ totalNumberOfElements );
232- if ($ coverage > $ this ->highLowerBound ) {
260+ $ coverage = PHP_CodeCoverage_Util::percent (
261+ $ numberOfCoveredElements , $ totalNumberOfElements
262+ );
263+
264+ if ($ coverage > $ this ->highLowerBound ) {
233265 return $ this ->colors ['green ' ];
234- } else if ($ coverage > $ this ->lowUpperBound ) {
266+ }
267+
268+ else if ($ coverage > $ this ->lowUpperBound ) {
235269 return $ this ->colors ['yellow ' ];
236270 }
271+
237272 return $ this ->colors ['red ' ];
238273 }
239274
240275 protected function printCoverageCounts ($ numberOfCoveredElements , $ totalNumberOfElements , $ presicion ) {
241276 $ format = '% ' . $ presicion . 's ' ;
242- return PHP_CodeCoverage_Util::percent ($ numberOfCoveredElements , $ totalNumberOfElements , TRUE , TRUE )
243- . ' ( ' . sprintf ($ format , $ numberOfCoveredElements ) . '/ ' . sprintf ($ format , $ totalNumberOfElements ) . ') ' ;
244- }
245277
278+ return PHP_CodeCoverage_Util::percent (
279+ $ numberOfCoveredElements , $ totalNumberOfElements , TRUE , TRUE
280+ ) .
281+ ' ( ' . sprintf ($ format , $ numberOfCoveredElements ) . '/ ' .
282+ sprintf ($ format , $ totalNumberOfElements ) . ') ' ;
283+ }
246284}
247-
0 commit comments