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