Skip to content

Commit 26229db

Browse files
committed
Improve readme, document improved ReflectionDescriptor
1 parent 6ea29ef commit 26229db

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ Queries are analyzed statically and do not require a running database server. Th
128128

129129
Most DQL features are supported, including `GROUP BY`, `DISTINCT`, all flavors of `JOIN`, arithmetic expressions, functions, aggregations, `NEW`, etc. Sub queries and `INDEX BY` are not yet supported (infered type will be `mixed`).
130130

131+
### Query type inference of expressions
132+
133+
Whether `MAX(e.id)` is fetched as `numeric-string` or `int` highly [depends on drivers, their setup and PHP version](https://github.com/janedbal/php-database-drivers-fetch-test).
134+
This extension autodetects your setup and provides accurate results for `pdo_mysql`, `mysqli`, `pdo_sqlite`, `sqlite3`, `pdo_pgsql` and `pgsql`.
135+
Any other driver will result in mixed.
136+
131137
### Supported methods
132138

133139
The `getResult` method is supported when called without argument, or with the hydrateMode argument set to `Query::HYDRATE_OBJECT`:
@@ -152,12 +158,6 @@ $query->getOneOrNullResult(Query::HYDRATE_OBJECT); // User
152158

153159
This is due to the design of the `Query` class preventing from determining the hydration mode used by these functions unless it is specified explicitly during the call.
154160

155-
### Expression types inferring
156-
157-
Whether `MAX(e.id)` is fetched as `numeric-string` or `int` highly [depends on drivers, their setup and PHP version](https://github.com/janedbal/php-database-drivers-fetch-test).
158-
This extension autodetects your setup and provides accurate results for `pdo_mysql`, `mysqli`, `pdo_sqlite`, `sqlite3`, `pdo_pgsql` and `pgsql`.
159-
Any other driver will result in mixed.
160-
161161
### Problematic approaches
162162

163163
Not every QueryBuilder can be statically analysed, here are few advices to maximize type inferring:
@@ -201,6 +201,10 @@ Type descriptors don't have to deal with nullable types, as these are transparen
201201

202202
If your custom type's `convertToPHPValue()` and `convertToDatabaseValue()` methods have proper typehints, you don't have to write your own descriptor for it. The `PHPStan\Type\Doctrine\Descriptors\ReflectionDescriptor` can analyse the typehints and do the rest for you.
203203

204+
If parent of your type is one of the Doctrine's non-abstract ones, `ReflectionDescriptor` will reuse its descriptor even for expression resolution (e.g. `AVG(t.cost)`).
205+
For example, if you extend `Doctrine\DBAL\Types\DecimalType`, it will know that sqlite fetches that as `float|int` and other drivers as `numeric-string`.
206+
If you extend only `Doctrine\DBAL\Types\Type`, you should use custom descriptor and optionally implement even `DoctrineTypeDriverAwareDescriptor` to provide driver-specific resolution.
207+
204208
### Registering type descriptors
205209

206210
When you write a custom type descriptor, you have to let PHPStan know about it. Add something like this into your `phpstan.neon`:

0 commit comments

Comments
 (0)