From 312e0abbdcfbddb772075280140c2f191335ac90 Mon Sep 17 00:00:00 2001 From: Chiiwen Date: Sun, 7 May 2017 16:18:31 -0700 Subject: [PATCH 1/2] Add support to non-phpunit code, allow users to add ignore pattern. I use code-coverage for web applications. add vendors to ignorelist. --- src/Filter.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Filter.php b/src/Filter.php index 771a657ae..db383d712 100644 --- a/src/Filter.php +++ b/src/Filter.php @@ -22,6 +22,14 @@ class Filter */ private $whitelistedFiles = []; + private $ignoreLists = []; + + /** + * @param array $ignoreLists + */ + public function setIgnoreLists($ignoreLists) { + $this->ignoreLists = $ignoreLists; + } /** * Adds a directory to the whitelist (recursively). * @@ -127,8 +135,17 @@ public function isFiltered($filename) } $filename = realpath($filename); - + if (empty($this->whitelistedFiles)){ + foreach($this->ignoreLists as $ignorePattern ){ + $pattern = '/'.$ignorePattern.'/'; + if (preg_match($pattern, $filename)){ + return true; + } + } + return false; + } else{ return !isset($this->whitelistedFiles[$filename]); + } } /** From 7d0e5e523364a247d192b0fb5e1419db79873361 Mon Sep 17 00:00:00 2001 From: Chiiwen Date: Sun, 7 May 2017 20:55:34 -0700 Subject: [PATCH 2/2] Return filtered code coverage. This allows users to serialize code coverage data, and merge later. --- src/CodeCoverage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CodeCoverage.php b/src/CodeCoverage.php index fa9d4b9a1..460bc812c 100644 --- a/src/CodeCoverage.php +++ b/src/CodeCoverage.php @@ -306,7 +306,7 @@ public function stop($append = true, $linesToBeCovered = [], array $linesToBeUse $this->currentId = null; - return $data; + return $this->data; } /**