Skip to content

Commit 20fcf05

Browse files
committed
2 parents 81824ab + 4ffe33a commit 20fcf05

File tree

1 file changed

+41
-20
lines changed

1 file changed

+41
-20
lines changed

CodeSniffer/File.php

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -510,21 +510,34 @@ public function start($contents=null)
510510
// Remove errors and warnings for ignored lines.
511511
foreach ($this->_ignoredLines as $line => $ignore) {
512512
if (isset($this->_errors[$line]) === true) {
513-
foreach ($this->_errors[$line] as $col => $errors) {
514-
$this->_errorCount -= count($errors);
513+
if ($this->_recordErrors === false) {
514+
$this->_errorCount -= $this->_errors[$line];
515+
} else {
516+
foreach ($this->_errors[$line] as $col => $errors) {
517+
$this->_errorCount -= count($errors);
518+
}
515519
}
516520

517521
unset($this->_errors[$line]);
518522
}
519523

520524
if (isset($this->_warnings[$line]) === true) {
521-
foreach ($this->_warnings[$line] as $col => $warnings) {
522-
$this->_warningCount -= count($warnings);
525+
if ($this->_recordErrors === false) {
526+
$this->_errorCount -= $this->_warnings[$line];
527+
} else {
528+
foreach ($this->_warnings[$line] as $col => $warnings) {
529+
$this->_warningCount -= count($warnings);
530+
}
523531
}
524532

525533
unset($this->_warnings[$line]);
526534
}
527535
}
536+
537+
if ($this->_recordErrors === false) {
538+
$this->_errors = array();
539+
$this->_warnings = array();
540+
}
528541

529542
// If short open tags are off but the file being checked uses
530543
// short open tags, the whole content will be inline HTML
@@ -768,8 +781,20 @@ public function addError($error, $stackPtr, $code='', $data=array(), $severity=0
768781
}
769782
}
770783

784+
if ($stackPtr === null) {
785+
$lineNum = 1;
786+
$column = 1;
787+
} else {
788+
$lineNum = $this->_tokens[$stackPtr]['line'];
789+
$column = $this->_tokens[$stackPtr]['column'];
790+
}
791+
771792
$this->_errorCount++;
772793
if ($this->_recordErrors === false) {
794+
if (isset($this->_errors[$lineNum]) === false) {
795+
$this->_errors[$lineNum] = 0;
796+
}
797+
$this->_errors[$lineNum]++;
773798
return;
774799
}
775800

@@ -784,14 +809,6 @@ public function addError($error, $stackPtr, $code='', $data=array(), $severity=0
784809
$message = vsprintf($error, $data);
785810
}
786811

787-
if ($stackPtr === null) {
788-
$lineNum = 1;
789-
$column = 1;
790-
} else {
791-
$lineNum = $this->_tokens[$stackPtr]['line'];
792-
$column = $this->_tokens[$stackPtr]['column'];
793-
}
794-
795812
if (isset($this->_errors[$lineNum]) === false) {
796813
$this->_errors[$lineNum] = array();
797814
}
@@ -885,8 +902,20 @@ public function addWarning($warning, $stackPtr, $code='', $data=array(), $severi
885902
}
886903
}
887904

905+
if ($stackPtr === null) {
906+
$lineNum = 1;
907+
$column = 1;
908+
} else {
909+
$lineNum = $this->_tokens[$stackPtr]['line'];
910+
$column = $this->_tokens[$stackPtr]['column'];
911+
}
912+
888913
$this->_warningCount++;
889914
if ($this->_recordErrors === false) {
915+
if (isset($this->_warnings[$lineNum]) === false) {
916+
$this->_warnings[$lineNum] = 0;
917+
}
918+
$this->_warnings[$lineNum]++;
890919
return;
891920
}
892921

@@ -901,14 +930,6 @@ public function addWarning($warning, $stackPtr, $code='', $data=array(), $severi
901930
$message = vsprintf($warning, $data);
902931
}
903932

904-
if ($stackPtr === null) {
905-
$lineNum = 1;
906-
$column = 1;
907-
} else {
908-
$lineNum = $this->_tokens[$stackPtr]['line'];
909-
$column = $this->_tokens[$stackPtr]['column'];
910-
}
911-
912933
if (isset($this->_warnings[$lineNum]) === false) {
913934
$this->_warnings[$lineNum] = array();
914935
}

0 commit comments

Comments
 (0)