| Conditions | 10 |
| Paths | 113 |
| Total Lines | 30 |
| Code Lines | 21 |
| 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 |
||
| 43 | public function index(): void |
||
| 44 | { |
||
| 45 | $this->getRequest()->allowMethod(['get']); |
||
| 46 | |||
| 47 | /** @var \Authentication\Identity $user */ |
||
| 48 | $user = $this->Authentication->getIdentity(); |
||
| 49 | $this->set( |
||
| 50 | 'jobsAllow', |
||
| 51 | (array)Hash::extract($this->getMeta($user), 'resources./async_jobs.hints.allow') |
||
| 52 | ); |
||
| 53 | |||
| 54 | // set modules counters |
||
| 55 | $counters = Configure::read('UI.modules.counters', ['trash']); |
||
| 56 | if ($counters === 'none') { |
||
| 57 | return; |
||
| 58 | } |
||
| 59 | $counters = is_array($counters) || in_array($counters, ['none', 'all']) ? $counters : ['trash']; |
||
| 60 | $modules = array_keys((array)$this->viewBuilder()->getVar('modules')); |
||
| 61 | $modules = $counters === 'all' ? $modules : array_intersect($modules, $counters); |
||
| 62 | foreach ($modules as $name) { |
||
| 63 | if (CacheTools::existsCount($name)) { |
||
| 64 | continue; |
||
| 65 | } |
||
| 66 | $endpoint = $name === 'tags' ? '/model/tags' : $name; |
||
| 67 | $options = $name === 'tags' ? ['page_size' => 1] : ['limit' => 1, 'page_size' => 1, 'fields' => 'id']; |
||
| 68 | try { |
||
| 69 | $response = $this->apiClient->get($endpoint, $options); |
||
| 70 | CacheTools::setModuleCount($response, $name); |
||
| 71 | } catch (\Exception $e) { |
||
| 72 | CacheTools::setModuleCount(['meta' => ['pagination' => ['count' => '-']]], $name); |
||
| 73 | } |
||
| 89 |