| Conditions | 22 |
| Paths | 12800 |
| Total Lines | 104 |
| Code Lines | 79 |
| Lines | 10 |
| Ratio | 9.62 % |
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 |
||
| 53 | function loadRowsAction() |
||
|
1 ignored issue
–
show
|
|||
| 54 | { |
||
| 55 | $result = new Server\Result(); |
||
| 56 | $result->content = []; |
||
| 57 | ob_start(); |
||
| 58 | $params = []; |
||
| 59 | if (!empty($_GET['params'])) { |
||
| 60 | $params = $_GET['params']; |
||
| 61 | } |
||
| 62 | View Code Duplication | if (strpos($_GET['modelName'], ':')) { |
|
| 63 | $raw = explode(':', $_GET['modelName']); |
||
| 64 | $modelName = $raw[0]; |
||
| 65 | $id = $raw[1]; |
||
| 66 | $model = $modelName::get($id, $modelName::index(), $params); |
||
| 67 | } else { |
||
| 68 | $modelName = $_GET['modelName']; |
||
| 69 | $id = null; |
||
| 70 | $model = null; |
||
| 71 | } |
||
| 72 | if (!empty($_GET['params']['relation'])) { |
||
| 73 | $params['relation'] = $_GET['params']['relation']; |
||
| 74 | $relations = $modelName::relations(); |
||
| 75 | $type = !empty($relations[$_GET['params']['relation']]['type']) ? $relations[$_GET['params']['relation']]['type'] : 'to'; |
||
| 76 | |||
| 77 | switch ($type) { |
||
| 78 | case 'relModel': |
||
| 79 | $modelName = $relations[$_GET['params']['relation']]['relModel']; |
||
| 80 | break; |
||
| 81 | default: |
||
| 82 | $modelName = $relations[$_GET['params']['relation']]['model']; |
||
| 83 | } |
||
| 84 | } |
||
| 85 | if (!empty($_GET['filters'])) { |
||
| 86 | $params['filters'] = $_GET['filters']; |
||
| 87 | } |
||
| 88 | |||
| 89 | if (!empty($_GET['sortered'])) { |
||
| 90 | $params['sortered'] = $_GET['sortered']; |
||
| 91 | } |
||
| 92 | if (!empty($_GET['mode'])) { |
||
| 93 | $params['mode'] = $_GET['mode']; |
||
| 94 | } |
||
| 95 | if (!empty($_GET['all'])) { |
||
| 96 | $params['all'] = true; |
||
| 97 | } |
||
| 98 | $dataManager = new Ui\DataManager($modelName, $_GET['managerName']); |
||
| 99 | if (!empty($_GET['download'])) { |
||
| 100 | $params['all'] = true; |
||
| 101 | $params['download'] = true; |
||
| 102 | set_time_limit(0); |
||
| 103 | ob_end_clean(); |
||
| 104 | header('Content-Encoding: UTF-8'); |
||
| 105 | header("Content-Type: text/csv"); |
||
| 106 | header("Content-Disposition: attachment; filename=" . $modelName::$objectName . '.csv'); |
||
| 107 | echo "\xEF\xBB\xBF"; // UTF-8 BOM |
||
| 108 | |||
| 109 | |||
| 110 | $cols = $dataManager->getCols(); |
||
| 111 | $cols = array_slice($cols, (!empty($dataManager->managerOptions['groupActions']) ? 1 : 0)); |
||
| 112 | $endRow = true; |
||
| 113 | foreach ($cols as $colName => $options) { |
||
| 114 | if (!$endRow) { |
||
| 115 | echo ";"; |
||
| 116 | } |
||
| 117 | $endRow = false; |
||
| 118 | echo '"' . $options['label'] . '"'; |
||
| 119 | } |
||
| 120 | echo "\n"; |
||
| 121 | $endRow = true; |
||
| 122 | } |
||
| 123 | $rows = $dataManager->getRows($params, $model); |
||
| 124 | foreach ($rows as $row) { |
||
| 125 | if (!empty($_GET['download'])) { |
||
| 126 | $row = array_slice($row, (!empty($dataManager->managerOptions['groupActions']) ? 1 : 0), -1); |
||
| 127 | foreach ($row as $col) { |
||
| 128 | if (!$endRow) { |
||
|
1 ignored issue
–
show
|
|||
| 129 | echo ";"; |
||
| 130 | } |
||
| 131 | $endRow = false; |
||
| 132 | echo '"' . str_replace("\n", '', $col) . '"'; |
||
| 133 | } |
||
| 134 | echo "\n"; |
||
| 135 | $endRow = true; |
||
| 136 | } else { |
||
| 137 | Ui\Table::drawRow($row); |
||
| 138 | } |
||
| 139 | } |
||
| 140 | if (!empty($_GET['download'])) { |
||
| 141 | exit(); |
||
|
1 ignored issue
–
show
|
|||
| 142 | } |
||
| 143 | $result->content['rows'] = ob_get_contents(); |
||
| 144 | ob_clean(); |
||
| 145 | $result->content['pages'] = ''; |
||
| 146 | if (empty($params['all'])) { |
||
| 147 | $pages = $dataManager->getPages($params, $model); |
||
| 148 | |||
| 149 | if ($pages) { |
||
| 150 | $pages->draw(); |
||
| 151 | } |
||
| 152 | $result->content['pages'] = ob_get_contents(); |
||
| 153 | ob_end_clean(); |
||
| 154 | } |
||
| 155 | $result->send(); |
||
| 156 | } |
||
| 157 | |||
| 368 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.