| Conditions | 38 |
| Paths | > 20000 |
| Total Lines | 150 |
| Code Lines | 95 |
| 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 |
||
| 100 | function main() |
||
| 101 | {
|
||
| 102 | Skin::$view = new CategoriesView($this); |
||
| 103 | if ($this->origin) {
|
||
| 104 | if ($this->type == Categorie::TYPE_PRODUCT) {
|
||
|
|
|||
| 105 | $idProdOrigin = $this->origin; |
||
| 106 | } |
||
| 107 | if ($this->type == Categorie::TYPE_SUPPLIER) {
|
||
| 108 | $idSupplierOrigin = $this->origin; |
||
| 109 | } |
||
| 110 | if ($this->type == Categorie::TYPE_CUSTOMER) {
|
||
| 111 | $idCompanyOrigin = $this->origin; |
||
| 112 | } |
||
| 113 | if ($this->type == Categorie::TYPE_MEMBER) {
|
||
| 114 | $idMemberOrigin = $this->origin; |
||
| 115 | } |
||
| 116 | if ($this->type == Categorie::TYPE_CONTACT) {
|
||
| 117 | $idContactOrigin = $this->origin; |
||
| 118 | } |
||
| 119 | if ($this->type == Categorie::TYPE_PROJECT) {
|
||
| 120 | $idProjectOrigin = $this->origin; |
||
| 121 | } |
||
| 122 | } |
||
| 123 | |||
| 124 | if ($this->catorigin && $this->type == Categorie::TYPE_PRODUCT) {
|
||
| 125 | $idCatOrigin = $this->catorigin; |
||
| 126 | } |
||
| 127 | |||
| 128 | $this->object = new AlCategorie(); |
||
| 129 | |||
| 130 | $extrafields = new AlExtraFields(); |
||
| 131 | $extralabels = $extrafields->fetch_name_optionals_label($this->object->table_element); |
||
| 132 | |||
| 133 | // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array array |
||
| 134 | Globals::$hookManager->initHooks(array('categorycard'));
|
||
| 135 | |||
| 136 | |||
| 137 | /* |
||
| 138 | * Actions |
||
| 139 | */ |
||
| 140 | |||
| 141 | // Add action |
||
| 142 | if ($this->action == 'add' && Globals::$user->rights->categorie->creer) {
|
||
| 143 | // Action ajout d'une categorie |
||
| 144 | if ($this->cancel) {
|
||
| 145 | if ($this->urlfrom) {
|
||
| 146 | header("Location: " . $urlfrom);
|
||
| 147 | exit; |
||
| 148 | } |
||
| 149 | if ($idProdOrigin) {
|
||
| 150 | header("Location: " . DOL_URL_ROOT . '/categories/viewcat.php?id=' . $idProdOrigin . '&type=' . $this->type);
|
||
| 151 | exit; |
||
| 152 | } |
||
| 153 | if ($idCompanyOrigin) {
|
||
| 154 | header("Location: " . DOL_URL_ROOT . '/categories/viewcat.php?id=' . $idCompanyOrigin . '&type=' . $this->type);
|
||
| 155 | exit; |
||
| 156 | } |
||
| 157 | if ($idSupplierOrigin) {
|
||
| 158 | header("Location: " . DOL_URL_ROOT . '/categories/viewcat.php?id=' . $idSupplierOrigin . '&type=' . $this->type);
|
||
| 159 | exit; |
||
| 160 | } |
||
| 161 | if ($idMemberOrigin) {
|
||
| 162 | header("Location: " . DOL_URL_ROOT . '/categories/viewcat.php?id=' . $idMemberOrigin . '&type=' . $this->type);
|
||
| 163 | exit; |
||
| 164 | } |
||
| 165 | if ($idContactOrigin) {
|
||
| 166 | header("Location: " . DOL_URL_ROOT . '/categories/viewcat.php?id=' . $idContactOrigin . '&type=' . $this->type);
|
||
| 167 | exit; |
||
| 168 | } |
||
| 169 | if ($idProjectOrigin) {
|
||
| 170 | header("Location: " . DOL_URL_ROOT . '/categories/viewcat.php?id=' . $idProjectOrigin . '&type=' . $this->type);
|
||
| 171 | exit; |
||
| 172 | } |
||
| 173 | header("Location: " . DOL_URL_ROOT . '/categories/index.php?leftmenu=cat&type=' . $this->type);
|
||
| 174 | exit; |
||
| 175 | } |
||
| 176 | |||
| 177 | $object->label = $this->label; |
||
| 178 | $object->color = $this->color; |
||
| 179 | $object->description = AlDolUtils::dol_htmlcleanlastbr($this->description); |
||
| 180 | $object->socid = ($this->socid ? $this->socid : 'null'); |
||
| 181 | $object->visible = $this->visible; |
||
| 182 | $object->type = $this->type; |
||
| 183 | |||
| 184 | if ($parent != "-1") {
|
||
| 185 | $object->fk_parent = $parent; |
||
| 186 | } |
||
| 187 | |||
| 188 | $ret = $extrafields->setOptionalsFromPost($extralabels, $object); |
||
| 189 | if ($ret < 0) {
|
||
| 190 | $error++; |
||
| 191 | } |
||
| 192 | |||
| 193 | if (!$object->label) {
|
||
| 194 | $error++; |
||
| 195 | setEventMessages(Globals::$langs->trans("ErrorFieldRequired", Globals::$langs->transnoentities("Ref")), null, 'errors');
|
||
| 196 | $this->action = 'create'; |
||
| 197 | } |
||
| 198 | |||
| 199 | // Create category in database |
||
| 200 | if (!$error) {
|
||
| 201 | $result = $object->create($user); |
||
| 202 | if ($result > 0) {
|
||
| 203 | $this->action = 'confirmed'; |
||
| 204 | $_POST["addcat"] = ''; |
||
| 205 | } else {
|
||
| 206 | setEventMessages($object->error, $object->errors, 'errors'); |
||
| 207 | } |
||
| 208 | } |
||
| 209 | } |
||
| 210 | |||
| 211 | // Confirm action |
||
| 212 | if (($this->action == 'add' || $this->action == 'confirmed') && Globals::$user->rights->categorie->creer) {
|
||
| 213 | // Action confirmation de creation categorie |
||
| 214 | if ($this->action == 'confirmed') {
|
||
| 215 | if ($urlfrom) {
|
||
| 216 | header("Location: " . $urlfrom);
|
||
| 217 | exit; |
||
| 218 | } |
||
| 219 | if ($backtopage) {
|
||
| 220 | header("Location: " . $backtopage);
|
||
| 221 | exit; |
||
| 222 | } |
||
| 223 | if ($idProdOrigin) {
|
||
| 224 | header("Location: " . DOL_URL_ROOT . '/categories/viewcat.php?id=' . $idProdOrigin . '&type=' . $this->type . '&mesg=' . urlencode(Globals::$langs->trans("CatCreated")));
|
||
| 225 | exit; |
||
| 226 | } |
||
| 227 | if ($idCompanyOrigin) {
|
||
| 228 | header("Location: " . DOL_URL_ROOT . '/categories/viewcat.php?id=' . $idCompanyOrigin . '&type=' . $this->type . '&mesg=' . urlencode(Globals::$langs->trans("CatCreated")));
|
||
| 229 | exit; |
||
| 230 | } |
||
| 231 | if ($idSupplierOrigin) {
|
||
| 232 | header("Location: " . DOL_URL_ROOT . '/categories/viewcat.php?id=' . $idSupplierOrigin . '&type=' . $this->type . '&mesg=' . urlencode(Globals::$langs->trans("CatCreated")));
|
||
| 233 | exit; |
||
| 234 | } |
||
| 235 | if ($idMemberOrigin) {
|
||
| 236 | header("Location: " . DOL_URL_ROOT . '/categories/viewcat.php?id=' . $idMemberOrigin . '&type=' . $this->type . '&mesg=' . urlencode(Globals::$langs->trans("CatCreated")));
|
||
| 237 | exit; |
||
| 238 | } |
||
| 239 | if ($idContactOrigin) {
|
||
| 240 | header("Location: " . DOL_URL_ROOT . '/categories/viewcat.php?id=' . $idContactOrigin . '&type=' . $this->type . '&mesg=' . urlencode(Globals::$langs->trans("CatCreated")));
|
||
| 241 | exit; |
||
| 242 | } |
||
| 243 | if ($idProjectOrigin) {
|
||
| 244 | header("Location: " . DOL_URL_ROOT . '/categories/viewcat.php?id=' . $idProjectOrigin . '&type=' . $this->type . '&mesg=' . urlencode(Globals::$langs->trans("CatCreated")));
|
||
| 245 | exit; |
||
| 246 | } |
||
| 247 | |||
| 248 | header("Location: " . DOL_URL_ROOT . '/categories/viewcat.php?id=' . $result . '&type=' . $this->type);
|
||
| 249 | exit; |
||
| 250 | } |
||
| 254 |