| Conditions | 19 |
| Paths | 82 |
| Total Lines | 56 |
| Code Lines | 31 |
| 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 |
||
| 24 | public function shouldCache(MvcEvent $event) |
||
| 25 | { |
||
| 26 | $except = $this->getExcept(); |
||
| 27 | |||
| 28 | if (!isset($except['namespaces']) && !isset($except['controllers']) && !isset($except['actions'])) { |
||
| 29 | throw new BadConfigurationException( |
||
| 30 | "At least one of ['namespaces', 'controllers', 'actions'] keys has to be set in the " |
||
| 31 | . "\$config['strokercache']['strategies']['enabled']['" . __CLASS__ . "']['except'][] " |
||
| 32 | . "configuration array." |
||
| 33 | ); |
||
| 34 | } |
||
| 35 | |||
| 36 | $routeMatch = $event->getRouteMatch(); |
||
| 37 | |||
| 38 | if (null === $routeMatch) { |
||
| 39 | return false; |
||
| 40 | } |
||
| 41 | |||
| 42 | $controller = $this->normalize($routeMatch->getParam('controller')); |
||
| 43 | $action = $this->normalize($routeMatch->getParam('action')); |
||
| 44 | |||
| 45 | $shouldCache = true; |
||
| 46 | |||
| 47 | if (true === $shouldCache && isset($except['namespaces'])) { |
||
| 48 | foreach ($except['namespaces'] as $exceptNamespace) { |
||
| 49 | if (0 === strpos($controller, $this->normalize($exceptNamespace))) { |
||
| 50 | $shouldCache = false; |
||
| 51 | break 1; |
||
| 52 | } |
||
| 53 | } |
||
| 54 | } |
||
| 55 | |||
| 56 | if (true === $shouldCache && isset($except['controllers'])) { |
||
| 57 | foreach ($except['controllers'] as $exceptController) { |
||
| 58 | if ($controller === $this->normalize($exceptController)) { |
||
| 59 | $shouldCache = false; |
||
| 60 | break 1; |
||
| 61 | } |
||
| 62 | } |
||
| 63 | } |
||
| 64 | |||
| 65 | if (true === $shouldCache && isset($except['actions'])) { |
||
| 66 | foreach ($except['actions'] as $exceptController => $exceptActions) { |
||
| 67 | if ($controller === $this->normalize($exceptController)) { |
||
| 68 | foreach ($exceptActions as $exceptAction) { |
||
| 69 | if ($action === $this->normalize($exceptAction)) { |
||
| 70 | $shouldCache = false; |
||
| 71 | break 2; |
||
| 72 | } |
||
| 73 | } |
||
| 74 | } |
||
| 75 | } |
||
| 76 | } |
||
| 77 | |||
| 78 | return $shouldCache; |
||
| 79 | } |
||
| 80 | |||
| 115 |