| Conditions | 32 |
| Paths | > 20000 |
| Total Lines | 137 |
| Code Lines | 87 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 67 | public function getCheckPreBuilding($module) |
||
| 68 | { |
||
| 69 | $cf = Modulebuilder\Files\CreateFile::getInstance(); |
||
| 70 | |||
| 71 | $modId = $module->getVar('mod_id'); |
||
| 72 | $tables = $cf->getTableTables($modId); |
||
| 73 | $errors = []; |
||
| 74 | |||
| 75 | foreach (array_keys($tables) as $t) { |
||
| 76 | if (1 == $tables[$t]->getVar('table_broken')) { |
||
| 77 | $tableId = $tables[$t]->getVar('table_id'); |
||
| 78 | $tableName = $tables[$t]->getVar('table_name'); |
||
| 79 | $fields = $cf->getTableFields($modId, $tableId); |
||
| 80 | $fieldSatus = ''; |
||
| 81 | |||
| 82 | foreach (array_keys($fields) as $f) { |
||
| 83 | $fieldName = $fields[$f]->getVar('field_name'); |
||
| 84 | if (16 == $fields[$f]->getVar('field_element')) { |
||
| 85 | $fieldSatus = $fieldName; |
||
| 86 | } |
||
| 87 | } |
||
| 88 | // check whether each table with handling "broken" has also a field "status" |
||
| 89 | if ('' == $fieldSatus) { |
||
| 90 | $error = str_replace('%t', $tableName, _AM_MODULEBUILDER_CHECKPREBUILD_BROKEN1); |
||
| 91 | $errors[] = ['tableName' => $tableName, 'icon' => 'error', 'info' => $error]; |
||
| 92 | } |
||
| 93 | } |
||
| 94 | } |
||
| 95 | foreach (array_keys($tables) as $t) { |
||
| 96 | $tableId = $tables[$t]->getVar('table_id'); |
||
| 97 | $tableName = $tables[$t]->getVar('table_name'); |
||
| 98 | $fields = $cf->getTableFields($modId, $tableId); |
||
| 99 | |||
| 100 | foreach (array_keys($fields) as $f) { |
||
| 101 | $fieldName = $fields[$f]->getVar('field_name'); |
||
| 102 | // check fields for parameters |
||
| 103 | if ($f > 0) { |
||
| 104 | $fieldParams = (int)$fields[$f]->getVar('field_parent') + (int)$fields[$f]->getVar('field_admin') + (int)$fields[$f]->getVar('field_inlist') + (int)$fields[$f]->getVar('field_inform') |
||
| 105 | + (int)$fields[$f]->getVar('field_user') + (int)$fields[$f]->getVar('field_ihead') + (int)$fields[$f]->getVar('field_ibody') + (int)$fields[$f]->getVar('field_ifoot') |
||
| 106 | + (int)$fields[$f]->getVar('field_thead') + (int)$fields[$f]->getVar('field_tbody') + (int)$fields[$f]->getVar('field_tfoot') + (int)$fields[$f]->getVar('field_block') |
||
| 107 | + (int)$fields[$f]->getVar('field_main') + (int)$fields[$f]->getVar('field_search') + (int)$fields[$f]->getVar('field_required'); |
||
| 108 | if (0 == $fieldParams) { |
||
| 109 | $error = str_replace(['%f', '%t'], [$fieldName, $tableName], _AM_MODULEBUILDER_CHECKPREBUILD_FIELDS1); |
||
| 110 | $errors[] = ['tableName' => $tableName, 'icon' => 'error', 'info' => $error]; |
||
| 111 | } |
||
| 112 | } |
||
| 113 | } |
||
| 114 | } |
||
| 115 | |||
| 116 | //check user file no usage in index or item |
||
| 117 | foreach (array_keys($tables) as $t) { |
||
| 118 | $tableId = $tables[$t]->getVar('table_id'); |
||
| 119 | $tableName = $tables[$t]->getVar('table_name'); |
||
| 120 | $fields = $cf->getTableFields($modId, $tableId); |
||
| 121 | |||
| 122 | foreach (array_keys($fields) as $f) { |
||
| 123 | $fieldName = $fields[$f]->getVar('field_name'); |
||
| 124 | if (1 == $fields[$f]->getVar('field_user')) { |
||
| 125 | // check fields for parameters |
||
| 126 | if ($f > 0) { |
||
| 127 | $fieldParams = (int)$fields[$f]->getVar('field_ihead') + (int)$fields[$f]->getVar('field_ibody') + (int)$fields[$f]->getVar('field_ifoot') |
||
| 128 | + (int)$fields[$f]->getVar('field_thead') + (int)$fields[$f]->getVar('field_tbody') + (int)$fields[$f]->getVar('field_tfoot'); |
||
| 129 | if (0 == $fieldParams) { |
||
| 130 | $error = str_replace(['%f', '%t'], [$fieldName, $tableName], _AM_MODULEBUILDER_CHECKPREBUILD_FIELDS2); |
||
| 131 | $errors[] = ['tableName' => $tableName, 'icon' => 'warning', 'info' => $error]; |
||
| 132 | } |
||
| 133 | } |
||
| 134 | } |
||
| 135 | } |
||
| 136 | } |
||
| 137 | //check user file index multiple usage |
||
| 138 | //check user file item multiple usage |
||
| 139 | foreach (array_keys($tables) as $t) { |
||
| 140 | $tableId = $tables[$t]->getVar('table_id'); |
||
| 141 | $tableName = $tables[$t]->getVar('table_name'); |
||
| 142 | $fields = $cf->getTableFields($modId, $tableId); |
||
| 143 | |||
| 144 | foreach (array_keys($fields) as $f) { |
||
| 145 | $fieldName = $fields[$f]->getVar('field_name'); |
||
| 146 | if (1 == $fields[$f]->getVar('field_user')) { |
||
| 147 | // check fields for parameters |
||
| 148 | if ($f > 0) { |
||
| 149 | $fieldParams = (int)$fields[$f]->getVar('field_ihead') + (int)$fields[$f]->getVar('field_ibody') + (int)$fields[$f]->getVar('field_ifoot'); |
||
| 150 | if ($fieldParams > 1) { |
||
| 151 | $error = str_replace(['%f', '%t'], [$fieldName, $tableName], _AM_MODULEBUILDER_CHECKPREBUILD_FIELDS3); |
||
| 152 | $errors[] = ['tableName' => $tableName, 'icon' => 'warning', 'info' => $error]; |
||
| 153 | } |
||
| 154 | $fieldParams = (int)$fields[$f]->getVar('field_thead') + (int)$fields[$f]->getVar('field_tbody') + (int)$fields[$f]->getVar('field_tfoot'); |
||
| 155 | if ($fieldParams > 1) { |
||
| 156 | $error = str_replace(['%f', '%t'], [$fieldName, $tableName], _AM_MODULEBUILDER_CHECKPREBUILD_FIELDS3); |
||
| 157 | $errors[] = ['tableName' => $tableName, 'icon' => 'warning', 'info' => $error]; |
||
| 158 | } |
||
| 159 | } |
||
| 160 | } |
||
| 161 | } |
||
| 162 | } |
||
| 163 | |||
| 164 | //use in block but not field selected |
||
| 165 | foreach (array_keys($tables) as $t) { |
||
| 166 | $tableId = $tables[$t]->getVar('table_id'); |
||
| 167 | $tableName = $tables[$t]->getVar('table_name'); |
||
| 168 | $fields = $cf->getTableFields($modId, $tableId); |
||
| 169 | $count = 0; |
||
| 170 | if (1 == $tables[$t]->getVar('table_blocks')) { |
||
| 171 | foreach (array_keys($fields) as $f) { |
||
| 172 | $fieldName = $fields[$f]->getVar('field_name'); |
||
| 173 | if (1 == $fields[$f]->getVar('field_block')) { |
||
| 174 | $count++; |
||
| 175 | } |
||
| 176 | } |
||
| 177 | if (0 == $count) { |
||
| 178 | $error = str_replace(['%f', '%t'], [$fieldName, $tableName], _AM_MODULEBUILDER_CHECKPREBUILD_BLOCK1); |
||
|
|
|||
| 179 | $errors[] = ['tableName' => $tableName, 'icon' => 'warning', 'info' => $error]; |
||
| 180 | } |
||
| 181 | } |
||
| 182 | } |
||
| 183 | //use in block but not field date |
||
| 184 | foreach (array_keys($tables) as $t) { |
||
| 185 | $tableId = $tables[$t]->getVar('table_id'); |
||
| 186 | $tableName = $tables[$t]->getVar('table_name'); |
||
| 187 | $fields = $cf->getTableFields($modId, $tableId); |
||
| 188 | $count = 0; |
||
| 189 | if (1 == $tables[$t]->getVar('table_blocks')) { |
||
| 190 | foreach (array_keys($fields) as $f) { |
||
| 191 | $fieldName = $fields[$f]->getVar('field_name'); |
||
| 192 | if (15 == $fields[$f]->getVar('field_element') || 21 == $fields[$f]->getVar('field_element')) { |
||
| 193 | $count++; |
||
| 194 | } |
||
| 195 | } |
||
| 196 | if (0 == $count) { |
||
| 197 | $error = str_replace(['%f', '%t'], [$fieldName, $tableName], _AM_MODULEBUILDER_CHECKPREBUILD_BLOCK2); |
||
| 198 | $errors[] = ['tableName' => $tableName, 'icon' => 'warning', 'info' => $error]; |
||
| 199 | } |
||
| 200 | } |
||
| 201 | } |
||
| 202 | |||
| 203 | return $errors; |
||
| 204 | } |
||
| 206 |