I would like to have a way to check our php scripts for missing types in functions/methods.
In the class below, the first method has typed arguments and a return type. The second doesn't:
<?php
class MyClass{
function alter_string(string $a_string): string{
return $a_string;
}
function alter_another_string($a_string){
return $a_string;
}
}
Is there some way to check all return types and argument types are added? I am using Eclipse for PHP Developers as IDE. But any other solution would be nice too.
I could write my own script that reads the php files and checks each function for a return type. And if there are arguments to the function, that script checks whether the types are added to these arguments. But I am pretty sure there is some existing way to achieve this.
You may use something like the following:
You may also use PHPStan in this case.