@@ -51,10 +51,10 @@ class LowerCaseTypeSniff implements Sniff
5151 public function register ()
5252 {
5353 $ tokens = Tokens::$ castTokens ;
54+ $ tokens += Tokens::$ ooScopeTokens ;
5455 $ tokens [] = T_FUNCTION ;
5556 $ tokens [] = T_CLOSURE ;
5657 $ tokens [] = T_FN ;
57- $ tokens [] = T_VARIABLE ;
5858 return $ tokens ;
5959
6060 }//end register()
@@ -90,40 +90,66 @@ public function process(File $phpcsFile, $stackPtr)
9090 * Check property types.
9191 */
9292
93- if ($ tokens [$ stackPtr ]['code ' ] === T_VARIABLE ) {
94- try {
95- $ props = $ phpcsFile ->getMemberProperties ($ stackPtr );
96- } catch (RuntimeException $ e ) {
97- // Not an OO property.
93+ if (isset (Tokens::$ ooScopeTokens [$ tokens [$ stackPtr ]['code ' ]]) === true ) {
94+ if (isset ($ tokens [$ stackPtr ]['scope_opener ' ], $ tokens [$ stackPtr ]['scope_closer ' ]) === false ) {
9895 return ;
9996 }
10097
101- if (empty ($ props ) === true ) {
102- // Parse error - property in interface or enum. Ignore.
103- return ;
104- }
98+ for ($ i = ($ tokens [$ stackPtr ]['scope_opener ' ] + 1 ); $ i < $ tokens [$ stackPtr ]['scope_closer ' ]; $ i ++) {
99+ // Skip over potentially large docblocks.
100+ if ($ tokens [$ i ]['code ' ] === \T_DOC_COMMENT_OPEN_TAG
101+ && isset ($ tokens [$ i ]['comment_closer ' ]) === true
102+ ) {
103+ $ i = $ tokens [$ i ]['comment_closer ' ];
104+ continue ;
105+ }
105106
106- // Strip off potential nullable indication.
107- $ type = ltrim ($ props ['type ' ], '? ' );
107+ // Skip over function declarations and everything nested within.
108+ if ($ tokens [$ i ]['code ' ] === \T_FUNCTION
109+ && isset ($ tokens [$ i ]['scope_closer ' ]) === true
110+ ) {
111+ $ i = $ tokens [$ i ]['scope_closer ' ];
112+ continue ;
113+ }
108114
109- if ($ type !== '' ) {
110- $ error = ' PHP property type declarations must be lowercase; expected "%s" but found "%s" ' ;
111- $ errorCode = ' PropertyTypeFound ' ;
115+ if ($ tokens [ $ i ][ ' code ' ] !== \ T_VARIABLE ) {
116+ continue ;
117+ }
112118
113- if ($ props ['type_token ' ] === T_TYPE_INTERSECTION ) {
114- // Intersection types don't support simple types.
115- } else if (strpos ($ type , '| ' ) !== false ) {
116- $ this ->processUnionType (
117- $ phpcsFile ,
118- $ props ['type_token ' ],
119- $ props ['type_end_token ' ],
120- $ error ,
121- $ errorCode
122- );
123- } else if (isset ($ this ->phpTypes [strtolower ($ type )]) === true ) {
124- $ this ->processType ($ phpcsFile , $ props ['type_token ' ], $ type , $ error , $ errorCode );
119+ try {
120+ $ props = $ phpcsFile ->getMemberProperties ($ i );
121+ } catch (RuntimeException $ e ) {
122+ // Not an OO property.
123+ continue ;
125124 }
126- }
125+
126+ if (empty ($ props ) === true ) {
127+ // Parse error - property in interface or enum. Ignore.
128+ return ;
129+ }
130+
131+ // Strip off potential nullable indication.
132+ $ type = ltrim ($ props ['type ' ], '? ' );
133+
134+ if ($ type !== '' ) {
135+ $ error = 'PHP property type declarations must be lowercase; expected "%s" but found "%s" ' ;
136+ $ errorCode = 'PropertyTypeFound ' ;
137+
138+ if ($ props ['type_token ' ] === T_TYPE_INTERSECTION ) {
139+ // Intersection types don't support simple types.
140+ } else if (strpos ($ type , '| ' ) !== false ) {
141+ $ this ->processUnionType (
142+ $ phpcsFile ,
143+ $ props ['type_token ' ],
144+ $ props ['type_end_token ' ],
145+ $ error ,
146+ $ errorCode
147+ );
148+ } else if (isset ($ this ->phpTypes [strtolower ($ type )]) === true ) {
149+ $ this ->processType ($ phpcsFile , $ props ['type_token ' ], $ type , $ error , $ errorCode );
150+ }
151+ }
152+ }//end for
127153
128154 return ;
129155 }//end if
0 commit comments