Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: PhpUnitStrictFixer - do not crash on property having the name of method to fix #7804

Merged

Conversation

kubawerlos
Copy link
Contributor

No description provided.

@coveralls
Copy link

coveralls commented Feb 2, 2024

Coverage Status

coverage: 94.759%. remained the same
when pulling 480c081 on 6b7562617765726c6f73:fix_PhpUnitStrictFixer
into ee8a4ef on PHP-CS-Fixer:master.

@kubawerlos kubawerlos marked this pull request as ready for review February 2, 2024 16:20
@@ -686,17 +686,25 @@ public static function provideFunctionReturnTypeInfoPre80Cases(): iterable

/**
* @dataProvider provideIsTheSameClassCallCases
*
* @param list<int> $sameClassCallIndices
Copy link
Member

Choose a reason for hiding this comment

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

list ❤️

{
$tokens = Tokens::fromCode($code);
$analyzer = new FunctionsAnalyzer();

self::assertSame($isTheSameClassCall, $analyzer->isTheSameClassCall($tokens, $index));
for ($index = $tokens->count(); $index >= 0; --$index) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
for ($index = $tokens->count(); $index >= 0; --$index) {
for ($index = $tokens->count() - 1; $index >= 0; --$index) {

if we have size==2, then array[2] doesn't exist

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly: https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/v3.49.0/src/Tokenizer/Analyzer/FunctionsAnalyzer.php#L186-L188

Previous tests had checked for -1: https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/v3.49.0/tests/Tokenizer/Analyzer/FunctionsAnalyzerTest.php#L711-L715

Maybe we want to throw an error for a non-existing index? Definitely, we want to check what will happen if the non-existing index is given.

Copy link
Member

Choose a reason for hiding this comment

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

to me code looks very counterintuitive to iterate over all existing indexes plus one non-existing , out of the blue it looks almost like a typo error to be fixed (even by sca detecting calling $array[non-exist-index], if sca advanced enough).

i would encourage to have dedicated check for non-existing index.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we want to throw an error for a non-existing index?

out of the blue sounds like possible variant, probably how I would drive it if creating this function from scratch [~indexoutofboundsexception].
we could check how code would react, i hope we do not rely on this existing behaviour to return false instead of error

Copy link
Contributor Author

@kubawerlos kubawerlos Feb 4, 2024

Choose a reason for hiding this comment

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

@keradus keradus merged commit 60edba3 into PHP-CS-Fixer:master Feb 4, 2024
25 checks passed
@kubawerlos kubawerlos deleted the fix_PhpUnitStrictFixer branch February 4, 2024 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants