111
111
* @author Marc McIntyre <[email protected] >
112
112
* @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600)
113
113
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
114
- * @version Release: @package_version@
114
+ * @version Release: 1.4.2
115
115
* @link http://pear.php.net/package/PHP_CodeSniffer
116
116
*/
117
117
class PHP_CodeSniffer_File
@@ -510,21 +510,34 @@ public function start($contents=null)
510
510
// Remove errors and warnings for ignored lines.
511
511
foreach ($ this ->_ignoredLines as $ line => $ ignore ) {
512
512
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
+ }
515
519
}
516
520
517
521
unset($ this ->_errors [$ line ]);
518
522
}
519
523
520
524
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
+ }
523
531
}
524
532
525
533
unset($ this ->_warnings [$ line ]);
526
534
}
527
535
}
536
+
537
+ if ($ this ->_recordErrors === false ) {
538
+ $ this ->_errors = array ();
539
+ $ this ->_warnings = array ();
540
+ }
528
541
529
542
// If short open tags are off but the file being checked uses
530
543
// short open tags, the whole content will be inline HTML
@@ -768,8 +781,20 @@ public function addError($error, $stackPtr, $code='', $data=array(), $severity=0
768
781
}
769
782
}
770
783
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
+
771
792
$ this ->_errorCount ++;
772
793
if ($ this ->_recordErrors === false ) {
794
+ if (isset ($ this ->_errors [$ lineNum ]) === false ) {
795
+ $ this ->_errors [$ lineNum ] = 0 ;
796
+ }
797
+ $ this ->_errors [$ lineNum ]++;
773
798
return ;
774
799
}
775
800
@@ -784,14 +809,6 @@ public function addError($error, $stackPtr, $code='', $data=array(), $severity=0
784
809
$ message = vsprintf ($ error , $ data );
785
810
}
786
811
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
-
795
812
if (isset ($ this ->_errors [$ lineNum ]) === false ) {
796
813
$ this ->_errors [$ lineNum ] = array ();
797
814
}
@@ -885,8 +902,20 @@ public function addWarning($warning, $stackPtr, $code='', $data=array(), $severi
885
902
}
886
903
}
887
904
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
+
888
913
$ this ->_warningCount ++;
889
914
if ($ this ->_recordErrors === false ) {
915
+ if (isset ($ this ->_warnings [$ lineNum ]) === false ) {
916
+ $ this ->_warnings [$ lineNum ] = 0 ;
917
+ }
918
+ $ this ->_warnings [$ lineNum ]++;
890
919
return ;
891
920
}
892
921
@@ -901,14 +930,6 @@ public function addWarning($warning, $stackPtr, $code='', $data=array(), $severi
901
930
$ message = vsprintf ($ warning , $ data );
902
931
}
903
932
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
-
912
933
if (isset ($ this ->_warnings [$ lineNum ]) === false ) {
913
934
$ this ->_warnings [$ lineNum ] = array ();
914
935
}
@@ -1086,7 +1107,7 @@ private static function _convertTabs(&$tokens, $tokenizer, $eolChar)
1086
1107
1087
1108
if (strpos ($ tokenContent , "\t" ) === false ) {
1088
1109
// There are no tabs in this content.
1089
- $ currColumn += strlen ($ tokenContent );
1110
+ $ currColumn += ( strlen ($ tokenContent) - 1 );
1090
1111
} else {
1091
1112
// We need to determine the length of each tab.
1092
1113
$ tabs = preg_split (
@@ -1097,6 +1118,7 @@ private static function _convertTabs(&$tokens, $tokenizer, $eolChar)
1097
1118
);
1098
1119
1099
1120
$ tabNum = 0 ;
1121
+ $ adjustedTab = false ;
1100
1122
$ tabsToSpaces = array ();
1101
1123
$ newContent = '' ;
1102
1124
@@ -1118,6 +1140,7 @@ private static function _convertTabs(&$tokens, $tokenizer, $eolChar)
1118
1140
// This is the first tab, and we are already at a
1119
1141
// tab stop, so this tab counts as a single space.
1120
1142
$ currColumn ++;
1143
+ $ adjustedTab = true ;
1121
1144
} else {
1122
1145
$ currColumn ++;
1123
1146
while (($ currColumn % PHP_CODESNIFFER_TAB_WIDTH ) != 0 ) {
@@ -1132,13 +1155,19 @@ private static function _convertTabs(&$tokens, $tokenizer, $eolChar)
1132
1155
}//end if
1133
1156
}//end foreach
1134
1157
1158
+ if ($ tabNum === 1 && $ adjustedTab === true ) {
1159
+ $ currColumn --;
1160
+ }
1161
+
1135
1162
$ tokens [$ i ]['content ' ] = $ newContent ;
1136
1163
}//end if
1137
1164
1138
1165
if (isset ($ tokens [($ i + 1 )]['line ' ]) === true
1139
1166
&& $ tokens [($ i + 1 )]['line ' ] !== $ tokens [$ i ]['line ' ]
1140
1167
) {
1141
1168
$ currColumn = 1 ;
1169
+ } else {
1170
+ $ currColumn ++;
1142
1171
}
1143
1172
}//end for
1144
1173
0 commit comments