| Conditions | 10 |
| Paths | 10 |
| Total Lines | 32 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 /** MicroController */ |
||
| 79 | public function applyFilters($action, $isPre = true, array $filters = [], $data = null) |
||
| 80 | { |
||
| 81 | if (!$filters) { |
||
| 82 | return $data; |
||
| 83 | } |
||
| 84 | |||
| 85 | foreach ($filters AS $filter) { |
||
| 86 | if (empty($filter['class']) || !class_exists($filter['class'])) { |
||
| 87 | continue; |
||
| 88 | } |
||
| 89 | |||
| 90 | if (empty($filter['actions']) || !in_array($action, $filter['actions'], true)) { |
||
| 91 | continue; |
||
| 92 | } |
||
| 93 | |||
| 94 | /** @var \Micro\Filter\IFilter $_filter */ |
||
| 95 | $_filter = new $filter['class']($action, $this->container); |
||
| 96 | |||
| 97 | $res = $isPre ? $_filter->pre($filter) : $_filter->post($filter + ['data' => $data]); |
||
| 98 | if (!$res) { |
||
| 99 | if (!empty($_filter->result['redirect'])) { |
||
| 100 | header('Location: ' . $_filter->result['redirect']); |
||
| 101 | |||
| 102 | die(); |
||
| 103 | } |
||
| 104 | throw new Exception($_filter->result['message']); |
||
| 105 | } |
||
| 106 | $data = $res; |
||
| 107 | } |
||
| 108 | |||
| 109 | return $data; |
||
| 110 | } |
||
| 111 | |||
| 134 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: