1616 * Verifies the correct usage of type cast keywords.
1717 *
1818 * Type casts should be:
19- * - lowercase;
20- * - short form, i.e. (bool) not (boolean);
2119 * - normalized, i.e. (float) not (real).
2220 *
2321 * Additionally, the use of the (unset) and (binary) casts is discouraged.
2725 * @package WPCS\WordPressCodingStandards
2826 *
2927 * @since 1.2.0
28+ * @since 2.0.0 No longer checks that type casts are lowercase or short form.
29+ * Relevant PHPCS native sniffs have been included in the rulesets instead.
3030 */
3131class TypeCastsSniff extends Sniff {
3232
@@ -36,10 +36,12 @@ class TypeCastsSniff extends Sniff {
3636 * @return array
3737 */
3838 public function register () {
39- $ targets = Tokens::$ castTokens ;
40- unset( $ targets [ \T_ARRAY_CAST ], $ targets [ \T_OBJECT_CAST ] );
41-
42- return $ targets ;
39+ return array (
40+ \T_DOUBLE_CAST ,
41+ \T_UNSET_CAST ,
42+ \T_STRING_CAST ,
43+ \T_BINARY_CAST ,
44+ );
4345 }
4446
4547 /**
@@ -55,39 +57,7 @@ public function process_token( $stackPtr ) {
5557 $ typecast = str_replace ( ' ' , '' , $ this ->tokens [ $ stackPtr ]['content ' ] );
5658 $ typecast_lc = strtolower ( $ typecast );
5759
58- $ this ->phpcsFile ->recordMetric ( $ stackPtr , 'Typecast encountered ' , $ typecast );
59-
6060 switch ( $ token_code ) {
61- case \T_BOOL_CAST :
62- if ( '(bool) ' !== $ typecast_lc ) {
63- $ fix = $ this ->phpcsFile ->addFixableError (
64- 'Short form type keywords must be used; expected "(bool)" but found "%s" ' ,
65- $ stackPtr ,
66- 'LongBoolFound ' ,
67- array ( $ typecast )
68- );
69-
70- if ( true === $ fix ) {
71- $ this ->phpcsFile ->fixer ->replaceToken ( $ stackPtr , '(bool) ' );
72- }
73- }
74- break ;
75-
76- case \T_INT_CAST :
77- if ( '(int) ' !== $ typecast_lc ) {
78- $ fix = $ this ->phpcsFile ->addFixableError (
79- 'Short form type keywords must be used; expected "(int)" but found "%s" ' ,
80- $ stackPtr ,
81- 'LongIntFound ' ,
82- array ( $ typecast )
83- );
84-
85- if ( true === $ fix ) {
86- $ this ->phpcsFile ->fixer ->replaceToken ( $ stackPtr , '(int) ' );
87- }
88- }
89- break ;
90-
9161 case \T_DOUBLE_CAST :
9262 if ( '(float) ' !== $ typecast_lc ) {
9363 $ fix = $ this ->phpcsFile ->addFixableError (
0 commit comments