Skip to content

Add fetch_column/fetch_object/fetch_row methods & mysqli_fetch_all func - #827

Merged
staabm merged 6 commits into
staabm:mainfrom
bpfoley:func-and-method-fetch
Nov 13, 2026
Merged

staabm merged 6 commits into
staabm:mainfrom
bpfoley:func-and-method-fetch

Conversation

@bpfoley

@bpfoley bpfoley commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

No description provided.

* @param list<ParametersAcceptor> $variants
*/
private function getExprObjectType(Scope $scope, Expr $expr): ?Type
private function getArgOrDefault(array $variants, CallLike $call, Scope $scope, int $i): Type

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

please add tests to show proof this method also works properly for calls with named arguments

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. I added this just for {mysqli_,}fetch_column because named arguments are a syntax error in PHP 7.4 so we can't extend the tests in tests/default/data/mysqli.php , and the same mechanism used for fetch_column is used for fetch_all.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually never mind the previous comment. The linter forced me to move all the named argument tests into a separate file, so I tested everything.

@bpfoley
bpfoley force-pushed the func-and-method-fetch branch 2 times, most recently from a122bf6 to 2d18e84 Compare November 12, 2026 17:44
Comment thread src/Rules/MysqliFetchRangeRule.php Resolved
Comment thread src/Rules/MysqliFetchRangeRule.php Outdated
Comment on lines +119 to +130
if (! $hasOffset->yes()) {
return [
RuleErrorBuilder::message(sprintf(
'Column offset %s may be out of range; valid offsets are %s.',
$columnType->describe(VerbosityLevel::value()),
$numericRowType->getIterableKeyType()->describe(VerbosityLevel::value()),
))
->identifier('dba.columnOffset')
->line($columnArg->value->getStartLine())
->build(),
];
}

@staabm staabm Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

this handling should depend on "reportMaybe" (so the phpstan level), as in e.g. https://github.com/phpstan/phpstan-src/blob/ec03c848556e234672ab70d1a343cab6800f7353/src/Rules/Functions/CallCallablesRule.php#L39-L40

I would prefer we keep the new rule in a separate PR to ease reviewing

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ACK. I'll move it out into a separate PR

@bpfoley
bpfoley force-pushed the func-and-method-fetch branch from 38aafd3 to ca27a69 Compare November 13, 2026 12:20
@staabm
staabm merged commit 685070e into staabm:main Nov 13, 2026
28 checks passed
@staabm

staabm commented Nov 13, 2026

Copy link
Copy Markdown
Owner

thank you!

@bpfoley
bpfoley deleted the func-and-method-fetch branch November 13, 2026 14:06
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