Problem/Motivation
The \Drupal\comment\CommentInterface::getCommentedEntity() definition is the following:
/**
* Returns the entity to which the comment is attached.
*
* @return \Drupal\Core\Entity\FieldableEntityInterface
* The entity on which the comment is attached.
*/
public function getCommentedEntity();
The PHPDoc states that the method always returns a FieldableEntityInterface; however, in fact, the method may also return NULL in some cases like when a host entity was removed but the comment left orphan.
The incorrect documentation may lead to bugs caused by an assumption that a return value is always not empty.
An example of such bug is #2565247: Fatal error: Call to a member function url() on null
Proposed resolution
Correct the method doc.
User interface changes
None.
API changes
The \Drupal\comment\CommentInterface::getCommentedEntity() method PHPDoc @return will be updated; the API is not changed though.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#4 | interdiff-2-4.txt | 578 bytes | abramm |
#4 | drupal-fix_incorrect_getCommentedEntity_phpdoc-3001851-4.patch | 690 bytes | abramm |
Comments
Comment #2
abrammHere's a simple patch fixing this.
Changed the issue Component to 'documentation'.
Comment #3
longwaveLooks good, one tiny point:
"is an orphan" is better English.
Comment #4
abrammThank you @longwave.
Easiest fix ever.
Comment #5
longwaveThank you for the quick fix, looks great!
Comment #6
alexpottCommitted and pushed f8f869f223 to 8.7.x and 98bc15d7ed to 8.6.x. Thanks!