@@ -225,48 +225,10 @@ public function append(array $data, $id = NULL, array $filterGroups = array('DEF
225225 throw new InvalidArgumentException ;
226226 }
227227
228- foreach (array_keys ($ data ) as $ filename ) {
229- if (!$ this ->filter ->isFile ($ filename ) ||
230- (!defined ('PHP_CODECOVERAGE_TESTSUITE ' ) &&
231- strpos ($ filename , dirname (__FILE__ )) === 0 ) ||
232- substr ($ filename , -17 ) == 'Text/Template.php ' ||
233- substr ($ filename , -17 ) == 'File/Iterator.php ' ||
234- substr ($ filename , -25 ) == 'File/Iterator/Factory.php ' ) {
235- unset($ data [$ filename ]);
236- }
237- }
238-
239- // Apply blacklist/whitelist filtering.
240- foreach (array_keys ($ data ) as $ filename ) {
241- if ($ this ->filter ->isFiltered ($ filename , $ filterGroups )) {
242- unset($ data [$ filename ]);
243- }
244- }
245-
228+ $ this ->applySelfFilter ($ data );
229+ $ this ->applyListsFilter ($ data , $ filterGroups );
246230 $ raw = $ data ;
247-
248- // Apply @covers filtering.
249- if ($ id instanceof PHPUnit_Framework_TestCase) {
250- $ linesToBeCovered = PHP_CodeCoverage_Util::getLinesToBeCovered (
251- get_class ($ id ), $ id ->getName ()
252- );
253- } else {
254- $ linesToBeCovered = array ();
255- }
256-
257- if (!empty ($ linesToBeCovered )) {
258- $ data = array_intersect_key ($ data , $ linesToBeCovered );
259-
260- foreach (array_keys ($ data ) as $ filename ) {
261- $ data [$ filename ] = array_intersect_key (
262- $ data [$ filename ], array_flip ($ linesToBeCovered [$ filename ])
263- );
264- }
265- }
266-
267- else if ($ this ->forceCoversAnnotation ) {
268- $ data = array ();
269- }
231+ $ this ->applyCoversAnnotationFilter ($ data , $ id );
270232
271233 if (!empty ($ data )) {
272234 if ($ id instanceof PHPUnit_Framework_TestCase) {
@@ -441,6 +403,72 @@ public function setPromoteGlobals($flag)
441403 $ this ->promoteGlobals = $ flag ;
442404 }
443405
406+ /**
407+ * Filters sourcecode files from PHP_CodeCoverage, Text_Template, and
408+ * File_Iterator.
409+ *
410+ * @param array $data
411+ */
412+ protected function applySelfFilter (&$ data )
413+ {
414+ foreach (array_keys ($ data ) as $ filename ) {
415+ if (!$ this ->filter ->isFile ($ filename ) ||
416+ (!defined ('PHP_CODECOVERAGE_TESTSUITE ' ) &&
417+ strpos ($ filename , dirname (__FILE__ )) === 0 ) ||
418+ substr ($ filename , -17 ) == 'Text/Template.php ' ||
419+ substr ($ filename , -17 ) == 'File/Iterator.php ' ||
420+ substr ($ filename , -25 ) == 'File/Iterator/Factory.php ' ) {
421+ unset($ data [$ filename ]);
422+ }
423+ }
424+ }
425+
426+ /**
427+ * Applies the blacklist/whitelist filtering.
428+ *
429+ * @param array $data
430+ * @param array $filterGroups
431+ */
432+ protected function applyListsFilter (&$ data , $ filterGroups )
433+ {
434+ foreach (array_keys ($ data ) as $ filename ) {
435+ if ($ this ->filter ->isFiltered ($ filename , $ filterGroups )) {
436+ unset($ data [$ filename ]);
437+ }
438+ }
439+ }
440+
441+ /**
442+ * Applies the @covers annotation filtering.
443+ *
444+ * @param array $data
445+ * @param mixed $id
446+ */
447+ protected function applyCoversAnnotationFilter (&$ data , $ id )
448+ {
449+ if ($ id instanceof PHPUnit_Framework_TestCase) {
450+ $ linesToBeCovered = PHP_CodeCoverage_Util::getLinesToBeCovered (
451+ get_class ($ id ), $ id ->getName ()
452+ );
453+ } else {
454+ $ linesToBeCovered = array ();
455+ }
456+
457+ if (!empty ($ linesToBeCovered )) {
458+ $ data = array_intersect_key ($ data , $ linesToBeCovered );
459+
460+ foreach (array_keys ($ data ) as $ filename ) {
461+ $ data [$ filename ] = array_intersect_key (
462+ $ data [$ filename ], array_flip ($ linesToBeCovered [$ filename ])
463+ );
464+ }
465+ }
466+
467+ else if ($ this ->forceCoversAnnotation ) {
468+ $ data = array ();
469+ }
470+ }
471+
444472 /**
445473 * Processes whitelisted files that are not covered.
446474 */
0 commit comments