The Drupal\comment\Controller\CommentController::getReplyForm() method never returns a RedirectResponse object.

Issue fork drupal-3536999

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

chesn0k created an issue. See original summary.

chesn0k’s picture

Version: 11.2.x-dev » 11.x-dev

chesn0k changed the visibility of the branch 3536999-drupal_comment-getreplyform-never-returns-object to hidden.

chesn0k’s picture

Status: Active » Needs review
niklan’s picture

Status: Needs review » Reviewed & tested by the community

Confirming that this is an issue with PHPStan 2 (Level 9) when a controller is extended, e.g., for decorating purposes or any other.

final class ExampleController extends CommentController {

  public function __invoke(Request $request, EntityInterface $entity, string $field_name, ?int $pid = null): array {
    $build = parent::getReplyForm($request, $entity, $field_name, $pid);

    $children = [];
    foreach (Element::children($build) as $child) {
      $children[] = $build[$child];
    }

    return [
      '#theme' => 'example_theme_hook',
      '#children' => $children,
    ];
  }

}

This example will lead to an error:

Parameter #1 $elements of static method Drupal\Core\Render\Element::children() expects array, array|Symfony\Component\HttpFoundation\RedirectResponse given.

But it never returns a response. The proposed solution fixes it. Also, the documentation for the return type implies that it is always an array; it does not specify when it is possible to get a RedirectResponse.

catch’s picture

Version: 11.x-dev » 11.2.x-dev
Status: Reviewed & tested by the community » Fixed

This looks like either copypasta or cruft left over from a refactor - other methods in the class return redirects.

Committed/pushed to 11.x, thanks!

  • catch committed 4a461d26 on 11.2.x
    Issue #3536999 by chesn0k, niklan: Drupal\comment\Controller\...

  • catch committed be61071f on 11.x
    Issue #3536999 by chesn0k, niklan: Drupal\comment\Controller\...

catch’s picture

Status: Fixed » Closed (fixed)

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