| Conditions | 11 | 
| Paths | 1024 | 
| Total Lines | 45 | 
| Code Lines | 22 | 
| 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 | ||
| 124 | protected function setCacheContorlHeader(Response $response): Response | ||
| 125 |     { | ||
| 126 | $cacheControlConfig = $this->getConfig()->getCacheControlConfig(); | ||
| 127 | |||
| 128 |         if (!empty($cacheControlConfig[static::CONFIG_CACHE_CONTROL_DIRECTIVE_PUBLIC])) { | ||
| 129 | $response->setPublic(); | ||
| 130 | } | ||
| 131 | |||
| 132 |         if (!empty($cacheControlConfig[static::CONFIG_CACHE_CONTROL_DIRECTIVE_PRIVATE])) { | ||
| 133 | $response->setPrivate(); | ||
| 134 | } | ||
| 135 | |||
| 136 |         if (!empty($cacheControlConfig[static::CONFIG_CACHE_CONTROL_DIRECTIVE_MAX_AGE])) { | ||
| 137 | $response->setMaxAge($cacheControlConfig[static::CONFIG_CACHE_CONTROL_DIRECTIVE_MAX_AGE]); | ||
| 138 | } | ||
| 139 | |||
| 140 |         if (!empty($cacheControlConfig[static::CONFIG_CACHE_CONTROL_DIRECTIVE_S_MAX_AGE])) { | ||
| 141 | $response->setSharedMaxAge($cacheControlConfig[static::CONFIG_CACHE_CONTROL_DIRECTIVE_S_MAX_AGE]); | ||
| 142 | } | ||
| 143 | |||
| 144 |         if (!empty($cacheControlConfig[static::CONFIG_CACHE_CONTROL_DIRECTIVE_NO_CACHE])) { | ||
| 145 | $response->headers->addCacheControlDirective(static::CONFIG_CACHE_CONTROL_DIRECTIVE_NO_CACHE, true); | ||
| 146 | } | ||
| 147 | |||
| 148 |         if (!empty($cacheControlConfig[static::CONFIG_CACHE_CONTROL_DIRECTIVE_MUST_REVALIDATE])) { | ||
| 149 | $response->headers->addCacheControlDirective(static::CONFIG_CACHE_CONTROL_DIRECTIVE_MUST_REVALIDATE, true); | ||
| 150 | } | ||
| 151 | |||
| 152 |         if (!empty($cacheControlConfig[static::CONFIG_CACHE_CONTROL_DIRECTIVE_NO_STORE])) { | ||
| 153 | $response->headers->addCacheControlDirective(static::CONFIG_CACHE_CONTROL_DIRECTIVE_NO_STORE, true); | ||
| 154 | } | ||
| 155 | |||
| 156 |         if (!empty($cacheControlConfig[static::CONFIG_CACHE_CONTROL_DIRECTIVE_NO_TRANSFORM])) { | ||
| 157 | $response->headers->addCacheControlDirective(static::CONFIG_CACHE_CONTROL_DIRECTIVE_NO_TRANSFORM, true); | ||
| 158 | } | ||
| 159 | |||
| 160 |         if (!empty($cacheControlConfig[static::CONFIG_CACHE_CONTROL_DIRECTIVE_IMMUTABLE])) { | ||
| 161 | $response->headers->addCacheControlDirective(static::CONFIG_CACHE_CONTROL_DIRECTIVE_IMMUTABLE, true); | ||
| 162 | } | ||
| 163 | |||
| 164 |         if (!empty($cacheControlConfig[static::CONFIG_CACHE_CONTROL_STALE_WHILE_REVALIDATE])) { | ||
| 165 | $response->headers->addCacheControlDirective(static::CONFIG_CACHE_CONTROL_STALE_WHILE_REVALIDATE, true); | ||
| 166 | } | ||
| 167 | |||
| 168 | return $response; | ||
| 169 | } | ||
| 171 |