| Conditions | 10 |
| Paths | 10 |
| Total Lines | 34 |
| Code Lines | 17 |
| 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 /** MicroController */ |
||
| 70 | public function applyFilters($action, $isPre = true, array $filters = [], $data = null) |
||
| 71 | { |
||
| 72 | if (!$filters) { |
||
|
|
|||
| 73 | return $data; |
||
| 74 | } |
||
| 75 | |||
| 76 | foreach ($filters as $filter) { |
||
| 77 | if (empty($filter['class']) || !class_exists($filter['class'])) { |
||
| 78 | continue; |
||
| 79 | } |
||
| 80 | |||
| 81 | if (empty($filter['actions']) || !in_array($action, $filter['actions'], true)) { |
||
| 82 | continue; |
||
| 83 | } |
||
| 84 | |||
| 85 | /** @var \Micro\Filter\IFilter $_filter */ |
||
| 86 | $_filter = new $filter['class']($action); |
||
| 87 | /** @var ResponseInterface $response */ |
||
| 88 | $response = $isPre ? $_filter->pre($filter) : $_filter->post($filter + ['data' => $data]); |
||
| 89 | |||
| 90 | if (!$response) { |
||
| 91 | if (!empty($_filter->result['redirect'])) { |
||
| 92 | /** @var ResponseInterface $redirect */ |
||
| 93 | $redirect = (new ResponseInjector)->build(); |
||
| 94 | return $redirect->withHeader('Location', $_filter->result['redirect']); |
||
| 95 | } |
||
| 96 | throw new Exception($_filter->result['message']); |
||
| 97 | } |
||
| 98 | /** @noinspection CallableParameterUseCaseInTypeContextInspection */ |
||
| 99 | $data = $response; |
||
| 100 | } |
||
| 101 | |||
| 102 | return $data; |
||
| 103 | } |
||
| 104 | |||
| 131 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.