@@ -41,6 +41,39 @@ class TokenHelper
4141 T_CALLABLE ,
4242 ];
4343
44+ /**
45+ * @param \PHP_CodeSniffer_File $phpcsFile
46+ * @param int|int[] $types
47+ * @param int $startPointer
48+ * @param int|null $endPointer
49+ * @return int|null
50+ */
51+ public static function findNext (\PHP_CodeSniffer_File $ phpcsFile , $ types , int $ startPointer , int $ endPointer = null )
52+ {
53+ $ token = $ phpcsFile ->findNext ($ types , $ startPointer , $ endPointer , false );
54+ if ($ token === false ) {
55+ return null ;
56+ }
57+ return $ token ;
58+ }
59+
60+ /**
61+ * @param \PHP_CodeSniffer_File $phpcsFile
62+ * @param int|int[] $types
63+ * @param string $content
64+ * @param int $startPointer
65+ * @param int|null $endPointer
66+ * @return int|null
67+ */
68+ public static function findNextContent (\PHP_CodeSniffer_File $ phpcsFile , $ types , string $ content , int $ startPointer , int $ endPointer = null )
69+ {
70+ $ token = $ phpcsFile ->findNext ($ types , $ startPointer , $ endPointer , false , $ content );
71+ if ($ token === false ) {
72+ return null ;
73+ }
74+ return $ token ;
75+ }
76+
4477 /**
4578 * @param \PHP_CodeSniffer_File $phpcsFile
4679 * @param int $startPointer search starts at this token, inclusive
@@ -68,6 +101,38 @@ public static function findNextExcluding(\PHP_CodeSniffer_File $phpcsFile, $type
68101 return $ token ;
69102 }
70103
104+ /**
105+ * @param \PHP_CodeSniffer_File $phpcsFile
106+ * @param int|int[] $types
107+ * @param int $startPointer
108+ * @param int|null $endPointer
109+ * @return int|null
110+ */
111+ public static function findNextLocal (\PHP_CodeSniffer_File $ phpcsFile , $ types , int $ startPointer , int $ endPointer = null )
112+ {
113+ $ token = $ phpcsFile ->findNext ($ types , $ startPointer , $ endPointer , false , null , true );
114+ if ($ token === false ) {
115+ return null ;
116+ }
117+ return $ token ;
118+ }
119+
120+ /**
121+ * @param \PHP_CodeSniffer_File $phpcsFile
122+ * @param int|int[] $types
123+ * @param int $startPointer
124+ * @param int|null $endPointer
125+ * @return int|null
126+ */
127+ public static function findNextLocalExcluding (\PHP_CodeSniffer_File $ phpcsFile , $ types , int $ startPointer , int $ endPointer = null )
128+ {
129+ $ token = $ phpcsFile ->findNext ($ types , $ startPointer , $ endPointer , true , null , true );
130+ if ($ token === false ) {
131+ return null ;
132+ }
133+ return $ token ;
134+ }
135+
71136 /**
72137 * @param \PHP_CodeSniffer_File $phpcsFile
73138 * @param int $startPointer search starts at this token, inclusive
@@ -79,6 +144,22 @@ public static function findNextAnyToken(\PHP_CodeSniffer_File $phpcsFile, int $s
79144 return self ::findNextExcluding ($ phpcsFile , [], $ startPointer , $ endPointer );
80145 }
81146
147+ /**
148+ * @param \PHP_CodeSniffer_File $phpcsFile
149+ * @param int[]|int $types
150+ * @param int $startPointer search starts at this token, inclusive
151+ * @param int|null $endPointer search ends at this token, exclusive
152+ * @return int|null
153+ */
154+ public static function findPrevious (\PHP_CodeSniffer_File $ phpcsFile , $ types , int $ startPointer , int $ endPointer = null )
155+ {
156+ $ token = $ phpcsFile ->findPrevious ($ types , $ startPointer , $ endPointer , false );
157+ if ($ token === false ) {
158+ return null ;
159+ }
160+ return $ token ;
161+ }
162+
82163 /**
83164 * @param \PHP_CodeSniffer_File $phpcsFile
84165 * @param int $startPointer search starts at this token, inclusive
@@ -113,8 +194,8 @@ public static function findPreviousExcluding(\PHP_CodeSniffer_File $phpcsFile, $
113194 */
114195 public static function findFirstTokenOnNextLine (\PHP_CodeSniffer_File $ phpcsFile , int $ pointer )
115196 {
116- $ newLinePointer = $ phpcsFile-> findNext ( T_WHITESPACE , $ pointer , null , false , $ phpcsFile ->eolChar );
117- if ($ newLinePointer === false ) {
197+ $ newLinePointer = self :: findNextContent ( $ phpcsFile, T_WHITESPACE , $ phpcsFile ->eolChar , $ pointer );
198+ if ($ newLinePointer === null ) {
118199 return null ;
119200 }
120201 $ tokens = $ phpcsFile ->getTokens ();
0 commit comments