@@ -43,6 +43,7 @@ protected function processMemberVar(File $phpcsFile, $stackPtr)
4343 $ find [] = T_VARIABLE ;
4444 $ find [] = T_VAR ;
4545 $ find [] = T_READONLY ;
46+ $ find [] = T_FINAL ;
4647 $ find [] = T_SEMICOLON ;
4748 $ find [] = T_OPEN_CURLY_BRACKET ;
4849
@@ -130,12 +131,36 @@ protected function processMemberVar(File $phpcsFile, $stackPtr)
130131 *
131132 * Ref: https://www.php-fig.org/per/coding-style/#46-modifier-keywords
132133 *
133- * At this time (PHP 8.2), inheritance modifiers cannot be applied to properties and
134- * the `static` and `readonly` modifiers are mutually exclusive and cannot be used together.
134+ * The `static` and `readonly` modifiers are mutually exclusive and cannot be used together.
135135 *
136136 * Based on that, the below modifier keyword order checks are sufficient (for now).
137137 */
138138
139+ if ($ propertyInfo ['scope_specified ' ] === true && $ propertyInfo ['is_final ' ] === true ) {
140+ $ scopePtr = $ phpcsFile ->findPrevious (Tokens::$ scopeModifiers , ($ stackPtr - 1 ));
141+ $ finalPtr = $ phpcsFile ->findPrevious (T_FINAL , ($ stackPtr - 1 ));
142+ if ($ finalPtr > $ scopePtr ) {
143+ $ error = 'The final declaration must come before the visibility declaration ' ;
144+ $ fix = $ phpcsFile ->addFixableError ($ error , $ stackPtr , 'FinalAfterVisibility ' );
145+ if ($ fix === true ) {
146+ $ phpcsFile ->fixer ->beginChangeset ();
147+
148+ for ($ i = ($ finalPtr + 1 ); $ finalPtr < $ stackPtr ; $ i ++) {
149+ if ($ tokens [$ i ]['code ' ] !== T_WHITESPACE ) {
150+ break ;
151+ }
152+
153+ $ phpcsFile ->fixer ->replaceToken ($ i , '' );
154+ }
155+
156+ $ phpcsFile ->fixer ->replaceToken ($ finalPtr , '' );
157+ $ phpcsFile ->fixer ->addContentBefore ($ scopePtr , $ tokens [$ finalPtr ]['content ' ].' ' );
158+
159+ $ phpcsFile ->fixer ->endChangeset ();
160+ }
161+ }
162+ }//end if
163+
139164 if ($ propertyInfo ['scope_specified ' ] === true && $ propertyInfo ['is_static ' ] === true ) {
140165 $ scopePtr = $ phpcsFile ->findPrevious (Tokens::$ scopeModifiers , ($ stackPtr - 1 ));
141166 $ staticPtr = $ phpcsFile ->findPrevious (T_STATIC , ($ stackPtr - 1 ));
0 commit comments