| Conditions | 10 |
| Paths | 12 |
| Total Lines | 50 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| Bugs | 1 | Features | 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 |
||
| 64 | protected function getCacheObject(RequestInterface $request, ResponseInterface $response) |
||
| 65 | { |
||
| 66 | if (!isset($this->statusAccepted[$response->getStatusCode()])) { |
||
| 67 | // Don't cache it |
||
| 68 | return; |
||
| 69 | } |
||
| 70 | |||
| 71 | $cacheControl = new KeyValueHttpHeader($response->getHeader('Cache-Control')); |
||
| 72 | $varyHeader = new KeyValueHttpHeader($response->getHeader('Vary')); |
||
| 73 | |||
| 74 | if ($varyHeader->has('*')) { |
||
| 75 | // This will never match with a request |
||
| 76 | return; |
||
| 77 | } |
||
| 78 | |||
| 79 | if ($cacheControl->has('no-store')) { |
||
| 80 | // No store allowed (maybe some sensitives data...) |
||
| 81 | return; |
||
| 82 | } |
||
| 83 | |||
| 84 | if ($cacheControl->has('no-cache')) { |
||
| 85 | // Stale response see RFC7234 section 5.2.1.4 |
||
| 86 | $entry = new CacheEntry($request, $response, new \DateTime('-1 seconds')); |
||
| 87 | |||
| 88 | return $entry->hasValidationInformation() ? $entry : null; |
||
| 89 | } |
||
| 90 | |||
| 91 | foreach ($this->ageKey as $key) { |
||
| 92 | if ($cacheControl->has($key)) { |
||
| 93 | return new CacheEntry( |
||
| 94 | $request, |
||
| 95 | $response, |
||
| 96 | new \DateTime('+'.(int) $cacheControl->get($key).'seconds') |
||
| 97 | ); |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 101 | if ($response->hasHeader('Expires')) { |
||
| 102 | $expireAt = \DateTime::createFromFormat(\DateTime::RFC1123, $response->getHeaderLine('Expires')); |
||
| 103 | if ($expireAt !== false) { |
||
| 104 | return new CacheEntry( |
||
| 105 | $request, |
||
| 106 | $response, |
||
| 107 | $expireAt |
||
| 108 | ); |
||
| 109 | } |
||
| 110 | } |
||
| 111 | |||
| 112 | return new CacheEntry($request, $response, new \DateTime('-1 seconds')); |
||
| 113 | } |
||
| 114 | |||
| 213 |