| Total Complexity | 49 |
| Total Lines | 247 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like DataManagerController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use DataManagerController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 11 | class DataManagerController extends Controller { |
||
|
|
|||
| 12 | |||
| 13 | public function parseRequest() { |
||
| 64 | } |
||
| 65 | |||
| 66 | public function indexAction() { |
||
| 67 | $result = new Server\Result(); |
||
| 68 | |||
| 69 | ob_start(); |
||
| 70 | |||
| 71 | $request = $this->parseRequest(); |
||
| 72 | |||
| 73 | $dataManager = new Ui\DataManager($request['modelName'], $request['managerName']); |
||
| 74 | $dataManager->draw($request['params'], $request['model']); |
||
| 75 | |||
| 76 | $result->content = ob_get_contents(); |
||
| 77 | |||
| 78 | ob_end_clean(); |
||
| 79 | |||
| 80 | $result->send(); |
||
| 81 | } |
||
| 82 | |||
| 83 | public function loadRowsAction() { |
||
| 84 | $result = new Server\Result(); |
||
| 85 | $result->content = []; |
||
| 86 | |||
| 87 | ob_start(); |
||
| 88 | |||
| 89 | $request = $this->parseRequest(); |
||
| 90 | |||
| 91 | $dataManager = new Ui\DataManager($request['modelName'], $request['managerName']); |
||
| 92 | if ($request['download']) { |
||
| 93 | |||
| 94 | ini_set('memory_limit', '4000M'); |
||
| 95 | set_time_limit(0); |
||
| 96 | |||
| 97 | $request['params']['all'] = true; |
||
| 98 | $request['params']['download'] = true; |
||
| 99 | ob_end_clean(); |
||
| 100 | header('Content-Encoding: UTF-8'); |
||
| 101 | header("Content-Type: text/csv"); |
||
| 102 | header("Content-Disposition: attachment; filename=" . str_replace(' ', '_', $request['modelName']::$objectName ? $request['modelName']::$objectName : $request['modelName']) . ".csv"); |
||
| 103 | echo "\xEF\xBB\xBF"; // UTF-8 BOM |
||
| 104 | |||
| 105 | |||
| 106 | $cols = $dataManager->getCols(); |
||
| 107 | if ($dataManager->getActions(true)) { |
||
| 108 | $cols = array_slice($cols, 1); |
||
| 109 | } |
||
| 110 | $endRow = true; |
||
| 111 | foreach ($cols as $colName => $options) { |
||
| 112 | if (!$endRow) { |
||
| 113 | echo ";"; |
||
| 114 | } |
||
| 115 | $endRow = false; |
||
| 116 | echo '"' . $options['label'] . '"'; |
||
| 117 | } |
||
| 118 | echo "\n"; |
||
| 119 | $endRow = true; |
||
| 120 | } |
||
| 121 | if (!$request['params']['all']) { |
||
| 122 | $pages = $dataManager->getPages($request['params'], $request['model']); |
||
| 123 | $request['params']['page'] = !empty($pages->params['page']) ? $pages->params['page'] : $dataManager->page; |
||
| 124 | $request['params']['limit'] = !empty($pages->params['limit']) ? $pages->params['limit'] : $dataManager->limit; |
||
| 125 | } |
||
| 126 | $rows = $dataManager->getRows($request['params'], $request['model']); |
||
| 127 | foreach ($rows as $row) { |
||
| 128 | if ($request['download']) { |
||
| 129 | foreach ($row as $col) { |
||
| 130 | if (!$endRow) { |
||
| 131 | echo ";"; |
||
| 132 | } |
||
| 133 | $endRow = false; |
||
| 134 | echo '"' . str_replace(["\n", '"'], ['“'], $col) . '"'; |
||
| 135 | } |
||
| 136 | echo "\n"; |
||
| 137 | $endRow = true; |
||
| 138 | } else { |
||
| 139 | Ui\Table::drawRow($row); |
||
| 140 | } |
||
| 141 | } |
||
| 142 | if ($request['download']) { |
||
| 143 | exit(); |
||
| 144 | } |
||
| 145 | |||
| 146 | $result->content['rows'] = ob_get_contents(); |
||
| 147 | $result->content['summary'] = $dataManager->getSummary($request['params'], $request['model']); |
||
| 148 | ob_clean(); |
||
| 149 | |||
| 150 | $result->content['pages'] = ''; |
||
| 151 | if (isset($pages) && $pages) { |
||
| 152 | if ($pages) { |
||
| 153 | $pages->draw(); |
||
| 154 | echo '<div style="background:#fff;">записей: <b>' . $pages->options['count'] . '</b>. страница <b>' . $pages->params['page'] . '</b> из <b>' . $pages->params['pages'] . '</b></div>'; |
||
| 155 | } |
||
| 156 | $result->content['pages'] = ob_get_contents(); |
||
| 157 | ob_end_clean(); |
||
| 158 | } |
||
| 159 | $result->send(); |
||
| 160 | } |
||
| 161 | |||
| 162 | public function loadCategorysAction() { |
||
| 163 | $result = new Server\Result(); |
||
| 164 | |||
| 165 | ob_start(); |
||
| 166 | |||
| 167 | $request = $this->parseRequest(); |
||
| 168 | |||
| 169 | $dataManager = new Ui\DataManager($request['modelName'], $request['managerName']); |
||
| 170 | $dataManager->drawCategorys(); |
||
| 171 | |||
| 172 | $result->content = ob_get_contents(); |
||
| 173 | ob_end_clean(); |
||
| 174 | |||
| 175 | $result->send(); |
||
| 176 | } |
||
| 177 | |||
| 178 | public function delRowAction() { |
||
| 179 | |||
| 180 | $request = $this->parseRequest(); |
||
| 181 | |||
| 182 | $dataManager = new Ui\DataManager($request['modelName'], $request['managerName']); |
||
| 183 | |||
| 184 | if ($dataManager->checkAccess()) { |
||
| 185 | $model = $request['modelName']::get($request['key'], $request['modelName']::index(), $request['params']); |
||
| 186 | if ($model) { |
||
| 187 | $model->delete($request['params']); |
||
| 188 | } |
||
| 189 | } |
||
| 190 | $result = new Server\Result(); |
||
| 191 | $result->successMsg = empty($request['silence']) ? 'Запись удалена' : ''; |
||
| 192 | $result->send(); |
||
| 193 | } |
||
| 194 | |||
| 195 | public function updateRowAction() { |
||
| 211 | } |
||
| 212 | |||
| 213 | public function groupActionAction() { |
||
| 241 | } |
||
| 242 | |||
| 243 | public function delCategoryAction() { |
||
| 244 | |||
| 258 | } |
||
| 259 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths