Conditions | 10 |
Paths | 512 |
Total Lines | 82 |
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 |
||
86 | protected function _renderDashboard(string $type = null) : string |
||
87 | { |
||
88 | $categoryModel = new Model\Category(); |
||
89 | $articleModel = new Model\Article(); |
||
90 | $extraModel = new Model\Extra(); |
||
91 | $commentModel = new Model\Comment(); |
||
92 | $userModel = new Model\User(); |
||
93 | $groupModel = new Model\Group(); |
||
94 | $moduleModel = new Model\Module(); |
||
95 | $filesystem = new Filesystem\Filesystem(); |
||
96 | $divider = '/'; |
||
97 | |||
98 | /* html element */ |
||
99 | |||
100 | $element = new Html\Element(); |
||
101 | $titleElement = $element |
||
102 | ->copy() |
||
103 | ->init('h3', |
||
104 | [ |
||
105 | 'class' => $this->_optionArray['className']['dashboard']['title'] |
||
106 | ]); |
||
107 | $textElement = $element |
||
108 | ->copy() |
||
109 | ->init('span', |
||
110 | [ |
||
111 | 'class' => $this->_optionArray['className']['dashboard']['text'] |
||
112 | ]); |
||
113 | |||
114 | /* handle type */ |
||
115 | |||
116 | if ($type === 'categories') |
||
117 | { |
||
118 | $titleElement->text($categoryModel->query()->where('status', 1)->count() . $divider . $categoryModel->query()->count()); |
||
119 | $textElement->text($this->_language->get('_reporter')['categories_publish']); |
||
120 | } |
||
121 | if ($type === 'articles') |
||
122 | { |
||
123 | $titleElement->text($articleModel->query()->where('status', 1)->count() . $divider . $articleModel->query()->count()); |
||
124 | $textElement->text($this->_language->get('_reporter')['articles_publish']); |
||
125 | } |
||
126 | if ($type === 'extras') |
||
127 | { |
||
128 | $titleElement->text($extraModel->query()->where('status', 1)->count() . $divider . $extraModel->query()->count()); |
||
129 | $textElement->text($this->_language->get('_reporter')['extras_publish']); |
||
130 | } |
||
131 | if ($type === 'comments') |
||
132 | { |
||
133 | $titleElement->text($commentModel->query()->where('status', 1)->count() . $divider . $commentModel->query()->count()); |
||
134 | $textElement->text($this->_language->get('_reporter')['comments_publish']); |
||
135 | } |
||
136 | if ($type === 'users') |
||
137 | { |
||
138 | $titleElement->text($userModel->query()->where('status', 1)->count() . $divider . $userModel->query()->count()); |
||
139 | $textElement->text($this->_language->get('_reporter')['users_enable']); |
||
140 | } |
||
141 | if ($type === 'groups') |
||
142 | { |
||
143 | $titleElement->text($groupModel->query()->where('status', 1)->count() . $divider . $groupModel->query()->count()); |
||
144 | $textElement->text($this->_language->get('_reporter')['groups_enable']); |
||
145 | } |
||
146 | if ($type === 'modules') |
||
147 | { |
||
148 | $titleElement->text($moduleModel->query()->count() . $divider . $filesystem->init('modules')->countIterator()); |
||
149 | $textElement->text($this->_language->get('_reporter')['modules_install']); |
||
150 | } |
||
151 | if ($type === 'languages') |
||
152 | { |
||
153 | $titleElement->text($filesystem->init('languages')->countIterator()); |
||
154 | $textElement->text($this->_language->get('_reporter')['languages_install']); |
||
155 | } |
||
156 | if ($type === 'templates') |
||
157 | { |
||
158 | $titleElement->text($filesystem->init('templates', false, |
||
159 | [ |
||
160 | 'admin', |
||
161 | 'console', |
||
162 | 'install' |
||
163 | ])->countIterator()); |
||
164 | $textElement->text($this->_language->get('_reporter')['templates_install']); |
||
165 | } |
||
166 | return $titleElement . $textElement; |
||
167 | } |
||
168 | } |
||
169 |