dereuromark / cakephp-ide-helper

IDE Helper plugin for CakePHP
MIT License
183 stars 39 forks source link

Controller annotation for `paginate()` doesn't get added everywhere #292

Closed LordSimal closed 8 months ago

LordSimal commented 1 year ago

For some reason the bin/cake annotate all command doesn't seem to generate controller annotations for the paginate() method on all controllers.

I only seem to get them on controllers which do a paginate via $this->paginate($this->TableName); but not for something like

$query = $this->TableName->find();
$result = $this->paginate($query);
dereuromark commented 1 year ago

It probably cannot read the correct class from just "regex" or tokenize. In that case it would need to use AST and actually get the result via this. Might not be too trivial. Would you want to give it a shot?

dereuromark commented 1 year ago

We also might reach the limit of what static annotations can do What if you have two or three different paginations in a controller?

In that case it would be better to use the IDEs meta capability to get return based on param type. But that would be PHPStorm part of the plugin then.

LordSimal commented 1 year ago

I would agree that having the correct return type of paginate() being inferred by the given param type is the better approach.

But then we are back at it again to not having a table specific query class...

dereuromark commented 1 year ago

Could we use AST to determine the object going into paginate() and then add inline annotations here?

LordSimal commented 1 year ago

I have to play arround more with php-parser to truly understand how to work with the AST

dereuromark commented 1 year ago

Since you could have multiple different models with

$this->paginate($query);

now I feal like we should then only annotate it abstractly if possible. So no concrete collection but whatever subset as interface would always be correct inside docblock method What do you think?

dereuromark commented 1 year ago

On the other side, the PHPStorm meta data maybe could be more concrete on the type of query and model being used, but that would be static and not runtime, so also hard to accomplish.