phpstan-dba
phpstan-dba copied to clipboard
PDO: support more fetch modes
- [x] PDO::FETCH_BOTH
- [x] PDO::FETCH_ASSOC
- [x] PDO::FETCH_NUMERIC
- [x] PDO::FETCH_KEY_PAIR
PdoStatement->fetch*() - [ ] PDO::FETCH_KEY_PAIR in
Pdo->query() - [x] PDO::FETCH_COLUMN in
PdoStatement->fetch*() - [ ] PDO::FETCH_COLUMN in
Pdo->query() - [ ] PDO::FETCH_GROUP
- [ ] PDO::FETCH_UNIQUE
- [x] PDO::FETCH_CLASS in
PdoStatement->fetchAll() - [x] PDO::FETCH_CLASS in
PdoStatement->fetchObject() - [ ] PDO::FETCH_CLASS in
Pdo->query() - [ ] PDO::FETCH_CLASS in
PdoStatement->setFetchMode*() - [x] PDO::FETCH_OBJ
- [ ] PDO::FETCH_INTO
- [ ] PDO::FETCH_FUNC
See
- https://www.php.net/manual/en/pdostatement.fetch.php
- https://www.php.net/manual/en/pdostatement.fetchall.php
- https://phpdelusions.net/pdo/fetch_modes#FETCH_COLUMN
relevant in
$pdo->query($query, $fetchMode);$stmt->setFetchMode($fetchMode)$stmt->fetch($fetchMode)
relevant code parts: https://github.com/staabm/phpstan-dba/blob/4d442193a977424c78dc66de0ca65e50d84b40ff/src/PdoReflection/PdoStatementReflection.php#L49-L55 https://github.com/staabm/phpstan-dba/blob/4d442193a977424c78dc66de0ca65e50d84b40ff/src/PdoReflection/PdoStatementReflection.php#L96-L121
and adding corresponding tests in
https://github.com/staabm/phpstan-dba/blob/main/tests/default/data/pdo.php
PDO::FETCH_CLASS support would also be nice IMO
@xPaw since you are using some fetch types we do not yet support type-inference for: do you plan working on the missing fetch-modes?
I will support you in case there are questions left.
I don't currently have plans to look into that, sorry.
One thing worth pointing out is that some of the FETCH constants are actually flags, and not unique modes (thus they can be combined with some modes).
See here: https://github.com/php/php-src/blob/bf9b774327f139f5770ea87797b933b603f979de/ext/pdo/php_pdo_driver.h#L65-L87
One thing worth pointing out is that some of the FETCH constants are actually flags, and not unique modes (thus they can be combined with some modes).
good point.
feel free to provide failing unit tests or open issues with concrete examples of things you used/found in the wild.
I am not interessted in adding every theoretical possible combination, but just those things people actually use