CacheableDependencyInterface::getCacheTags should return a list<string> for compatibility with Cache::mergeTags

Created on 9 February 2025, about 1 month ago

Problem/Motivation

As of πŸ“Œ sebastianbergmann/comparator:5.0.2 Introduces (for Drupal) breaking changes Fixed Cache::mergeTags must be passed a list<string> of cache tags. This means if you're using a common pattern where you override getCacheTags in a block, entity type, etc, and call mergeTags from the parent, you need to run it through array_values. This can get very repetitive.

Steps to reproduce

Implement an entity type or block plugin and override getCacheTags with the following code:

  public function getCacheTags() {
    return Cache::mergeTags(parent::getCacheTags(), ['some:tag']);
  }

PHPStan will now complain:

Parameter #1 ...$cache_tags of static method Drupal\Core\Cache\Cache::mergeTags() expects list<string>,  
         array<string> given.                                                                                     
         πŸ’‘ array<string> might not be a list.

The fix is to wrap parent::getCacheTags in array_values()

Proposed resolution

Change return type of CacheableDependencyInterface::getCacheTags to list<string>

Remaining tasks

Agree

User interface changes

None

Introduced terminology

None

API changes

Changed return type of CacheableDependencyInterface::getCacheTags

Data model changes

None

Release notes snippet

TBC

πŸ“Œ Task
Status

Active

Version

11.1 πŸ”₯

Component

base system

Created by

πŸ‡¦πŸ‡ΊAustralia acbramley

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024