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