Unknown named argument in vscode

I am migrating my code from CakePHP 4 to CakePHP 5, so I have to use named arguments in my custom finders.

When I use

$this->Weekplans->find('accessible', role: 'admin');

it works as expected but in vscode I get an error: Unknown named argument $role.intelephense(P1044).

How can I get rid off this misleading error message?

Hi, In a normally installed CakePHP 5 environment the type hinting shouldn’t be too bad. But if you are doing a migration then perhaps the annotations might not be correct.

I’m not sure if the following will help but you might try the following. Of course git tag or commit your repo so you can rollback in case it has unexpected side effects

composer require --dev dereuromark/cakephp-ide-helper
bin/cake generate phpstorm
bin/cake annotate all
# also this is good for code completion when trying to get VSCode to auto complete 
# Model, Controller & View callback definitions.
bin/cake  generate code_completion 

generate phpstorm will give you $project_root/.phpstorm.meta.php/.ide-helper.meta.php which VS Code will parse to make better hints and the annotate all will add annotation at the top of all supported classes which again may help VSCode to make better suggestions

Thanks

It did not solved the problem but led me to the solution.

One of my local plugins somehow had a vendor folder with cake 4. I removed it and now all hintings are fine.

1 Like