Skip to content

Conversation

@TomasVotruba
Copy link
Member

@TomasVotruba TomasVotruba commented Oct 1, 2025

In one project I've noticed there is no array filled where obviously should be one.
Single isset might be triggered on null and key, but maybe more useful cases are ignored then. Let's open up this a bit and test in the wild, if brings more value 👍

@TomasVotruba TomasVotruba force-pushed the tv-array-param-from-isset-dim-fetch branch from 26d22aa to f119912 Compare October 1, 2025 07:52
Copy link
Member

@samsonasik samsonasik left a comment

Choose a reason for hiding this comment

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

There is rule StrictArrayParamDimFetchRector rule for it, for 0 index without context, it can be string, which maybe not array on purpose, see

// skip integer in possibly string type as string can be accessed via int
$dimType = $this->getType($node->dim);
if ($dimType->isInteger()->yes() && $variableType->isString()->maybe()) {
return null;
}

see https://3v4l.org/8h8nm

@TomasVotruba
Copy link
Member Author

TomasVotruba commented Oct 1, 2025

I could not find this one, thanks

I see lot of missed array types just to avoid string access. Will make this condition less strict to improve auto fill 👍

@samsonasik
Copy link
Member

Then that's need on very last on level set list with Int_ key, as risky, or just not register in the set list, user can manually use this rule when needed.

Also, still needs ParentClassMethodTypeOverrideGuard->hasParentClassMethod() check still needed.

@TomasVotruba TomasVotruba force-pushed the tv-array-param-from-isset-dim-fetch branch 4 times, most recently from 5c1b4b8 to a5d9773 Compare October 1, 2025 09:23
@TomasVotruba TomasVotruba changed the title [type-declarations] Add AddClassMethodParamArrayWhereDimFetchRector [type-declarations] Open isset check in StrictArrayParamDimFetchRectorTest, move to last position in type-declaration level Oct 1, 2025
@TomasVotruba TomasVotruba force-pushed the tv-array-param-from-isset-dim-fetch branch from a5d9773 to b2dd4a7 Compare October 1, 2025 09:25
…rTest, move to last position in type-declaration level
@TomasVotruba TomasVotruba force-pushed the tv-array-param-from-isset-dim-fetch branch from 2bc2bc4 to 88a4185 Compare October 1, 2025 09:27

final class CoverIssetWithDimFetch
{
public function run(array $param, $item): bool
Copy link
Contributor

@staabm staabm Oct 1, 2025

Choose a reason for hiding this comment

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

in this case $param could be anything which implements ArrayAccess not just the rare case of string-offset access.

in case you "wrongly guess" the array type a call with a ArrayAccess object will produce a fatal error at runtime - see https://3v4l.org/csROV

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, it's a choice of practice over risk of few edge cases. We apply same logic to other rules too, to ease manual daunting work on project upgrades.

If your codebase uses any type in this case, exclude the rule.

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed, it's a choice of practice over risk of few edge cases. We apply same logic to other rules too, to ease manual daunting work on project upgrades.

If your codebase uses any type in this case, exclude the rule.

@TomasVotruba TomasVotruba merged commit 7a73e88 into main Oct 1, 2025
49 of 50 checks passed
@TomasVotruba TomasVotruba deleted the tv-array-param-from-isset-dim-fetch branch October 1, 2025 15:57
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.

4 participants