@@ -240,14 +240,10 @@ public function explain()
240240 $ sniffs = array_keys ($ this ->sniffCodes );
241241 sort ($ sniffs );
242242
243- ob_start ( );
243+ $ sniffCount = count ( $ sniffs );
244244
245- $ lastStandard = null ;
246- $ lastCount = 0 ;
247- $ sniffCount = count ($ sniffs );
248-
249- // Add a dummy entry to the end so we loop
250- // one last time and clear the output buffer.
245+ // Add a dummy entry to the end so we loop one last time
246+ // and echo out the collected info about the last standard.
251247 $ sniffs [] = '' ;
252248
253249 $ summaryLine = PHP_EOL ."The $ this ->name standard contains 1 sniff " .PHP_EOL ;
@@ -257,7 +253,9 @@ public function explain()
257253
258254 echo $ summaryLine ;
259255
260- ob_start ();
256+ $ lastStandard = null ;
257+ $ lastCount = 0 ;
258+ $ sniffsInStandard = [];
261259
262260 foreach ($ sniffs as $ i => $ sniff ) {
263261 if ($ i === $ sniffCount ) {
@@ -269,32 +267,31 @@ public function explain()
269267 }
270268 }
271269
270+ // Reached the first item in the next standard.
271+ // Echo out the info collected from the previous standard.
272272 if ($ currentStandard !== $ lastStandard ) {
273- $ sniffList = ob_get_contents ();
274- ob_end_clean ();
275-
276- echo PHP_EOL .$ lastStandard .' ( ' .$ lastCount .' sniff ' ;
273+ $ subTitle = $ lastStandard .' ( ' .$ lastCount .' sniff ' ;
277274 if ($ lastCount > 1 ) {
278- echo 's ' ;
275+ $ subTitle .= 's ' ;
279276 }
280277
281- echo ') ' .PHP_EOL ;
282- echo str_repeat ('- ' , (strlen ($ lastStandard .$ lastCount ) + 10 ));
283- echo PHP_EOL ;
284- echo $ sniffList ;
278+ $ subTitle .= ') ' ;
285279
286- $ lastStandard = $ currentStandard ;
287- $ lastCount = 0 ;
280+ echo PHP_EOL .$ subTitle .PHP_EOL ;
281+ echo str_repeat ('- ' , strlen ($ subTitle )).PHP_EOL ;
282+ echo ' ' .implode (PHP_EOL .' ' , $ sniffsInStandard ).PHP_EOL ;
283+
284+ $ lastStandard = $ currentStandard ;
285+ $ lastCount = 0 ;
286+ $ sniffsInStandard = [];
288287
289288 if ($ currentStandard === null ) {
290289 break ;
291290 }
292-
293- ob_start ();
294291 }//end if
295292
296- echo ' ' . $ sniff. PHP_EOL ;
297- $ lastCount ++ ;
293+ $ sniffsInStandard [] = $ sniff ;
294+ ++ $ lastCount ;
298295 }//end foreach
299296
300297 }//end explain()
0 commit comments