Rewriting PHPDocs based on the correct types

53 Views Asked by At

This might be a long shot, but maybe someone can help or have ideas.

In Mautic, we are doing a lot of refactoring at the moment to upgrade the code base to be PHP 8.x one of the issues I am facing personally is that we have lots of classes with the wrong PHPDocs which makes it impossible for tools like rector to work correct since the types are either wrong or uses mixed which is like there is no type at all.

I have done some research but I was not lucky finding any tool that would analyze the code and then regenerate PHPDocs using the write types.

If someone has suggestions, it would be super helpful.

Thank you

2

There are 2 best solutions below

0
Khaled Alam On

Using PhpStorm IDE will be super helpful, here is an example.

via Code > Inspect Code

enter image description here

enter image description here

enter image description here

enter image description here

0
Alister Bulman On

Rector has moved to what it calls 'Strictly known types', defined in the setlist: SetList::TYPE_DECLARATION. The docblocks are not trusted.

It will base any types it adds to the code on what it can conclusively assert - for example, strlen(non-null-string) will always return an integer, substr will always return a string.