For instance, supposing that you have a function someString(): string and you have something like that:
/** @var string $variable */
$variable = someString();
You could note that $variable yet is a string, once that it was received by the called function, so you can drop that command.
Consider:
@var and @type@param@returnIf we drop PhpDoc parts here, will PS emit additional warnings (default IDE configuration)?
Yes, it will do. I don't know if is possible we force-disable it. For @param, for instance, it will requires that you create the phpdoc for it, even if you don't declare any description and your parameter have type definition in code.
Then the inspection needs to be deactivated by default, IMO.
The idea is a good one - will help a lot to clean code up when migrating to return types declaration.
I am heading up with this situation often lately, I mean removing lot of superfluous comments since type declaration is providing all info needed as result of migrating. Not in office now, but will report back, once there, about use cases I found.
Ok.
I keep thinking further: perhaps we can report /** @var string $variable */ for local variables by default (like unnecessary type-castings) and have an option to do the same for PhpDoc (disabled by default).
Hello everyone.
I think it would be nice to have this inspection with following use cases:
/**
* @return string < -- this doc comment not needed
*/
public function getName() : string{
return 'test'
}
/**
* @param string $name < -- this doc comment not needed
*/
public function setName(string $name) : self{
// ...
}
/**
* @return Users[] <- do not fire error here
*/
public function getUsers() : array;
/**
* @param bool $active <- We can add option to fire error on this or not.
* @return Users[] <- do not fire error here
*/
public function getUsers(bool $active) : array;
And yes, users should disable standard phpstorm inspection (missing doc comment)
p.s.
In our team we prefer to remove doc comment if it does not explain more than types.
But if comment add at least one explanation (see use case 3) then we leave it.
An additional case: when you declare a single type (or nullable type) on @param but don't declares on code. For instance:
/**
* @param Carbon $carbon
*/
function test($carbon) {
}
It should be replaced by just:
function test(Carbon $carbon) {
}
Picking up for Ultimate - all of us on it =)
To clarify: only for local variables, PhpDoc is not in the scope.
@funivan: I think this is part of PhpClean already (superfluous @var string $variable). Can you confirm, please?
@kalessil right now PhpClean can handle only redundant tags in PhpDoc for methods and functions.
But in the future, I'm planning to support @var for variables.
Super, then I'm closing the issue.
Most helpful comment
An additional case: when you declare a single type (or nullable type) on
@parambut don't declares on code. For instance:It should be replaced by just: