Conditions | 12 |
Paths | 65 |
Total Lines | 49 |
Code Lines | 27 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
41 | public function getConfiguration($context = Config::CONTEXT_DEFAULT, $storeScopeLocally = false) |
||
42 | { |
||
43 | $key = 'current_cache_object_' . $context; |
||
44 | if (isset($this->config[$key]) && $this->config[$key] instanceof Config) { |
||
45 | return $this->config[$key]; |
||
46 | } |
||
47 | |||
48 | // By default we will get the config location from the remote server for each request. But we can override that. |
||
49 | if ($this->localCache instanceof StorageInterface && $storeScopeLocally) { |
||
50 | // If a local cache is defined we check there for the current scope key first |
||
51 | $currentConfigItem = $this->localCache->getItem($key); |
||
52 | // if we don't find the scope key we check the global cache |
||
53 | if (!$currentConfigItem) { |
||
54 | $currentConfigItem = $this->cache->getItem($key); |
||
55 | // If the primary cache gives us a value we store it locally |
||
56 | if ($currentConfigItem) { |
||
57 | $this->localCache->setItem($key, $currentConfigItem); |
||
58 | } |
||
59 | } |
||
60 | } else { |
||
61 | // Local cache is not configured, so we get the current config cache key from the global cache. |
||
62 | $currentConfigItem = $this->cache->getItem($key); |
||
63 | } |
||
64 | |||
65 | $config = null; |
||
66 | if ($this->localCache instanceof StorageInterface) { |
||
67 | // First we check the local cache for the configuration object if it exists. |
||
68 | $config = $this->localCache->getItem($currentConfigItem); |
||
69 | } |
||
70 | |||
71 | // Either way, if the config is null we check the global cache |
||
72 | if ($config === null) { |
||
73 | $config = $this->cache->getItem($currentConfigItem); |
||
74 | if ($config !== null) { |
||
75 | if ($this->localCache instanceof StorageInterface) { |
||
76 | $this->localCache->setItem($currentConfigItem, $config); |
||
77 | } |
||
78 | } |
||
79 | } |
||
80 | |||
81 | if ($config) { |
||
82 | $config = new Config($config); |
||
83 | $this->config[$key] = $config; |
||
84 | return $this->config[$key]; |
||
85 | } |
||
86 | $config = $this->builder->build($context); |
||
87 | $this->config[$key] = $config; |
||
88 | return $config; |
||
89 | } |
||
90 | |||
92 |