Description:
I'd like to propose the idea of a "strip down useless PHPDoc"-fixer that:
@param records when they don't provide additional informations@return records when they don't provide additional informationsBefore:
<?php
class Example
{
/**
* @param \stdClass $obj
* @return \stdClass
*/
public function canBeRemoved(\stdClass $obj): \stdClass
{
}
/**
* @param \stdClass|array $mixed
* @return \stdClass
*/
public function canNotBeRemoved($mixed): \stdClass
{
}
/**
* @param \stdClass $obj
* @param int|bool $mixed
* @return \stdClass
*/
public function firstParamCanBeRemoved(\stdClass $obj, $mixed): \stdClass
{
}
}
After:
<?php
class Example
{
public function canBeRemoved(\stdClass $obj): \stdClass
{
}
/**
* @param \stdClass|array $mixed
*/
public function canNotBeRemoved($mixed): \stdClass
{
}
/**
* @param int|bool $mixed
*/
public function firstParamCanBeRemoved(\stdClass $obj, $mixed): \stdClass
{
}
}
Hi.
This feature was accepted and even discussed how to do it as part of bigger, more generic rule.
Need to find that discussion.
@localheinz , I remember I was discussing it with you and you thumbed this issue as well, do you remember our discussion?
@keradus
Cannot recall, but I remember countless times re-iterating personal rules for when a method needs a docblock and when it doesn't to former team members, hehe.
In the light of that, a fixer that solves this problem would be a nice addition to the tool belt!
However, I would suggest to
class Example
{
/**
* @param \stdClass $obj
* @return \stdClass
*/
public function canBeRemoved(\stdClass $obj): \stdClass
{
}
/**
* @param \stdClass|array $mixed
* @return \stdClass
*/
public function canNotBeRemoved($mixed): \stdClass
{
}
/**
* @param \stdClass $obj
* @param int|bool $mixed
* @return \stdClass
*/
public function firstParamCanBeRemoved(\stdClass $obj, $mixed): \stdClass
{
}
}
After:
class Example
{
public function canBeRemoved(\stdClass $obj): \stdClass
{
}
/**
* @param \stdClass|array $mixed
*/
public function canNotBeRemoved($mixed): \stdClass
{
}
/**
* @param int|bool $mixed
*/
public function firstParamCanBeRemoved(\stdClass $obj, $mixed): \stdClass
{
}
}
```
ok, I will try to find that ticket to have full overview and not creating 2 different specs.
I think you are looking for https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/2464 :)
@keradus Is there a spec for this issue? Or is it waiting for a pull request?
The most complete would be already mentioned #2464, i think
not remove parts of a docblock
This should be configurable IMHO. Some libraries adopt removing useless part while keeping the PHPDoc.
@keradus BTW, is not the way Symfony maintainers are moving?
Another test case:
Before:
class Example
{
/**
* @param string $name
* @param string $email This should be kept because of the custom description.
*/
public function display(string $name, string $email): void
{
}
}
After:
class Example
{
/**
* @param string $email This should be kept because of the custom description.
*/
public function display(string $name, string $email): void
{
}
}
Most helpful comment
However, I would suggest to
class Example
{
/**
* @param \stdClass $obj
* @return \stdClass
*/
public function canBeRemoved(\stdClass $obj): \stdClass
{
}
}
After:
class Example
{
public function canBeRemoved(\stdClass $obj): \stdClass
{
}
}
```