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
- Write a patch
- Review
- Commit
User interface changes
None.
API changes
None.
Data model changes
None.
Comments
Comment #2
idebr commentedAttached patch replaces type casted dependencies with their associated Interface when available.
Comment #4
idebr commentedIt appears the patch in #2 was committed recently, so updating the issue status to 'Fixed'. See http://cgit.drupalcode.org/paragraphs/commit/?id=46cc60b7a5650ca3b925d35...
Comment #5
miro_dietikerYeah thx. My comment was somehow dropped... :-)