ResourceResponseSubscriber typehints and checks for ResourceResponseInterface but then calls other methods

Created on 26 April 2022, over 2 years ago
Updated 18 December 2023, 9 months ago

Problem/Motivation

In ResourceResponseSubscriber we have:

    if (!$response instanceof ResourceResponseInterface) {
      return;
    }

...

  protected function renderResponseBody(Request $request, ResourceResponseInterface $response, SerializerInterface $serializer, $format) {

...

  protected function flattenResponse(ResourceResponseInterface $response) {

but opening this class in an IDE shows a number of other methods are called on the $response, including:

    $final_response->setContent($response->getContent());
    $final_response->setStatusCode($response->getStatusCode());
    $final_response->setProtocolVersion($response->getProtocolVersion());

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component
RESTΒ  β†’

Last updated 6 days ago

Created by

πŸ‡¬πŸ‡§United Kingdom joachim

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    I think the solution here is that there is no interface for ResourceResponseInterface to extend from

    But the type hint in ResponseEvent::getResponse ensures that it is an instance of Response, which is where the other methods come from.

    I don't think we need to do anything here, the return type hint on \Symfony\Component\HttpKernel\Event\ResponseEvent::getResponse is enough

    Thoughts @joachim - I think this can be closed works as designed now there's a stronger return type-hint on that method than was probably there when this was filed.

Production build 0.71.5 2024