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

Kingdutch created an issue. See original summary.

  • klausi committed 98358fd on 8.x-3.x
    fix(FunctionComment): Also report return tag format errors for methods...
  • klausi committed c3ffa57 on 8.x-3.x
    fix(FunctionComment): Methods named after the class should not throw...
klausi’s picture

Status: Active » Fixed
Issue tags: +DevDaysTransylvania

Thanks a lot for reporting! I pushed a fix with a test case.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.