Skip to content

Commit

Permalink
Fixed bug #2575 : Custom error messages don't have data replaced when…
Browse files Browse the repository at this point in the history
… cache is enabled
  • Loading branch information
gsherwood committed Aug 5, 2019
1 parent 2fc1327 commit c3f7eed
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
-- Thanks to Juliette Reinders Folmer for the patch
- Fixed bug #2566 : Author tag email validation doesn't support all TLDs
-- Thanks to Juliette Reinders Folmer for the patch
- Fixed bug #2575 : Custom error messages don't have data replaced when cache is enabled
</notes>
<contents>
<dir name="/">
Expand Down
16 changes: 14 additions & 2 deletions src/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ class File
*/
protected $fixedCount = 0;

/**
* TRUE if errors are being replayed from the cache.
*
* @var boolean
*/
protected $replayingErrors = false;

/**
* An array of sniffs that are being ignored.
*
Expand Down Expand Up @@ -1029,8 +1036,13 @@ protected function addMessage($error, $message, $line, $column, $code, $data, $s
return true;
}

// Work out the error message.
if (isset($this->ruleset->ruleset[$sniffCode]['message']) === true) {
// See if there is a custom error message format to use.
// But don't do this if we are replaying errors because replayed
// errors have already used the custom format and have had their
// data replaced.
if ($this->replayingErrors === false
&& isset($this->ruleset->ruleset[$sniffCode]['message']) === true
) {
$message = $this->ruleset->ruleset[$sniffCode]['message'];
}

Expand Down
4 changes: 4 additions & 0 deletions src/Files/LocalFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ private function replayErrors($errors, $warnings)
$this->warningCount = 0;
$this->fixableCount = 0;

$this->replayingErrors = true;

foreach ($errors as $line => $lineErrors) {
foreach ($lineErrors as $column => $colErrors) {
foreach ($colErrors as $error) {
Expand Down Expand Up @@ -207,6 +209,8 @@ private function replayErrors($errors, $warnings)
}
}

$this->replayingErrors = false;

}//end replayErrors()


Expand Down

0 comments on commit c3f7eed

Please sign in to comment.