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
In the following code (Drupal\Core\Access\AccessManager::check(), line 130) AccessResult::neutral()
is preloaded and stored in $result
. 5 lines later another call to this method is made return AccessResult::neutral();
. Returning $result does exactly the same and saves one method call.
$result = AccessResult::neutral();
if (!empty($checks)) {
$arguments_resolver = $this->argumentsResolverFactory->getArgumentsResolver($route_match, $account, $request);
if (!$checks) {
return AccessResult::neutral();
}
Proposed resolution
Return $result
instead of AccessResult::neutral()
.
Remaining tasks
None
User interface changes
None
API changes
None
Data model changes
None
Comment | File | Size | Author |
---|---|---|---|
#3 | 2785991-3.patch | 778 bytes | dawehner |
#2 | access_manager_unnecessary_method_call-2785991-3.patch | 644 bytes | blazey |
Comments
Comment #2
blazey CreditAttribution: blazey as a volunteer commentedComment #3
dawehnerNice find!
This is IMHO an even better bugfix. This code will never be triggered anyway, see
Comment #4
blazey CreditAttribution: blazey as a volunteer commentedOf course you're right :). If
$checks
is not empty it cannot be falsy either. Dead code, so changing status to RTBC.Comment #5
alexpottTasks can only go into 8.3.x. Patch looks nice. Less code - every little helps. Committed 92c311c and pushed to 8.3.x. Thanks!