Conditions | 12 |
Paths | 3 |
Total Lines | 43 |
Code Lines | 29 |
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 |
||
61 | public function dashboardAction() |
||
62 | { |
||
63 | $model = new ViewModel(); |
||
64 | $model->setTemplate('core/index/dashboard'); |
||
65 | $modules = $this->moduleManager->getLoadedModules(); |
||
66 | foreach ($this->config('dashboard', array_keys($modules)) as $module => $cfg) { |
||
67 | if (!isset($cfg['enabled']) || true !== $cfg['enabled']) { |
||
68 | continue; |
||
69 | } |
||
70 | foreach ($cfg['widgets'] as $captureTo => $spec) { |
||
71 | if (isset($spec['controller'])) { |
||
72 | $params = array('action' => 'dashboard'); |
||
73 | if (isset($spec['params'])) { |
||
74 | $params = array_merge($params, $spec['params']); |
||
75 | } |
||
76 | |||
77 | $viewModel = $this->forward()->dispatch($spec['controller'], $params); |
||
78 | // we ignore all errors and simply continue with the error template as widget content |
||
79 | $response = $this->getResponse(); |
||
80 | if (200 != $response->getStatusCode()) { |
||
81 | $response->setStatusCode(200); |
||
82 | $viewModel = array( |
||
83 | 'content' => 'Error loading widget.', |
||
84 | ); |
||
85 | } |
||
86 | if (!$viewModel instanceof ViewModel) { |
||
87 | $viewModel = new ViewModel($viewModel); |
||
88 | } |
||
89 | if ($template = $viewModel->getTemplate()) { |
||
90 | $viewModel->setVariable('script', $template); |
||
91 | } |
||
92 | } elseif (isset($spec['script'])) { |
||
93 | $viewModel = new ViewModel(array('script' => $spec['script'])); |
||
94 | } elseif (isset($spec['content'])) { |
||
95 | $viewModel = new ViewModel(array('content' => $spec['content'])); |
||
96 | } |
||
97 | |||
98 | $viewModel->setTemplate('core/index/dashboard-widget.phtml'); |
||
99 | $model->addChild($viewModel, "dashboard_{$module}_{$captureTo}"); |
||
100 | } |
||
101 | } |
||
102 | return $model; |
||
103 | } |
||
104 | |||
113 |
This check marks private properties in classes that are never used. Those properties can be removed.