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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

blazey created an issue. See original summary.

blazey’s picture

Status: Active » Needs review
FileSize
644 bytes
dawehner’s picture

Nice find!

This is IMHO an even better bugfix. This code will never be triggered anyway, see

    if (!empty($checks)) {
      $arguments_resolver = $this->argumentsResolverFactory->getArgumentsResolver($route_match, $account, $request);

      if (!$checks) {
        return AccessResult::neutral();
      }
blazey’s picture

Status: Needs review » Reviewed & tested by the community

Of course you're right :). If $checks is not empty it cannot be falsy either. Dead code, so changing status to RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Tasks can only go into 8.3.x. Patch looks nice. Less code - every little helps. Committed 92c311c and pushed to 8.3.x. Thanks!

  • alexpott committed 92c311c on 8.3.x
    Issue #2785991 by blazey, dawehner: Unnecessary call to AccessResult::...

Status: Fixed » Closed (fixed)

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