Conditions | 10 |
Paths | 16 |
Total Lines | 67 |
Code Lines | 41 |
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 |
||
46 | public function process(ServerRequestInterface $request, DelegateInterface $delegate) |
||
47 | { |
||
48 | $requestMethod = $request->getMethod(); |
||
49 | $key = str_replace(['\\', '/', ':', '*', '?', '"', '<', '>', '|'], '_', $request->getUri()->getPath().'?'.$request->getUri()->getQuery()); |
||
50 | |||
51 | if ($this->cacheCondition->isOk() && $requestMethod == 'GET') { |
||
52 | $cacheResponse = $this->cache->get($key); |
||
53 | if ($cacheResponse) { |
||
54 | $this->log->debug("Cache HIT on $key"); |
||
55 | |||
56 | return $cacheResponse; |
||
57 | } else { |
||
58 | $this->log->debug("Cache MISS on key $key"); |
||
59 | $response = $delegate->process($request); |
||
60 | |||
61 | $noCache = false; |
||
62 | if ($response->hasHeader('Mouf-Cache-Control') && $response->getHeader('Mouf-Cache-Control')[0] == 'no-cache') { |
||
63 | $noCache = true; |
||
64 | } |
||
65 | |||
66 | if ($noCache) { |
||
67 | $this->log->debug("Mouf NO CACHE header found, not storing '$key'"); |
||
68 | } else { |
||
69 | $ttl = null; |
||
70 | |||
71 | // TODO: continue here! |
||
72 | // Use PSR-7 response to analyze maxage and expires... |
||
73 | // ...or... use a completely different HTTP cache implementation!!! |
||
74 | // There must be one around for PSR-7! |
||
75 | |||
76 | $maxAge = $response->getMaxAge(); |
||
|
|||
77 | $expires = $response->getExpires(); |
||
78 | if ($maxAge) { |
||
79 | $this->log->debug("MaxAge specified : $maxAge"); |
||
80 | $ttl = $maxAge; |
||
81 | } elseif ($expires) { |
||
82 | $this->log->debug("Expires specified : $expires"); |
||
83 | $ttl = date_diff($expires, new \DateTime())->s; |
||
84 | } |
||
85 | |||
86 | if ($ttl) { |
||
87 | $this->log->debug("TTL is : $ttl"); |
||
88 | } |
||
89 | |||
90 | // Make sure the response is serializable |
||
91 | $serializableResponse = new Response(); |
||
92 | $serializableResponse->headers = $response->headers; |
||
93 | |||
94 | ob_start(); |
||
95 | $response->sendContent(); |
||
96 | $content = ob_get_clean(); |
||
97 | |||
98 | $serializableResponse->setContent($content); |
||
99 | |||
100 | $this->cache->set($key, $serializableResponse, $ttl); |
||
101 | $this->log->debug("Cache STORED on key $key"); |
||
102 | $response = $serializableResponse; |
||
103 | } |
||
104 | |||
105 | return $response; |
||
106 | } |
||
107 | } else { |
||
108 | $this->log->debug("No cache for $key"); |
||
109 | |||
110 | return $this->fallBackRouter->handle($request, $type, $catch); |
||
111 | } |
||
112 | } |
||
113 | } |
||
114 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.