From 9dd6d649caa9e3293b366278afc547797ad5fa4f Mon Sep 17 00:00:00 2001 From: Greg Sherwood Date: Fri, 23 Oct 2020 10:23:54 +1100 Subject: [PATCH] Revert "File::addMessage(): don't apply include/exclude patterns to STDIN" This reverts commit a95569ca6077ecc1529681df3681627e2034a5a4. --- src/Files/File.php | 92 ++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 48 deletions(-) diff --git a/src/Files/File.php b/src/Files/File.php index 0d5d0296f9..8f50d6d332 100644 --- a/src/Files/File.php +++ b/src/Files/File.php @@ -965,63 +965,59 @@ protected function addMessage($error, $message, $line, $column, $code, $data, $s // Make sure we are not ignoring this file. $included = null; - if (trim($this->path, '\'"') === 'STDIN') { - $included = true; - } else { - foreach ($checkCodes as $checkCode) { - $patterns = null; - - if (isset($this->configCache['includePatterns'][$checkCode]) === true) { - $patterns = $this->configCache['includePatterns'][$checkCode]; - $excluding = false; - } else if (isset($this->configCache['ignorePatterns'][$checkCode]) === true) { - $patterns = $this->configCache['ignorePatterns'][$checkCode]; - $excluding = true; - } + foreach ($checkCodes as $checkCode) { + $patterns = null; + + if (isset($this->configCache['includePatterns'][$checkCode]) === true) { + $patterns = $this->configCache['includePatterns'][$checkCode]; + $excluding = false; + } else if (isset($this->configCache['ignorePatterns'][$checkCode]) === true) { + $patterns = $this->configCache['ignorePatterns'][$checkCode]; + $excluding = true; + } - if ($patterns === null) { - continue; + if ($patterns === null) { + continue; + } + + foreach ($patterns as $pattern => $type) { + // While there is support for a type of each pattern + // (absolute or relative) we don't actually support it here. + $replacements = [ + '\\,' => ',', + '*' => '.*', + ]; + + // We assume a / directory separator, as do the exclude rules + // most developers write, so we need a special case for any system + // that is different. + if (DIRECTORY_SEPARATOR === '\\') { + $replacements['/'] = '\\\\'; } - foreach ($patterns as $pattern => $type) { - // While there is support for a type of each pattern - // (absolute or relative) we don't actually support it here. - $replacements = [ - '\\,' => ',', - '*' => '.*', - ]; + $pattern = '`'.strtr($pattern, $replacements).'`i'; + $matched = preg_match($pattern, $this->path); - // We assume a / directory separator, as do the exclude rules - // most developers write, so we need a special case for any system - // that is different. - if (DIRECTORY_SEPARATOR === '\\') { - $replacements['/'] = '\\\\'; + if ($matched === 0) { + if ($excluding === false && $included === null) { + // This file path is not being included. + $included = false; } - $pattern = '`'.strtr($pattern, $replacements).'`i'; - $matched = preg_match($pattern, $this->path); - - if ($matched === 0) { - if ($excluding === false && $included === null) { - // This file path is not being included. - $included = false; - } - - continue; - } + continue; + } - if ($excluding === true) { - // This file path is being excluded. - $this->ignoredCodes[$checkCode] = true; - return false; - } + if ($excluding === true) { + // This file path is being excluded. + $this->ignoredCodes[$checkCode] = true; + return false; + } - // This file path is being included. - $included = true; - break; - }//end foreach + // This file path is being included. + $included = true; + break; }//end foreach - }//end if + }//end foreach if ($included === false) { // There were include rules set, but this file