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