Verified Commit a7b77cbf authored by godotislate's avatar godotislate
Browse files

task: #3575492 Add [#NoDiscard] to CacheableMetadata::merge()

By: joachim
By: andypost
By: smustgrave
By: prudloff
parent 61a6cb28
Loading
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ class Cache {
   * @return list<string>
   *   The merged list of cache contexts.
   */
  #[\NoDiscard]
  public static function mergeContexts(array ...$cache_contexts) {
    $cache_contexts = array_values(array_unique(array_merge(...$cache_contexts)));
    assert(\Drupal::service('cache_contexts_manager')->assertValidTokens($cache_contexts), sprintf('Failed to assert that "%s" are valid cache contexts.', implode(', ', $cache_contexts)));
@@ -48,6 +49,7 @@ public static function mergeContexts(array ...$cache_contexts) {
   * @return list<string>
   *   The merged list of cache tags.
   */
  #[\NoDiscard]
  public static function mergeTags(array ...$cache_tags) {
    $cache_tags = array_values(array_unique(array_merge(...$cache_tags)));
    assert(Inspector::assertAllStrings($cache_tags), 'Cache tags must be valid strings');
@@ -65,6 +67,7 @@ public static function mergeTags(array ...$cache_tags) {
   * @return int
   *   The minimum max-age value.
   */
  #[\NoDiscard]
  public static function mergeMaxAges(...$max_ages) {
    // Remove Cache::PERMANENT values to return the correct minimum value.
    $max_ages = array_filter($max_ages, function ($max_age) {
+1 −0
Original line number Diff line number Diff line
@@ -89,6 +89,7 @@ public function setCacheMaxAge($max_age) {
   * @return static
   *   A new CacheableMetadata object, with the merged data.
   */
  #[\NoDiscard]
  public function merge(CacheableMetadata $other) {
    $result = clone $this;

+1 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ class BubbleableMetadata extends CacheableMetadata implements AttachmentsInterfa
   * @return static
   *   A new bubbleable metadata object, with the merged data.
   */
  #[\NoDiscard]
  public function merge(CacheableMetadata $other) {
    $result = parent::merge($other);