Skip to content

Conversation

gharlan
Copy link
Member

@gharlan gharlan commented Sep 1, 2025

No description provided.

@coveralls
Copy link

coveralls commented Sep 2, 2025

Coverage Status

coverage: 94.694%. remained the same
when pulling a6a614e on gharlan:PhpUnitDedicateAssertFixer
into 9dfded1 on PHP-CS-Fixer:master.

@gharlan gharlan enabled auto-merge (squash) September 2, 2025 00:11
@gharlan gharlan merged commit 9b5f364 into PHP-CS-Fixer:master Sep 2, 2025
54 of 58 checks passed
@gharlan gharlan deleted the PhpUnitDedicateAssertFixer branch September 2, 2025 00:27
} while ($tokens[$classEndIndex]->isGivenKind([\T_STRING, \T_NS_SEPARATOR, \T_VARIABLE]));

if ($tokens[$classEndIndex]->equalsAny([',', ')'])) { // do the fixing
array_pop($classPartTokens);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't this change the logic? we did array_pop + reset, now we do only reset. is reset changing anything now ?

Copy link
Member Author

@gharlan gharlan Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reset gives the first array element.
With array_pop we removed the last element, because we always added one "wrong" last element to the list in do-while-loop.
Caused by the array_pop call phpstan wasn't sure that the list is non-empty. So it complained about the reset() call, which could return false for empty list.

By changing the lines in do-while-loop I avoid the wrong last element. So we do not have to remove it anymore by array_pop. This helps phpstan to understand that $classPartTokens can not be empty, so that calling reset is safe and always will return an element (the first one).

Copy link
Member

@keradus keradus Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant that while we no longer manipulate the array with array_pop, the reset sounds superfluous (we do not rely on moving internal pointer)

#9014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants