staabm / phpstan-dba

PHPStan based SQL static analysis and type inference for the database access layer
https://staabm.github.io/archive.html#phpstan-dba
MIT License
250 stars 17 forks source link

Analyzing multiple connections #585

Closed aszenz closed 1 year ago

aszenz commented 1 year ago

We use two db connections in the app, is their a way to analyze them both, i only see an option to add one pdo mysql db

staabm commented 1 year ago

You can use https://github.com/staabm/phpstan-dba/blob/main/src/QueryReflection/ChainedReflector.php to combine several pdo or mysql,... reflectors

aszenz commented 1 year ago

Perfect, works great. I see it now in docs too https://github.com/staabm/phpstan-dba/blob/main/docs/reflectors.md, hence closing this issue

aszenz commented 1 year ago

How does phpstan-dba know which reflector to use for each file like a repository, i see some errors where it uses an incorrect reflector on the repository file and throws errors like table central.foo doesn't exist, while it should actually check demo.foo

staabm commented 1 year ago

the chain just works thru the list of reflectors. the first one which returns a type, is used:

https://github.com/staabm/phpstan-dba/blob/31c4de9e3ea64110903e2d892ea0e8e26726afe9/src/QueryReflection/ChainedReflector.php#L54-L60

I guess this might lead to problems, e.g. when you have queries which can be executed successfully on several reflectors

aszenz commented 1 year ago

Hmm, my query should work on only one reflector, but it's not using that reflector

staabm commented 1 year ago

please open a new issue with code which reproduces your problem. it might be useful to create a small example repo.