@@ -51,10 +51,10 @@ class LowerCaseTypeSniff implements Sniff
51
51
public function register ()
52
52
{
53
53
$ tokens = Tokens::$ castTokens ;
54
+ $ tokens += Tokens::$ ooScopeTokens ;
54
55
$ tokens [] = T_FUNCTION ;
55
56
$ tokens [] = T_CLOSURE ;
56
57
$ tokens [] = T_FN ;
57
- $ tokens [] = T_VARIABLE ;
58
58
return $ tokens ;
59
59
60
60
}//end register()
@@ -90,40 +90,66 @@ public function process(File $phpcsFile, $stackPtr)
90
90
* Check property types.
91
91
*/
92
92
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 ) {
98
95
return ;
99
96
}
100
97
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
+ }
105
106
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
+ }
108
114
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
+ }
112
118
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 ;
125
124
}
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
127
153
128
154
return ;
129
155
}//end if
0 commit comments