Skip to content

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Dec 4, 2024

closes phpstan/phpstan#5101
closes phpstan/phpstan#12188

ArrayColumnRule re-uses the logic from the array_column return type extension and reports problems when the logic implies the result will be a never-type.

there are more open problems with array_column and I would approach those after this PR got merged

@clxmstaab clxmstaab force-pushed the array-col branch 2 times, most recently from 0ab86d3 to 9345415 Compare December 4, 2024 14:44
@staabm
Copy link
Contributor Author

staabm commented Dec 4, 2024

@herndlm any opinions on the rule?

only the last commit is important. commits 1-3 are pure refactorings, which could land as a separate previous PR, in case ondrej is fine with the approach in general

btw: I have no idea why the test is failling only with PHP <= 8.1
-> found the cause: PHPStan is pessimistic and allows "dynamic properties" in PHP < 8.2

[$returnValueType, $iterableAtLeastOnce] = $this->arrayColumnHelper->getReturnValueType($arrayType, $columnKeyType, $scope);
if ($returnValueType instanceof NeverType || $iterableAtLeastOnce->no()) {
$errorBuilder = RuleErrorBuilder::message(sprintf(
'Cannot access column %s on %s.',
Copy link
Contributor Author

@staabm staabm Dec 4, 2024

Choose a reason for hiding this comment

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

I think we will need a better message.. maybe mentioning array offsets or property access, but how to name it in unions of array/objects..?

maybe we can find a better generic message

@clxmstaab clxmstaab force-pushed the array-col branch 2 times, most recently from d6812de to adb4d58 Compare December 4, 2024 18:21
@ondrejmirtes
Copy link
Member

I'm looking forward to this, please rebase this on 2.1.x and mark it as ready so I can review it, thanks.

@staabm
Copy link
Contributor Author

staabm commented Jan 16, 2025

will send separate new PRs

@staabm staabm closed this Jan 16, 2025
@staabm staabm deleted the array-col branch January 16, 2025 15:32
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.

2 participants