Skip to content

Commit

Permalink
File::addMessage(): don't apply include/exclude patterns to STDIN
Browse files Browse the repository at this point in the history
Note: using `trim()` to remove potential quotes around `STDIN` which are sometimes passed by IDEs.
  • Loading branch information
jrfnl committed Sep 8, 2020
1 parent 0d79723 commit a95569c
Showing 1 changed file with 49 additions and 45 deletions.
94 changes: 49 additions & 45 deletions src/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -967,59 +967,63 @@ protected function addMessage($error, $message, $line, $column, $code, $data, $s

// Make sure we are not ignoring this file.
$included = null;
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;
}

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['/'] = '\\\\';
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;
}

$pattern = '`'.strtr($pattern, $replacements).'`i';
$matched = preg_match($pattern, $this->path);
if ($patterns === null) {
continue;
}

if ($matched === 0) {
if ($excluding === false && $included === null) {
// This file path is not being included.
$included = false;
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['/'] = '\\\\';
}

continue;
}
$pattern = '`'.strtr($pattern, $replacements).'`i';
$matched = preg_match($pattern, $this->path);

if ($excluding === true) {
// This file path is being excluded.
$this->ignoredCodes[$checkCode] = true;
return false;
}
if ($matched === 0) {
if ($excluding === false && $included === null) {
// This file path is not being included.
$included = false;
}

// This file path is being included.
$included = true;
break;
continue;
}

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
}//end foreach
}//end foreach
}//end if

if ($included === false) {
// There were include rules set, but this file
Expand Down

0 comments on commit a95569c

Please sign in to comment.