Skip to content

Commit 8b713e1

Browse files
committed
Fixed bug #2391 : Sniff-specific ignore rules inside rulesets are filtering out too many files
Moved is_array check earlier in shouldIgnorePath() as: $this->config->ignored was an array of pattern => string, where as $this->ruleset->getIgnorePatterns() was an array of ref => [pattern => string] Which meant the original array_merge was not merging the arrays correctly, which caused all files to be excluded as when the rule ref name appeared in the projects path.
1 parent ad34a36 commit 8b713e1

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

package.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
6868
-- The new error code is Squiz.PHP.DisallowMultipleAssignments.FoundInControlStructure
6969
-- All other multiple assignment cases use the existing error code Squiz.PHP.DisallowMultipleAssignments.Found
7070
-- Thanks to Juliette Reinders Folmer for the patch
71+
- Fixed bug #2391 : Sniff-specific ignore rules inside rulesets are filtering out too many files
72+
-- Thanks to Willington Vega for the patch
7173
- Fixed bug #2478 : FunctionCommentThrowTag.WrongNumber when exception is thrown once but built conditionally
7274
- Fixed bug #2479 : Generic.WhiteSpace.ScopeIndent error when using array destructing with exact indent checking
7375
- Fixed bug #2498 : Squiz.Arrays.ArrayDeclaration.MultiLineNotAllowed autofix breaks heredoc

src/Filters/Filter.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,17 @@ protected function shouldIgnorePath($path)
199199
$this->ignoreDirPatterns = [];
200200
$this->ignoreFilePatterns = [];
201201

202-
$ignorePatterns = array_merge($this->config->ignored, $this->ruleset->getIgnorePatterns());
202+
$ignorePatterns = $this->config->ignored;
203+
$rulesetIgnorePatterns = $this->ruleset->getIgnorePatterns();
204+
foreach ($rulesetIgnorePatterns as $pattern => $type) {
205+
// Ignore standard/sniff specific exclude rules.
206+
if (is_array($type) === true) {
207+
continue;
208+
}
209+
210+
$ignorePatterns[$pattern] = $type;
211+
}
212+
203213
foreach ($ignorePatterns as $pattern => $type) {
204214
// If the ignore pattern ends with /* then it is ignoring an entire directory.
205215
if (substr($pattern, -2) === '/*') {
@@ -214,7 +224,7 @@ protected function shouldIgnorePath($path)
214224
$this->ignoreFilePatterns[$pattern] = $type;
215225
}
216226
}
217-
}
227+
}//end if
218228

219229
$relativePath = $path;
220230
if (strpos($path, $this->basedir) === 0) {
@@ -229,11 +239,6 @@ protected function shouldIgnorePath($path)
229239
}
230240

231241
foreach ($ignorePatterns as $pattern => $type) {
232-
// Ignore standard/sniff specific exclude rules.
233-
if (is_array($type) === true) {
234-
continue;
235-
}
236-
237242
// Maintains backwards compatibility in case the ignore pattern does
238243
// not have a relative/absolute value.
239244
if (is_int($pattern) === true) {

tests/Core/Filters/Filter/AcceptTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class AcceptTest extends TestCase
4141
public static function setUpBeforeClass()
4242
{
4343
$standard = __DIR__.'/'.basename(__FILE__, '.php').'.xml';
44-
self::$config = new Config(["--standard=$standard"]);
44+
self::$config = new Config(["--standard=$standard", "--ignore=*/somethingelse/*"]);
4545
self::$ruleset = new Ruleset(self::$config);
4646

4747
}//end setUpBeforeClass()
@@ -88,6 +88,7 @@ public function dataExcludePatterns()
8888
[
8989
'/path/to/src/Main.php',
9090
'/path/to/src/Something/Main.php',
91+
'/path/to/src/Somethingelse/Main.php',
9192
'/path/to/src/Other/Main.php',
9293
],
9394
['/path/to/src/Main.php'],

tests/Core/Filters/Filter/AcceptTest.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="AcceptTest" xsi:noNamespaceSchemaLocation="phpcs.xsd">
33
<description>Ruleset to test the filtering based on exclude patterns.</description>
44

5-
<!-- Directory pattern. -->
6-
<exclude-pattern>*/something/*</exclude-pattern>
7-
<!-- File pattern. -->
8-
<exclude-pattern>*/Other/Main\.php$</exclude-pattern>
5+
<!-- Directory pattern. -->
6+
<exclude-pattern>*/something/*</exclude-pattern>
7+
<!-- File pattern. -->
8+
<exclude-pattern>*/Other/Main\.php$</exclude-pattern>
99

1010
<rule ref="Generic">
11-
<!-- Standard specific directory pattern. -->
11+
<!-- Standard specific directory pattern. -->
1212
<exclude-pattern>/anything/*</exclude-pattern>
13-
<!-- Standard specific file pattern. -->
13+
<!-- Standard specific file pattern. -->
1414
<exclude-pattern>/YetAnother/Main\.php</exclude-pattern>
1515
</rule>
1616
</ruleset>

0 commit comments

Comments
 (0)