phpmd
phpmd copied to clipboard
SuppressWarnings annotation for a function doesn't work
PHPMD sees this:
function ab() {
return 1;
}
and returns:
<violation beginline="2" endline="4" rule="ShortMethodName" ruleset="Naming Rules" package="+global" externalInfoUrl="http://phpmd.org/rules/naming.html#shortmethodname" function="ab" priority="3">
Avoid using short method names like ::ab(). The configured minimum method name length is 3.
</violation>
Using a @SuppressWarnings annotation like this has no effect:
/**
* @SuppressWarnings(PHPMD.ShortMethodName)
*/
function ab() {
return 1;
}
I don't run PHPMD with --strict.
I have verified that the annotation has effect on classes and methods for me.
How should I use the annotation for functions?
This also happens when trying to suppress a short variable on a parameter. I mention it here because it seems related.
Example:
class Model
{
/**
* @var integer The id of the model.
* @SuppressWarnings(PHPMD.ShortVariable)
*/
public $id;
}
Nobody? This is still open?
I think it's a bug
/**
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
* --> It work
*/
if (! function_exists('example')) {
/**
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
* --> doesn't work
*/
function example(array $array)
{
/**
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
* --> doesn't work
*/
foreach ($array as $key => $value) {
echo $key;
}
}
}
We have 3 different bugs here:
Original bug of this stream:
/**
* @SuppressWarnings(PHPMD.ShortMethodName)
*/
function ab() {
return 1;
}
Fixed.
class Model
{
/**
* @var integer The id of the model.
* @SuppressWarnings(PHPMD.ShortVariable)
*/
public $id;
}
The rule ShortVariable doesn't have the @SuppressWarnings proper support. And LongVariable has the same bug: #493. Those 2 rules are similar, so let track this issue in #493.
And the previous comment https://github.com/phpmd/phpmd/issues/337#issuecomment-439609957 It was discussed here: #441
I confirm it's still happening, so we should rather re-open #441