Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
According to the documentation of \Drupal\Core\Entity\EntityTypeInterface::getHandlerClass()
the method should return NULL if a handler class is not set.
We never test for this outcome.
Proposed resolution
Add a test case to Drupal\Tests\Core\Entity\EntityTypeTest
to ensure that a NULL result is possible.
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#18 | interdiff-15-18.txt | 524 bytes | Hardik_Patel_12 |
#18 | 2910775-18.patch | 658 bytes | Hardik_Patel_12 |
Comments
Comment #2
hchonovComment #3
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedIf a function doesn't return anything it behaves exactly the same as if it returned
NULL
. See below:Comment #4
dawehnerYeah this is not a bug , maybe a task ... slightly better code?
Comment #5
vijaycs85Comment #6
vijaycs85Comment #7
Mile23Rescoping because
EntityType::getHandlerClass()
seems to returnNULL
by not returning anything based onhasHandlerClass()
.This makes it an easy unit test to add to
Drupal\Tests\Core\Entity\EntityTypeTest
, because we never test for this outcome.Comment #8
Ivan Berezhnov CreditAttribution: Ivan Berezhnov as a volunteer and at Drupal Ukraine Community for Levi9 commentedComment #13
Sivaji_Ganesh_Jojodae CreditAttribution: Sivaji_Ganesh_Jojodae as a volunteer and commentedNot sure if the attached test & code change is what intended. Please review.
Comment #14
hchonovInstead of creating a new test we could incorporate these 2 lines in
::testGetHandler()
.Comment #15
Sivaji_Ganesh_Jojodae CreditAttribution: Sivaji_Ganesh_Jojodae as a volunteer and commentedMakes sense. Patch re-rolled to reflect the change.
Comment #16
hchonovThank you.
Comment #17
alexpottThis is not needed. It is implicit when there is no return. I do not want to encourage a spate of issues adding
return NULL
everywhere.Comment #18
Hardik_Patel_12 CreditAttribution: Hardik_Patel_12 at QED42 for Drupal India Association commentedfunction test()
{
return null;
}
function test()
{
return;
}
function test()
{
}
In all cases there for var_dump(test()); will be:
NULL
Kindly review a new patch.
Comment #19
Hardik_Patel_12 CreditAttribution: Hardik_Patel_12 at QED42 for Drupal India Association commentedComment #20
ravi.shankar CreditAttribution: ravi.shankar at OpenSense Labs commentedPatch #18 looks good to me, so making it RTBC.
Comment #21
hchonovI understand your worries, however I consider no explicit return a bad practice and I hope that there aren't that many places without explicit returns.
Comment #22
alexpott@hchonov okay I committed #15. I can buy the argument that when you have a return it's best that all returns are explicit.
Committed and pushed b6bf07b8aa to 9.0.x and a1468fef85 to 8.9.x. Thanks!