@@ -86,17 +86,18 @@ class PHP_CodeCoverage_Filter
86
86
* @param string $directory
87
87
* @param string $suffix
88
88
* @param string $prefix
89
+ * @param string $group
89
90
* @throws RuntimeException
90
91
*/
91
- public function addDirectoryToBlacklist ($ directory , $ suffix = '.php ' , $ prefix = '' )
92
+ public function addDirectoryToBlacklist ($ directory , $ suffix = '.php ' , $ prefix = '' , $ group = ' DEFAULT ' )
92
93
{
93
94
if (file_exists ($ directory )) {
94
95
$ files = File_Iterator_Factory::getFileIterator (
95
96
$ directory , $ suffix , $ prefix
96
97
);
97
98
98
99
foreach ($ files as $ file ) {
99
- $ this ->addFileToBlacklist ($ file ->getPathName ());
100
+ $ this ->addFileToBlacklist ($ file ->getPathName (), $ group );
100
101
}
101
102
} else {
102
103
throw new RuntimeException ($ directory . ' does not exist ' );
@@ -107,15 +108,20 @@ public function addDirectoryToBlacklist($directory, $suffix = '.php', $prefix =
107
108
* Adds a new file to be filtered (blacklist).
108
109
*
109
110
* @param string $filename
111
+ * @param string $group
110
112
* @throws RuntimeException
111
113
*/
112
- public function addFileToBlacklist ($ filename )
114
+ public function addFileToBlacklist ($ filename, $ group = ' DEFAULT ' )
113
115
{
114
116
if (file_exists ($ filename )) {
115
117
$ filename = realpath ($ filename );
116
118
117
- if (!in_array ($ filename , $ this ->blacklistedFiles )) {
118
- $ this ->blacklistedFiles [] = $ filename ;
119
+ if (!isset ($ this ->blacklistedFiles [$ group ])) {
120
+ $ this ->blacklistedFiles [$ group ] = array ($ filename );
121
+ }
122
+
123
+ else if (!in_array ($ filename , $ this ->blacklistedFiles [$ group ])) {
124
+ $ this ->blacklistedFiles [$ group ][] = $ filename ;
119
125
}
120
126
} else {
121
127
throw new RuntimeException ($ filename . ' does not exist ' );
@@ -128,17 +134,18 @@ public function addFileToBlacklist($filename)
128
134
* @param string $directory
129
135
* @param string $suffix
130
136
* @param string $prefix
137
+ * @param string $group
131
138
* @throws RuntimeException
132
139
*/
133
- public function removeDirectoryFromBlacklist ($ directory , $ suffix = '.php ' , $ prefix = '' )
140
+ public function removeDirectoryFromBlacklist ($ directory , $ suffix = '.php ' , $ prefix = '' , $ group = ' DEFAULT ' )
134
141
{
135
142
if (file_exists ($ directory )) {
136
143
$ files = File_Iterator_Factory::getFileIterator (
137
144
$ directory , $ suffix , $ prefix
138
145
);
139
146
140
147
foreach ($ files as $ file ) {
141
- $ this ->removeFileFromBlacklist ($ file ->getPathName ());
148
+ $ this ->removeFileFromBlacklist ($ file ->getPathName (), $ group );
142
149
}
143
150
} else {
144
151
throw new RuntimeException ($ directory . ' does not exist ' );
@@ -149,16 +156,19 @@ public function removeDirectoryFromBlacklist($directory, $suffix = '.php', $pref
149
156
* Removes a file from the filter (blacklist).
150
157
*
151
158
* @param string $filename
159
+ * @param string $group
152
160
* @throws RuntimeException
153
161
*/
154
- public function removeFileFromBlacklist ($ filename )
162
+ public function removeFileFromBlacklist ($ filename, $ group = ' DEFAULT ' )
155
163
{
156
164
if (file_exists ($ filename )) {
157
- $ filename = realpath ($ filename );
165
+ if (isset ($ this ->blacklistedFiles [$ group ])) {
166
+ $ filename = realpath ($ filename );
158
167
159
- foreach ($ this ->blacklistedFiles as $ key => $ _filename ) {
160
- if ($ filename == $ _filename ) {
161
- unset($ this ->blacklistedFiles [$ key ]);
168
+ foreach ($ this ->blacklistedFiles [$ group ] as $ key => $ _filename ) {
169
+ if ($ filename == $ _filename ) {
170
+ unset($ this ->blacklistedFiles [$ group ][$ key ]);
171
+ }
162
172
}
163
173
}
164
174
} else {
@@ -272,21 +282,29 @@ public static function isFile($filename)
272
282
273
283
/**
274
284
* @param string $filename
285
+ * @param array $groups
275
286
* @return boolean
276
287
*/
277
- public function isFiltered ($ filename )
288
+ public function isFiltered ($ filename, array $ groups = array ( ' DEFAULT ' ) )
278
289
{
279
290
$ filename = realpath ($ filename );
280
291
281
292
if (!empty ($ this ->whitelistedFiles )) {
282
293
return !in_array ($ filename , $ this ->whitelistedFiles );
283
294
}
284
295
285
- if (in_array ($ filename , $ this ->blacklistedFiles )) {
286
- return TRUE ;
296
+ $ blacklistedFiles = array ();
297
+
298
+ foreach ($ groups as $ group ) {
299
+ if (isset ($ this ->blacklistedFiles [$ group ])) {
300
+ $ blacklistedFiles = array_merge (
301
+ $ blacklistedFiles ,
302
+ $ this ->blacklistedFiles [$ group ]
303
+ );
304
+ }
287
305
}
288
306
289
- return FALSE ;
307
+ return in_array ( $ filename , $ blacklistedFiles ) ;
290
308
}
291
309
292
310
/**
0 commit comments