@@ -224,6 +224,13 @@ class PHP_CodeSniffer_File
224
224
*/
225
225
private $ _warningCount = 0 ;
226
226
227
+ /**
228
+ * The total number of errors/warnings that can be fixed.
229
+ *
230
+ * @var int
231
+ */
232
+ private $ _fixableCount = 0 ;
233
+
227
234
/**
228
235
* An array of sniffs listening to this file's processing.
229
236
*
@@ -407,6 +414,7 @@ public function start($contents=null)
407
414
$ this ->_warnings = array ();
408
415
$ this ->_errorCount = 0 ;
409
416
$ this ->_warningCount = 0 ;
417
+ $ this ->_fixableCount = 0 ;
410
418
411
419
$ this ->_parse ($ contents );
412
420
$ this ->fixer ->startFile ($ this );
@@ -435,6 +443,7 @@ public function start($contents=null)
435
443
$ this ->_warnings = array ();
436
444
$ this ->_errorCount = 0 ;
437
445
$ this ->_warningCount = 0 ;
446
+ $ this ->_fixableCount = 0 ;
438
447
return ;
439
448
} else if (strpos ($ token ['content ' ], '@codingStandardsChangeSetting ' ) !== false ) {
440
449
$ start = strpos ($ token ['content ' ], '@codingStandardsChangeSetting ' );
@@ -722,17 +731,24 @@ public static function detectLineEndings($file, $contents=null)
722
731
/**
723
732
* Adds an error to the error stack.
724
733
*
725
- * @param string $error The error message.
726
- * @param int $stackPtr The stack position where the error occurred.
727
- * @param string $code A violation code unique to the sniff message.
728
- * @param array $data Replacements for the error message.
729
- * @param int $severity The severity level for this error. A value of 0
730
- * will be converted into the default severity level.
734
+ * @param string $error The error message.
735
+ * @param int $stackPtr The stack position where the error occurred.
736
+ * @param string $code A violation code unique to the sniff message.
737
+ * @param array $data Replacements for the error message.
738
+ * @param int $severity The severity level for this error. A value of 0
739
+ * will be converted into the default severity level.
740
+ * @param boolean $fixable Can the error be fixed by the sniff?
731
741
*
732
742
* @return void
733
743
*/
734
- public function addError ($ error , $ stackPtr , $ code ='' , $ data =array (), $ severity =0 )
735
- {
744
+ public function addError (
745
+ $ error ,
746
+ $ stackPtr ,
747
+ $ code ='' ,
748
+ $ data =array (),
749
+ $ severity =0 ,
750
+ $ fixable =false
751
+ ) {
736
752
// Don't bother doing any processing if errors are just going to
737
753
// be hidden in the reports anyway.
738
754
if ($ this ->phpcs ->cli ->errorSeverity === 0 ) {
@@ -804,6 +820,10 @@ public function addError($error, $stackPtr, $code='', $data=array(), $severity=0
804
820
}
805
821
806
822
$ this ->_errorCount ++;
823
+ if ($ fixable === true ) {
824
+ $ this ->_fixableCount ++;
825
+ }
826
+
807
827
if ($ this ->_recordErrors === false ) {
808
828
if (isset ($ this ->_errors [$ lineNum ]) === false ) {
809
829
$ this ->_errors [$ lineNum ] = 0 ;
@@ -835,6 +855,7 @@ public function addError($error, $stackPtr, $code='', $data=array(), $severity=0
835
855
'message ' => $ message ,
836
856
'source ' => $ sniff ,
837
857
'severity ' => $ severity ,
858
+ 'fixable ' => $ fixable ,
838
859
);
839
860
840
861
}//end addError()
@@ -843,17 +864,24 @@ public function addError($error, $stackPtr, $code='', $data=array(), $severity=0
843
864
/**
844
865
* Adds an warning to the warning stack.
845
866
*
846
- * @param string $warning The error message.
847
- * @param int $stackPtr The stack position where the error occurred.
848
- * @param string $code A violation code unique to the sniff message.
849
- * @param array $data Replacements for the warning message.
850
- * @param int $severity The severity level for this warning. A value of 0
851
- * will be converted into the default severity level.
867
+ * @param string $warning The error message.
868
+ * @param int $stackPtr The stack position where the error occurred.
869
+ * @param string $code A violation code unique to the sniff message.
870
+ * @param array $data Replacements for the warning message.
871
+ * @param int $severity The severity level for this warning. A value of 0
872
+ * will be converted into the default severity level.
873
+ * @param boolean $fixable Can the warning be fixed by the sniff?
852
874
*
853
875
* @return void
854
876
*/
855
- public function addWarning ($ warning , $ stackPtr , $ code ='' , $ data =array (), $ severity =0 )
856
- {
877
+ public function addWarning (
878
+ $ warning ,
879
+ $ stackPtr ,
880
+ $ code ='' ,
881
+ $ data =array (),
882
+ $ severity =0 ,
883
+ $ fixable =false
884
+ ) {
857
885
// Don't bother doing any processing if warnings are just going to
858
886
// be hidden in the reports anyway.
859
887
if ($ this ->phpcs ->cli ->warningSeverity === 0 ) {
@@ -925,6 +953,10 @@ public function addWarning($warning, $stackPtr, $code='', $data=array(), $severi
925
953
}
926
954
927
955
$ this ->_warningCount ++;
956
+ if ($ fixable === true ) {
957
+ $ this ->_fixableCount ++;
958
+ }
959
+
928
960
if ($ this ->_recordErrors === false ) {
929
961
if (isset ($ this ->_warnings [$ lineNum ]) === false ) {
930
962
$ this ->_warnings [$ lineNum ] = 0 ;
@@ -956,11 +988,61 @@ public function addWarning($warning, $stackPtr, $code='', $data=array(), $severi
956
988
'message ' => $ message ,
957
989
'source ' => $ sniff ,
958
990
'severity ' => $ severity ,
991
+ 'fixable ' => $ fixable ,
959
992
);
960
993
961
994
}//end addWarning()
962
995
963
996
997
+ /**
998
+ * Adds a fixable error to the error stack.
999
+ *
1000
+ * @param string $error The error message.
1001
+ * @param int $stackPtr The stack position where the error occurred.
1002
+ * @param string $code A violation code unique to the sniff message.
1003
+ * @param array $data Replacements for the error message.
1004
+ * @param int $severity The severity level for this error. A value of 0
1005
+ * will be converted into the default severity level.
1006
+ *
1007
+ * @return void
1008
+ */
1009
+ public function addFixableError (
1010
+ $ error ,
1011
+ $ stackPtr ,
1012
+ $ code ='' ,
1013
+ $ data =array (),
1014
+ $ severity =0
1015
+ ) {
1016
+ $ this ->addError ($ error , $ stackPtr , $ code , $ data , $ severity , true );
1017
+
1018
+ }//end addFixableError()
1019
+
1020
+
1021
+ /**
1022
+ * Adds a fixable warning to the warning stack.
1023
+ *
1024
+ * @param string $warning The error message.
1025
+ * @param int $stackPtr The stack position where the error occurred.
1026
+ * @param string $code A violation code unique to the sniff message.
1027
+ * @param array $data Replacements for the warning message.
1028
+ * @param int $severity The severity level for this warning. A value of 0
1029
+ * will be converted into the default severity level.
1030
+ * @param boolean $fixable Can the warning be fixed by the sniff?
1031
+ *
1032
+ * @return void
1033
+ */
1034
+ public function addFixableWarning (
1035
+ $ warning ,
1036
+ $ stackPtr ,
1037
+ $ code ='' ,
1038
+ $ data =array (),
1039
+ $ severity =0
1040
+ ) {
1041
+ $ this ->addWarning ($ warning , $ stackPtr , $ code , $ data , $ severity , true );
1042
+
1043
+ }//end addFixableWarning()
1044
+
1045
+
964
1046
/**
965
1047
* Returns the number of errors raised.
966
1048
*
@@ -985,6 +1067,18 @@ public function getWarningCount()
985
1067
}//end getWarningCount()
986
1068
987
1069
1070
+ /**
1071
+ * Returns the number of fixable errors/warnings raised.
1072
+ *
1073
+ * @return int
1074
+ */
1075
+ public function getFixableCount ()
1076
+ {
1077
+ return $ this ->_fixableCount ;
1078
+
1079
+ }//end getFixableCount()
1080
+
1081
+
988
1082
/**
989
1083
* Returns the list of ignored lines.
990
1084
*
0 commit comments