Problem/Motivation

From the codebase:

    if ($this->isForbidden() || $other->isForbidden()) {
      // Removed for brevity, either or both are forbidden
    }
    elseif ($this->isAllowed() || $other->isAllowed()) {
      // Removed for brevity, either or both are allowed
    }
    else {
      // Removed for brevity, both have to be neutral at this point
      // as we already checked for allowed and forbidden.
    }

Yet in that final branch, we have the following check:

      if (!$this->isNeutral() || ($this->getCacheMaxAge() === 0 && $other->isNeutral()) || ($this->getCacheMaxAge() !== 0 && $other instanceof CacheableDependencyInterface && $other->getCacheMaxAge() !== 0)) {
        $merge_other = TRUE;
      }

This can be simplified to:

      if ($this->getCacheMaxAge() === 0  || ($other instanceof CacheableDependencyInterface && $other->getCacheMaxAge() !== 0)) {
        $merge_other = TRUE;
      }

Steps to reproduce

See code, read code, see bug.

Proposed resolution

See above.

Remaining tasks

Create MR with changes above.

User interface changes

/

API changes

/

Data model changes

/

Release notes snippet

/

Issue fork drupal-3451602

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

kristiaanvandeneynde created an issue. See original summary.

kristiaanvandeneynde’s picture

Status: Active » Needs review
catch’s picture

Status: Needs review » Reviewed & tested by the community

Looks like really straightforward clean-up to me. Original code just looks like it was written extremely defensively in case forbidden/allowed/neutral weren't the only three options but they are.

mxr576’s picture

I agree, this a simple and clean optimization of the original solution. RTBC++

  • catch committed 2311b8bf on 10.4.x
    Issue #3451602 by kristiaanvandeneynde: AccessResult::orIf() has...

  • catch committed 1c814ad4 on 11.x
    Issue #3451602 by kristiaanvandeneynde: AccessResult::orIf() has...
catch’s picture

Version: 11.0.x-dev » 10.4.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 11.x and cherry-picked to 10.4.x, thanks!

Status: Fixed » Closed (fixed)

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