@@ -31,15 +31,15 @@ class FunctionsDeprecatedWithoutArgumentSniff implements Sniff
3131 private const WARNING_CODE = 'FunctionsDeprecatedWithoutArgument ' ;
3232
3333 /**
34- * Deprecated functions without argument.
34+ * Deprecated functions without argument
3535 *
3636 * @var array
3737 */
38- private const FUNCTIONS_LIST = [
39- 'mb_check_encoding ' ,
40- 'get_class ' ,
41- 'get_parent_class ' ,
42- 'get_called_class '
38+ private const DEPRECATED_FUNCTIONS_AND_FIXES = [
39+ 'mb_check_encoding ' => ' null ' ,
40+ 'get_class ' => ' $this ' ,
41+ 'get_parent_class ' => ' $this ' ,
42+ 'get_called_class ' => ' $this '
4343 ];
4444
4545 /**
@@ -66,8 +66,17 @@ public function process(File $phpcsFile, $stackPtr): void
6666
6767 $ functionName = $ phpcsFile ->getTokensAsString ($ phpcsFile ->findPrevious (T_STRING , $ stackPtr ), 1 );
6868
69- if (in_array ($ functionName , self ::FUNCTIONS_LIST )) {
70- $ phpcsFile ->addWarning (sprintf (self ::WARNING_MESSAGE , $ functionName ), $ stackPtr , self ::WARNING_CODE );
69+ if (in_array ($ functionName , array_keys (self ::DEPRECATED_FUNCTIONS_AND_FIXES ))) {
70+ if ($ phpcsFile ->addFixableWarning (
71+ sprintf (self ::WARNING_MESSAGE , $ functionName ),
72+ $ stackPtr ,
73+ self ::WARNING_CODE
74+ ) === true ) {
75+ $ content = self ::DEPRECATED_FUNCTIONS_AND_FIXES [$ functionName ];
76+ $ phpcsFile ->fixer ->beginChangeset ();
77+ $ phpcsFile ->fixer ->addContentBefore ($ phpcsFile ->findNext (T_CLOSE_PARENTHESIS , $ stackPtr ), $ content );
78+ $ phpcsFile ->fixer ->endChangeset ();
79+ }
7180 }
7281 }
7382}
0 commit comments