cakephp-phpstan icon indicating copy to clipboard operation
cakephp-phpstan copied to clipboard

Backport of features from 3.* for cakephp 4

Open Harfusha opened this issue 1 year ago • 9 comments

Im i need of this extension TableAssociationTypeNodeResolverExtension, but i saw that it was added in version 3.1.

Any possiblity you will backport it?

Im little bit lost in this repo, but with little guidance i can backport it myself :)

Harfusha avatar Aug 01 '24 17:08 Harfusha

The require phpdoc is only available in the CakePHP 5 @template and @mixin https://github.com/cakephp/cakephp/blob/5.x/src/ORM/Association/BelongsToMany.php#L41

This is the source for TableAssociationTypeNodeResolverExtension https://github.com/CakeDC/cakephp-phpstan/blob/3.next-cake5/src/PhpDoc/TableAssociationTypeNodeResolverExtension.php

The extension is loaded at https://github.com/CakeDC/cakephp-phpstan/blob/3.next-cake5/extension.neon#L62

rochamarcelo avatar Aug 01 '24 21:08 rochamarcelo

If you have the time you could try to add the required phpdoc for CakePHP 4 at your localhost and try TableAssociationTypeNodeResolverExtension.php

If that work then sent a pull request to CakePHP and here

rochamarcelo avatar Aug 01 '24 21:08 rochamarcelo

I will try it tomorrow, thanks :)

Harfusha avatar Aug 01 '24 21:08 Harfusha

When it is added it throws this error + the old one Call to an undefined method Cake\ORM\Association\BelongsTo<App\Model\Table\AccountsTable>::getAccountTier().

Harfusha avatar Aug 02 '24 11:08 Harfusha

HAve you added phpdoc to your localhost cakephp install https://github.com/cakephp/cakephp/blob/5.x/src/ORM/Association/BelongsToMany.php#L41

rochamarcelo avatar Aug 02 '24 14:08 rochamarcelo

That may be the problem, i dont have time to test it today, but i will test is asap

Harfusha avatar Aug 02 '24 14:08 Harfusha

Yes that did the job! Thanks a lot, i will open PR for cakephp 4 :)

Edit: This helped me fix 200+ phpstan errors, thanks a lot for your time :)

Harfusha avatar Aug 05 '24 10:08 Harfusha

When the PR will be merged into cakephp 4 i will make PR for this repo

Harfusha avatar Aug 05 '24 11:08 Harfusha

I will make the PR next week

Harfusha avatar Aug 31 '24 08:08 Harfusha

Released version 2.1.0 . Thank You.

rochamarcelo avatar Oct 23 '24 12:10 rochamarcelo

Getting a lot of new errors since updated to 2.1.0:

  Call to an undefined method                                                                     
         Cake\ORM\Association\HasMany<App\Model\Table\MyTable>::createInitial().          
  568    Access to an undefined property                                                                 
         Cake\ORM\Association\HasMany<App\Model\Table\MyTable>::$SomeRelationShip.  
         💡 Learn more: https://phpstan.org/blog/solving-phpstan-access-to-undefined-property    

TheLevti avatar Nov 06 '24 15:11 TheLevti

Does SomeRelationShip property exists on MyTable? Can you provide code snippet?

Harfusha avatar Nov 06 '24 15:11 Harfusha

Does SomeRelationShip property exists on MyTable? Can you provide code snippet?

Both, the method and also the property exists. The problem is that after the update phpstan instead of HasMany&MyTable now sees HasMany as a generic and MyTable as the type used by the generic. So of course the property and method do not exist on HasMany. Reverting the version back to 2.0.1 resolves the issue.

TheLevti avatar Nov 06 '24 21:11 TheLevti

I have version 2.1.0 on my enterprise app with phpstan 9 and extra strictness and this version fixed me 577 errors. Can you provide the code snippet?

Harfusha avatar Nov 06 '24 21:11 Harfusha

It sounds like you are using an older version of CakePHP

rochamarcelo avatar Nov 06 '24 23:11 rochamarcelo

It sounds like you are using an older version of CakePHP

Could be it, I am on 4.4, latest would be 4.5.

Will let you know if updating to 4.5 helped.

TheLevti avatar Nov 07 '24 08:11 TheLevti