File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 15
15
16
16
namespace Inpsyde \InpsydeCodingStandard ;
17
17
18
+ use PHP_CodeSniffer \Exceptions \RuntimeException as CodeSnifferRuntimeException ;
18
19
use PHP_CodeSniffer \Files \File ;
19
20
20
21
/**
@@ -131,6 +132,34 @@ public static function functionIsMethod(File $file, int $position)
131
132
&& $ closerPosition > $ position + 4 ; // 4 because: (){}
132
133
}
133
134
135
+ /**
136
+ * @param File $file
137
+ * @param int $position
138
+ * @return bool
139
+ */
140
+ public static function functionIsArrayAccess (File $ file , int $ position )
141
+ {
142
+ $ token = $ file ->getTokens ()[$ position ] ?? null ;
143
+ if (!$ token || $ token ['code ' ] !== T_FUNCTION ) {
144
+ return false ;
145
+ }
146
+
147
+ try {
148
+ return in_array (
149
+ $ file ->getDeclarationName ($ position ),
150
+ [
151
+ 'offsetSet ' ,
152
+ 'offsetGet ' ,
153
+ 'offsetUnset ' ,
154
+ 'offsetExists ' ,
155
+ ],
156
+ true
157
+ );
158
+ } catch (CodeSnifferRuntimeException $ exception ) {
159
+ return false ;
160
+ }
161
+ }
162
+
134
163
/**
135
164
* @param File $file
136
165
* @param int $position
You can’t perform that action at this time.
0 commit comments