@@ -31,15 +31,15 @@ class FunctionsDeprecatedWithoutArgumentSniff implements Sniff
31
31
private const WARNING_CODE = 'FunctionsDeprecatedWithoutArgument ' ;
32
32
33
33
/**
34
- * Deprecated functions without argument.
34
+ * Deprecated functions without argument
35
35
*
36
36
* @var array
37
37
*/
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 '
43
43
];
44
44
45
45
/**
@@ -66,8 +66,17 @@ public function process(File $phpcsFile, $stackPtr): void
66
66
67
67
$ functionName = $ phpcsFile ->getTokensAsString ($ phpcsFile ->findPrevious (T_STRING , $ stackPtr ), 1 );
68
68
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
+ }
71
80
}
72
81
}
73
82
}
0 commit comments