Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding inline annotations #238

Open
dereuromark opened this issue Jul 28, 2021 · 1 comment
Open

Adding inline annotations #238

dereuromark opened this issue Jul 28, 2021 · 1 comment

Comments

@dereuromark
Copy link
Owner

dereuromark commented Jul 28, 2021

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
Copy link
Owner Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant