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 1515
1616namespace Inpsyde \InpsydeCodingStandard ;
1717
18+ use PHP_CodeSniffer \Exceptions \RuntimeException as CodeSnifferRuntimeException ;
1819use PHP_CodeSniffer \Files \File ;
1920
2021/**
@@ -131,6 +132,34 @@ public static function functionIsMethod(File $file, int $position)
131132 && $ closerPosition > $ position + 4 ; // 4 because: (){}
132133 }
133134
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+
134163 /**
135164 * @param File $file
136165 * @param int $position
You can’t perform that action at this time.
0 commit comments