@@ -71,47 +71,9 @@ class PHP_CodeCoverage_Filter
7171 protected $ whitelistedFiles = array ();
7272
7373 /**
74- * Prefills the blacklist with source files used by PHPUnit
75- * and PHP_CodeCoverage.
74+ * @var boolean
7675 */
77- public function __construct ()
78- {
79- $ functions = array (
80- 'file_iterator_autoload ' ,
81- 'php_codecoverage_autoload ' ,
82- 'php_invoker_autoload ' ,
83- 'php_timer_autoload ' ,
84- 'php_tokenstream_autoload ' ,
85- 'phpunit_autoload ' ,
86- 'phpunit_dbunit_autoload ' ,
87- 'phpunit_mockobject_autoload ' ,
88- 'phpunit_selenium_autoload ' ,
89- 'phpunit_story_autoload ' ,
90- 'text_template_autoload '
91- );
92-
93- foreach ($ functions as $ function ) {
94- if (function_exists ($ function )) {
95- $ this ->addFilesToBlacklist ($ function ());
96- }
97- }
98-
99- $ file = stream_resolve_include_path (
100- 'SymfonyComponents/YAML/sfYaml.php '
101- );
102-
103- if ($ file ) {
104- $ this ->addFileToBlacklist ($ file );
105- }
106-
107- $ file = stream_resolve_include_path (
108- 'SymfonyComponents/YAML/sfYamlDumper.php '
109- );
110-
111- if ($ file ) {
112- $ this ->addFileToBlacklist ($ file );
113- }
114- }
76+ protected $ blacklistPrefilled = FALSE ;
11577
11678 /**
11779 * Adds a directory to the blacklist (recursively).
@@ -209,9 +171,6 @@ public function addDirectoryToWhitelist($directory, $suffix = '.php', $prefix =
209171 /**
210172 * Adds a file to the whitelist.
211173 *
212- * When the whitelist is empty (default), blacklisting is used.
213- * When the whitelist is not empty, whitelisting is used.
214- *
215174 * @param string $filename
216175 */
217176 public function addFileToWhitelist ($ filename )
@@ -294,20 +253,18 @@ public function isFile($filename)
294253 * @return boolean
295254 * @throws PHP_CodeCoverage_Exception
296255 */
297- public function isFiltered ($ filename, $ ignoreWhitelist = FALSE )
256+ public function isFiltered ($ filename )
298257 {
299- if (!is_bool ($ ignoreWhitelist )) {
300- throw PHP_CodeCoverage_Util_InvalidArgumentHelper::factory (
301- 1 , 'boolean '
302- );
303- }
304-
305258 $ filename = realpath ($ filename );
306259
307- if (!$ ignoreWhitelist && ! empty ($ this ->whitelistedFiles )) {
260+ if (!empty ($ this ->whitelistedFiles )) {
308261 return !isset ($ this ->whitelistedFiles [$ filename ]);
309262 }
310263
264+ if (!$ this ->blacklistPrefilled ) {
265+ $ this ->prefillBlacklist ();
266+ }
267+
311268 return isset ($ this ->blacklistedFiles [$ filename ]);
312269 }
313270
@@ -341,4 +298,42 @@ public function hasWhitelist()
341298 {
342299 return !empty ($ this ->whitelistedFiles );
343300 }
301+
302+ /**
303+ * @since Method available since Release 1.2.3
304+ */
305+ protected function prefillBlacklist ()
306+ {
307+ $ this ->addDirectoryContainingClassToBlacklist ('File_Iterator ' );
308+ $ this ->addDirectoryContainingClassToBlacklist ('PHP_CodeCoverage ' );
309+ $ this ->addDirectoryContainingClassToBlacklist ('PHP_Invoker ' );
310+ $ this ->addDirectoryContainingClassToBlacklist ('PHP_Timer ' );
311+ $ this ->addDirectoryContainingClassToBlacklist ('PHP_Token ' );
312+ $ this ->addDirectoryContainingClassToBlacklist ('PHPUnit_Framework_TestCase ' , 2 );
313+ $ this ->addDirectoryContainingClassToBlacklist ('Text_Template ' );
314+ $ this ->addDirectoryContainingClassToBlacklist ('Symfony\Component\Yaml\Yaml ' );
315+
316+ $ this ->blacklistPrefilled = TRUE ;
317+ }
318+
319+ /**
320+ * @param string $className
321+ * @param integer $parent
322+ * @since Method available since Release 1.2.3
323+ */
324+ protected function addDirectoryContainingClassToBlacklist ($ className , $ parent = 1 )
325+ {
326+ if (!class_exists ($ className )) {
327+ return ;
328+ }
329+
330+ $ reflector = new ReflectionClass ($ className );
331+ $ directory = $ reflector ->getFileName ();
332+
333+ for ($ i = 0 ; $ i < $ parent ; $ i ++) {
334+ $ directory = dirname ($ directory );
335+ }
336+
337+ $ this ->addDirectoryToBlacklist ($ directory );
338+ }
344339}
0 commit comments