Skip to content

Conversation

@staabm
Copy link
Owner

@staabm staabm commented May 23, 2022

closes #372

$stmt = $pdo->query($q);
assertType('PDOStatement<array<bool|float|int|string>>', $stmt);
foreach ($stmt as $row) {
assertType('array<bool|float|int|string>', $row);
Copy link
Owner Author

@staabm staabm May 23, 2022

Choose a reason for hiding this comment

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

@Seldaek could I get your opinion on this one?

is it usefull to get a type like bool|float|int|string in cases where phpstan-dba cannot know the actual db query beeing used?

before this PR this was only a PDOStatement without any information about the types.
with this PR we now get types dependent on the used fetch-type - if available - even if the sql query cannot be inferred.

see the other tests below in this file

Copy link
Owner Author

Choose a reason for hiding this comment

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

also: I am not sure, whether a bool can actually be returned from PDO, or whether its always encoded as a int 0/1

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO the PR makes sense, vague types are better than mixed.

Raw PDO I don't think it can do bool, doctrine I think yes (maybe depending on API used).

Copy link
Owner Author

Choose a reason for hiding this comment

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

hmm I might have missed null here.. need to double check

@staabm staabm changed the title added failling test Infer default-result type when sql queries cannot be inferred May 23, 2022
@staabm staabm marked this pull request as ready for review May 24, 2022 19:46
@staabm staabm enabled auto-merge (squash) May 24, 2022 19:46
@staabm staabm merged commit fa34896 into main May 24, 2022
@staabm staabm deleted the bug372 branch May 24, 2022 19:46
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.

spurious error regarding mixed type

4 participants