Completed
Pull Request — 8.x-3.x (#525)
by Philipp
03:00
created

CacheablePluginTrait   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B buildCacheMetadata() 0 10 7
1
<?php
2
3
namespace Drupal\graphql\Plugin\GraphQL\Traits;
4
5
use Drupal\Core\Cache\CacheBackendInterface;
6
7
trait CacheablePluginTrait {
8
9
  /**
10
   * @param $definition
11
   *
12
   * @return array
13
   */
14
  protected function buildCacheMetadata($definition) {
15
    return [
16
      'schema_cache_contexts' => isset($definition['schema_cache_contexts']) ? $definition['schema_cache_contexts'] : ['languages:language_interface'],
17
      'schema_cache_tags' => isset($definition['schema_cache_tags']) ? $definition['schema_cache_tags'] : [],
18
      'schema_cache_max_age' => isset($definition['schema_cache_max_age']) ? $definition['schema_cache_max_age'] : CacheBackendInterface::CACHE_PERMANENT,
19
      'response_cache_contexts' => isset($definition['response_cache_contexts']) ? $definition['response_cache_contexts'] : ['user.permissions'],
20
      'response_cache_tags' => isset($definition['response_cache_tags']) ? $definition['response_cache_tags'] : [],
21
      'response_cache_max_age' => isset($definition['response_cache_max_age']) ? $definition['response_cache_max_age'] : CacheBackendInterface::CACHE_PERMANENT,
22
    ];
23
  }
24
}
25