Problem/Motivation

When using dependency injection, the calling code can provide a different implementation of a dependency as long as it follows the same interface. This is a common practice is testing scenarios and profiling, for example Drupal uses this in Simpletest and in the Webprofiler contrib module.

When the dependency is typecast to a specific class, the service is no longer swappable. Depending on the calling code, this can result in notices or errors.

Proposed resolution

Replace typecasted dependencies with their associated Interface when available.

Remaining tasks

  1. Write a patch
  2. Review
  3. Commit

User interface changes

None.

API changes

None.

Data model changes

None.

Comments

idebr created an issue. See original summary.

idebr’s picture

Status: Active » Needs review
StatusFileSize
new8.13 KB

Attached patch replaces type casted dependencies with their associated Interface when available.

  • miro_dietiker committed 46cc60b on 8.x-1.x authored by idebr
    Issue #2975973 by idebr: Typecast dependency injected classes to their...
idebr’s picture

Status: Needs review » Fixed

It appears the patch in #2 was committed recently, so updating the issue status to 'Fixed'. See http://cgit.drupalcode.org/paragraphs/commit/?id=46cc60b7a5650ca3b925d35...

miro_dietiker’s picture

Yeah thx. My comment was somehow dropped... :-)

Status: Fixed » Closed (fixed)

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