Skip to content

Commit

Permalink
Revert "File::addMessage(): don't apply include/exclude patterns to S…
Browse files Browse the repository at this point in the history
…TDIN"

This reverts commit a95569c.
  • Loading branch information
gsherwood committed Oct 22, 2020
1 parent a978246 commit 9dd6d64
Showing 1 changed file with 44 additions and 48 deletions.
92 changes: 44 additions & 48 deletions src/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9dd6d64

Please sign in to comment.