When you have a class with a function that has the same name (e.g. Access::access) then this is treated as a constructor even when a dedicated __constructor is present. This causes false positives.
A minimum representation looks like the following file:
Small.php
/**
* @file
* A file with a small example.
*/
/**
* A small class for a small example.
*/
class Small {
/**
* Our small constructor.
*/
public function __construct() {
}
/**
* A small example.
*
* @return string
*/
public function small() {
return 'string';
}
}
phpcs --standard=Drupal Small.php has the following output:
FILE: Small.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
22 | ERROR | @return tag is not required for constructor and
| | destructor
----------------------------------------------------------------------
I've tried running phpcs with a different standard and although for this particular example it shows other errors it does not show the error about the return tag.
As of PHP 5 (the minimum version supported by Drupal) a function with the name of the class it's in should only be treated as a constructor when no dedicated constructor (__constructor is present: http://php.net/manual/en/language.oop5.decon.php
Comments
Comment #3
klausiThanks a lot for reporting! I pushed a fix with a test case.