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