Skip to content

Commit b98fbeb

Browse files
committed
Include patterns are now evaluated as OR instead of AND (ref #2177)
1 parent be56c13 commit b98fbeb

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

package.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ http://pear.php.net/dtd/package-2.0.xsd">
2626
</stability>
2727
<license uri="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt">BSD 3-Clause License</license>
2828
<notes>
29+
- Rule include patterns in a ruleset.xml file are not evaluated as OR instead of AND
30+
-- Previously, a file had to match every include pattern and no exclude patterns to be included
31+
-- Now, a file must match at least one include pattern and no exclude patterns to be included
32+
-- This is a bug fix as include patterns are already documented to work this way
2933
- New token T_BITWISE_NOT added for the bitwise not operator
3034
-- This token was previously tokenized as T_NONE
3135
-- Any sniffs specifically looking for T_NONE tokens with a tilde as the contents must now also look for T_BITWISE_NOT

src/Files/File.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,7 @@ protected function addMessage($error, $message, $line, $column, $code, $data, $s
970970
}
971971

972972
// Make sure we are not ignoring this file.
973+
$included = null;
973974
foreach ($checkCodes as $checkCode) {
974975
$patterns = null;
975976

@@ -1002,16 +1003,34 @@ protected function addMessage($error, $message, $line, $column, $code, $data, $s
10021003

10031004
$pattern = '`'.strtr($pattern, $replacements).'`i';
10041005
$matched = preg_match($pattern, $this->path);
1005-
if (($matched === 1 && $excluding === true)
1006-
|| ($matched === 0 && $excluding === false)
1007-
) {
1008-
// This file path is being excluded, or not included.
1006+
1007+
if ($matched === 0) {
1008+
if ($excluding === false && $included === null) {
1009+
// This file path is not being included.
1010+
$included = false;
1011+
}
1012+
1013+
continue;
1014+
}
1015+
1016+
if ($excluding === true) {
1017+
// This file path is being excluded.
10091018
$this->ignoredCodes[$checkCode] = true;
10101019
return false;
10111020
}
1021+
1022+
// This file path is being included.
1023+
$included = true;
1024+
break;
10121025
}//end foreach
10131026
}//end foreach
10141027

1028+
if ($included === false) {
1029+
// There were include rules set, but this file
1030+
// path didn't match any of them.
1031+
return false;
1032+
}
1033+
10151034
$messageCount++;
10161035
if ($fixable === true) {
10171036
$this->fixableCount++;

0 commit comments

Comments
 (0)