Problem/Motivation

The method \Drupal\Core\KeyValueStore\DatabaseStorage::doSetIfNotExists currently has public visibility, but should be protected.

https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Core/KeyValueStore/DatabaseStorage.php?ref_type=heads#L170

The prefix "do" is typically used for internal implementation, while the regular method that calls "do*" functions acts as a wrapper. For example, the method ::set() is public, while ::doSet() is protected.

By keeping the method ::doSetIfNotExists() public, it forces classes that extend DatabaseStorage to implement it, even if it's not necessary. This method is also not a part of the interface.

Proposed resolution

Change the visibility of the method from public to protected. This change will not break the code that extends DatabaseStorage because in that case, it can change visibility from protected to public but not from public to protected.

The only concern is if someone uses it directly (core doesn't). In that case, we should deprecate its usage and change the signature in Drupal 12. However, I think this is overkill because it is clearly an internal method.

Issue fork drupal-3485410

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

niklan created an issue. See original summary.

niklan changed the visibility of the branch 11.1.x to hidden.

niklan’s picture

Status: Active » Needs review
andypost’s picture

Issue tags: +Needs change record

CR required to notify devs

andypost’s picture

Issue tags: -Needs change record

Added CR

andypost’s picture

Status: Needs review » Reviewed & tested by the community

Looks good if no deprecation dance required

  • longwave committed 64cc6471 on 11.x
    Issue #3485410 by niklan, andypost: \Drupal\Core\KeyValueStore\...
longwave’s picture

Version: 11.1.x-dev » 11.x-dev
Status: Reviewed & tested by the community » Fixed

I agree that this was likely just an oversight and nobody should be calling this directly, let's just clean this up in 11.2 only as it's not really doing any harm.

Committed 64cc647 and pushed to 11.x. Thanks!

longwave’s picture

Published the change record.

Status: Fixed » Closed (fixed)

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