cakephp-ide-helper icon indicating copy to clipboard operation
cakephp-ide-helper copied to clipboard

Adding inline annotations

Open dereuromark opened this issue 3 years ago • 1 comments

Sometimes you need to add those annotations manually:

/** @var \Queue\Model\Table\QueuedJobsTable $queuedJobsTable */
$queuedJobsTable = TableRegistry::getTableLocator()->get('Queue.QueuedJobs');

( in case you cannot or don't want to use ModelAwareTrait and loadModel() call )

And usually also the query results for all():

/** @var \App\Model\Entity\Module[] $modules */
$modules = $query->all()->toArray();

In order for the IDE/PHPStan/Psalm to know the collection item and autocomplete entity properties etc.

As well as first() calls:

/** @var \App\Model\Entity\AttributeValue $attributeValueToMove */
$attributeValueToMove = $this->AttributeValues->find()
            ->where(['attribute_id' => $attribute, 'position' => $oldPos])
            ->firstOrFail();
$attributeValueToMove->position = $newPos;

I am sure there are other use cases for inline annotations that are occurring over and over again.

We should try to find a way to auto fix that for us if we encounter such cases. Since this is too complex for tokenizing, we will need a AST based tool here that also is able to modify code (similar to rector) etc.

dereuromark avatar Jul 28 '21 13:07 dereuromark

This has been partially made possible, but on regex level, not static analyzer level https://github.com/dereuromark/cakephp-ide-helper/releases/tag/1.17.0

So it only works convention based and with a high level of missing things as well as some false positives. If someone has time to invest into AST based ideas, that would be awesome

dereuromark avatar Nov 25 '21 17:11 dereuromark