Skip to content

Added initial Doctrine Dbal type inference - #115

Merged
staabm merged 12 commits into
mainfrom
dbal
Jan 17, 2022
Merged

staabm merged 12 commits into
mainfrom
dbal

Conversation

@staabm

@staabm staabm commented Jan 17, 2022 •

Copy link
Copy Markdown
Owner

refs #94

adds support for

  • Connection->query()
  • Result->fetchNumeric()
  • Result->fetchAssociative()
  • Result->fetchAllNumeric()
  • Result->fetchAllAssociative()
  • Result->columnCount()

@staabm
staabm marked this pull request as draft January 17, 2022 13:10
Comment thread tests/data/doctrine-dbal.php Outdated
Comment on lines +12 to +19
$result = $conn->query('SELECT email, adaid, gesperrt, freigabe1u1 FROM ada');
assertType('Doctrine\DBAL\Result<array{email: string, 0: string, adaid: int<0, 4294967295>, 1: int<0, 4294967295>, gesperrt: int<-128, 127>, 2: int<-128, 127>, freigabe1u1: int<-128, 127>, 3: int<-128, 127>}>', $result);

$numericFetch = $result->fetchNumeric();
assertType('array{string, int<0, 4294967295>, int<-128, 127>, int<-128, 127>}', $numericFetch);

$numericFetch = $result->fetchAssociative();
assertType('array{email: string, adaid: int<0, 4294967295>, gesperrt: int<-128, 127>, freigabe1u1: int<-128, 127>}', $numericFetch);

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

@Seldaek could you verify this api and type expectations are correct?

@staabm staabm changed the title Added Doctrine Dbal type inference Added initial Doctrine Dbal type inference Jan 17, 2022
@staabm
staabm marked this pull request as ready for review January 17, 2022 13:29
Comment thread tests/data/doctrine-dbal.php Outdated
assertType('array<int, array{string, int<0, 4294967295>, int<-128, 127>, int<-128, 127>}>', $fetch);

$fetch = $result->fetchAllAssociative();
assertType('array<int, array{email: string, adaid: int<0, 4294967295>, gesperrt: int<-128, 127>, freigabe1u1: int<-128, 127>}>', $fetch);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

fetchAll* should perhaps return list<array{}> ? I imagine this is true for all drivers but who knows.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

phpstan does not yet support the list type natively. atm you can do this in phpdoc, but internally its still a array.

I thought about using a positive-int key.. not sure this holds?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah interesting :) Yes I'd think positive-int is true, if list<> is true.. I'm sure it's 99% true and there's someone with a weird implementation somewhere that breaks it but probably this won't matter?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

yeah, I think we should go as strict as possible.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

be careful. positive-int means >0, which is wrong for lists

@staabm staabm Jan 18, 2022 •

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Thx. We used int<0, max> in the end

@staabm

staabm commented Jan 17, 2022 •

Copy link
Copy Markdown
Owner Author

@Seldaek I have no application to actually test this dbal extension. could you give it a go for a small smoketest?

if it works for you, we can ship the next release later today with initial doctrine support :-)

@Seldaek

Seldaek commented Jan 17, 2022

Copy link
Copy Markdown
Contributor

Yeah happy to check later but probably easier if you merge it all first.

@staabm
staabm merged commit 786157f into main Jan 17, 2022
@staabm
staabm deleted the dbal branch January 17, 2022 14:33
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