sqlftw icon indicating copy to clipboard operation
sqlftw copied to clipboard

Phpstan result types

Open staabm opened this issue 3 years ago • 3 comments

In the readme I found

another will hopefully help PHPStan (static analysis tool for PHP) better understand SQL queries and their results

Since I am working on https://github.com/staabm/phpstan-dba - which achives a similar goal, I am interested in your plans. Maybe we can join forces on some of the involved problems..

staabm avatar Nov 25 '22 07:11 staabm

hi Markus, i am aware of your project, i just did not find time to react ^_^ in fact it was Ondřej Mirtes who made me aware of phpstan-dba and proposed that it would be nice to make it work truly statically (without calling any DB from CI; possibly from DB structure export)

till now i have been finishing the parser side. just two weeks ago i finished all MySQL features support. now i am preparing for a first talk (small local meetup) about this project and going to start promoting this tool

since you have already started to use it (https://github.com/staabm/phpstan-dba/commits/sqlftw), let me know any of your suggestions

providing PHPStan with types is one of the things i would like to do, but currently it is not a top priority. there is a lot of things to do. my plans for upcoming weeks/months are:

  • porting my older tool for analysing SQL migrations on this parser (few dozens of rules, mainly to make migrations safe; they do not work with any type model, but there is already a mechanism to provide existing exported DB structures when needed for analysis)
  • making parser better aware of platform versions (now basicly parses anything from 5.7 to 8.0.30)
  • preparing it for other platforms (MariaDB, PG...)
  • making it able to cope better with partially valid code
  • and of course building a type model for static type analysis of SQL (this could be really fun with user defined types in Postgre ^_^)

so, i am not sure when i will get to the PHPStan part. and maybe i won't have to... : ]

providing types for PHPStan is not the only goal of this project. there is more areas where static analysis is needed:

  • safe migrations
  • analysis of existing DB schema
  • providing types for PHPStan
  • analysing SQL queries from app (security, safety, bugs, performance)
  • analysing external SQL (analytics/data teams etc.)

SQLFTW will need all the parts like type model and provider of existing DB structures anyway, so we can definitely join our forces here

also, pleas also be aware, that this is still an early developer version and some APIs will change. there will be breaking changes in patch versions until i am a little confident about the interfaces and leave 0.1

paranoiq avatar Feb 14 '23 09:02 paranoiq

thx for the extensive answer. I will try to build up the sql <-> phpstan type system in phpstandba and keep it as isolated as possible for now.

maybe it can later be backported into sqlftw when it fits your roadmap. lets see how it goes.

staabm avatar Feb 14 '23 11:02 staabm

I started building dynamic return type extensions for the mysql function library in

https://github.com/staabm/phpstan-dba/tree/main/src/SqlAst

staabm avatar Feb 26 '23 09:02 staabm