@@ -58,13 +58,14 @@ public function register(): array
5858 * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
5959 * @param File $phpcsFile
6060 * @param int $identicalPointer
61+ * @return int
6162 */
62- public function process (File $ phpcsFile , $ identicalPointer ): void
63+ public function process (File $ phpcsFile , $ identicalPointer ): int
6364 {
6465 $ this ->enable = SniffSettingsHelper::isEnabledByPhpVersion ($ this ->enable , 80000 );
6566
6667 if (!$ this ->enable ) {
67- return ;
68+ return $ identicalPointer + 1 ;
6869 }
6970
7071 $ tokens = $ phpcsFile ->getTokens ();
@@ -73,7 +74,7 @@ public function process(File $phpcsFile, $identicalPointer): void
7374 $ pointerAfterIdentical = TokenHelper::findNextEffective ($ phpcsFile , $ identicalPointer + 1 );
7475
7576 if ($ tokens [$ pointerBeforeIdentical ]['code ' ] !== T_NULL && $ tokens [$ pointerAfterIdentical ]['code ' ] !== T_NULL ) {
76- return ;
77+ return $ identicalPointer + 1 ;
7778 }
7879
7980 $ isYoda = $ tokens [$ pointerBeforeIdentical ]['code ' ] === T_NULL ;
@@ -83,7 +84,7 @@ public function process(File $phpcsFile, $identicalPointer): void
8384 $ identificatorEndPointer = $ this ->findIdentificatorEnd ($ phpcsFile , $ identificatorStartPointer );
8485
8586 if ($ identificatorEndPointer === null ) {
86- return ;
87+ return $ pointerAfterIdentical + 1 ;
8788 }
8889
8990 $ conditionStartPointer = $ pointerBeforeIdentical ;
@@ -93,7 +94,7 @@ public function process(File $phpcsFile, $identicalPointer): void
9394 $ identificatorStartPointer = $ this ->findIdentificatorStart ($ phpcsFile , $ identificatorEndPointer );
9495
9596 if ($ identificatorStartPointer === null ) {
96- return ;
97+ return $ identificatorEndPointer + 1 ;
9798 }
9899
99100 $ conditionStartPointer = $ identificatorStartPointer ;
@@ -108,10 +109,15 @@ public function process(File $phpcsFile, $identicalPointer): void
108109
109110 $ allowedBooleanCondition = $ tokens [$ identicalPointer ]['code ' ] === T_IS_NOT_IDENTICAL ? T_BOOLEAN_AND : T_BOOLEAN_OR ;
110111 if ($ tokens [$ pointerAfterCondition ]['code ' ] === $ allowedBooleanCondition ) {
111- $ this ->checkNextCondition ($ phpcsFile , $ identicalPointer , $ conditionStartPointer , $ identificator , $ pointerAfterCondition );
112- } elseif ($ tokens [$ pointerAfterCondition ]['code ' ] === T_INLINE_THEN ) {
112+ return $ this ->checkNextCondition ($ phpcsFile , $ identicalPointer , $ conditionStartPointer , $ identificator , $ pointerAfterCondition );
113+ }
114+
115+ if ($ tokens [$ pointerAfterCondition ]['code ' ] === T_INLINE_THEN ) {
113116 $ this ->checkTernaryOperator ($ phpcsFile , $ identicalPointer , $ conditionStartPointer , $ identificator , $ pointerAfterCondition );
117+ return $ pointerAfterCondition + 1 ;
114118 }
119+
120+ return $ identicalPointer + 1 ;
115121 }
116122
117123 private function checkTernaryOperator (
@@ -258,20 +264,20 @@ private function checkNextCondition(
258264 int $ conditionStartPointer ,
259265 string $ identificator ,
260266 int $ nextConditionBooleanPointer
261- ): void
267+ ): int
262268 {
263269 $ nextIdentificatorPointers = $ this ->getNextIdentificator ($ phpcsFile , $ nextConditionBooleanPointer );
264270
265271 if ($ nextIdentificatorPointers === null ) {
266- return ;
272+ return $ nextConditionBooleanPointer ;
267273 }
268274
269275 [$ nextIdentificatorStartPointer , $ nextIdentificatorEndPointer ] = $ nextIdentificatorPointers ;
270276
271277 $ nextIdentificator = IdentificatorHelper::getContent ($ phpcsFile , $ nextIdentificatorStartPointer , $ nextIdentificatorEndPointer );
272278
273279 if (!$ this ->areIdentificatorsCompatible ($ identificator , $ nextIdentificator )) {
274- return ;
280+ return $ nextConditionBooleanPointer ;
275281 }
276282
277283 $ pointerAfterNexIdentificator = TokenHelper::findNextEffective ($ phpcsFile , $ nextIdentificatorEndPointer + 1 );
@@ -282,13 +288,17 @@ private function checkNextCondition(
282288 $ tokens [$ pointerAfterNexIdentificator ]['code ' ] !== $ tokens [$ identicalPointer ]['code ' ]
283289 && !in_array ($ tokens [$ pointerAfterNexIdentificator ]['code ' ], [T_INLINE_THEN , T_SEMICOLON ], true )
284290 ) {
285- return ;
291+ return $ nextConditionBooleanPointer ;
292+ }
293+
294+ if (!in_array ($ tokens [$ pointerAfterNexIdentificator ]['code ' ], [T_IS_IDENTICAL , T_IS_NOT_IDENTICAL ], true )) {
295+ return $ nextConditionBooleanPointer ;
286296 }
287297
288298 if ($ tokens [$ pointerAfterNexIdentificator ]['code ' ] === T_IS_NOT_IDENTICAL ) {
289299 $ pointerAfterNotIdentical = TokenHelper::findNextEffective ($ phpcsFile , $ pointerAfterNexIdentificator + 1 );
290300 if ($ tokens [$ pointerAfterNotIdentical ]['code ' ] !== T_NULL ) {
291- return ;
301+ return $ nextConditionBooleanPointer ;
292302 }
293303 }
294304
@@ -302,9 +312,11 @@ private function checkNextCondition(
302312 $ fix = $ phpcsFile ->addFixableError ('Operator ?-> is required. ' , $ identicalPointer , self ::CODE_REQUIRED_NULL_SAFE_OBJECT_OPERATOR );
303313
304314 if (!$ fix ) {
305- return ;
315+ return $ nextConditionBooleanPointer ;
306316 }
307317
318+ $ isConditionOfTernaryOperator = TernaryOperatorHelper::isConditionOfTernaryOperator ($ phpcsFile , $ identicalPointer );
319+
308320 $ phpcsFile ->fixer ->beginChangeset ();
309321
310322 $ phpcsFile ->fixer ->replaceToken ($ conditionStartPointer , sprintf ('%s?%s ' , $ identificator , $ identificatorDifference ));
@@ -314,6 +326,12 @@ private function checkNextCondition(
314326 }
315327
316328 $ phpcsFile ->fixer ->endChangeset ();
329+
330+ if ($ isConditionOfTernaryOperator ) {
331+ return TokenHelper::findNext ($ phpcsFile , T_INLINE_THEN , $ identicalPointer + 1 );
332+ }
333+
334+ return $ nextConditionBooleanPointer ;
317335 }
318336
319337 /**
0 commit comments