| Total Complexity | 43 |
| Total Lines | 191 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like ModeleThirdPartyCode often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ModeleThirdPartyCode, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 68 | abstract class ModeleThirdPartyCode |
||
| 69 | { |
||
| 70 | /** |
||
| 71 | * @var string Error code (or message) |
||
| 72 | */ |
||
| 73 | public $error=''; |
||
| 74 | |||
| 75 | /** Renvoi la description par defaut du modele de numerotation |
||
| 76 | * |
||
| 77 | * @param Translate $langs Object langs |
||
| 78 | * @return string Texte descripif |
||
| 79 | */ |
||
| 80 | public function info($langs) |
||
| 81 | { |
||
| 82 | $langs->load("bills"); |
||
| 83 | return $langs->trans("NoDescription"); |
||
| 84 | } |
||
| 85 | |||
| 86 | /** Renvoi nom module |
||
| 87 | * |
||
| 88 | * @param Translate $langs Object langs |
||
| 89 | * @return string Nom du module |
||
| 90 | */ |
||
| 91 | public function getNom($langs) |
||
| 92 | { |
||
| 93 | return $this->nom; |
||
| 94 | } |
||
| 95 | |||
| 96 | |||
| 97 | /** Renvoi un exemple de numerotation |
||
| 98 | * |
||
| 99 | * @param Translate $langs Object langs |
||
| 100 | * @return string Example |
||
| 101 | */ |
||
| 102 | public function getExample($langs) |
||
| 103 | { |
||
| 104 | $langs->load("bills"); |
||
| 105 | return $langs->trans("NoExample"); |
||
| 106 | } |
||
| 107 | |||
| 108 | /** Test si les numeros deja en vigueur dans la base ne provoquent pas de |
||
| 109 | * de conflits qui empechera cette numerotation de fonctionner. |
||
| 110 | * |
||
| 111 | * @return boolean false si conflit, true si ok |
||
| 112 | */ |
||
| 113 | public function canBeActivated() |
||
| 114 | { |
||
| 115 | return true; |
||
| 116 | } |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Return next value available |
||
| 120 | * |
||
| 121 | * @param Societe $objsoc Object thirdparty |
||
| 122 | * @param int $type Type |
||
| 123 | * @return string Value |
||
| 124 | */ |
||
| 125 | public function getNextValue($objsoc = 0, $type = -1) |
||
| 126 | { |
||
| 127 | global $langs; |
||
| 128 | return $langs->trans("Function_getNextValue_InModuleNotWorking"); |
||
| 129 | } |
||
| 130 | |||
| 131 | |||
| 132 | /** |
||
| 133 | * Return version of module |
||
| 134 | * |
||
| 135 | * @return string Version |
||
| 136 | */ |
||
| 137 | public function getVersion() |
||
| 138 | { |
||
| 139 | global $langs; |
||
| 140 | $langs->load("admin"); |
||
| 141 | |||
| 142 | if ($this->version == 'development') return $langs->trans("VersionDevelopment"); |
||
| 143 | if ($this->version == 'experimental') return $langs->trans("VersionExperimental"); |
||
| 144 | if ($this->version == 'dolibarr') return DOL_VERSION; |
||
| 145 | if ($this->version) return $this->version; |
||
| 146 | return $langs->trans("NotAvailable"); |
||
| 147 | } |
||
| 148 | |||
| 149 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 150 | /** |
||
| 151 | * Renvoie la liste des modeles de numérotation |
||
| 152 | * |
||
| 153 | * @param DoliDB $db Database handler |
||
| 154 | * @param integer $maxfilenamelength Max length of value to show |
||
| 155 | * @return array List of numbers |
||
| 156 | */ |
||
| 157 | public static function liste_modeles($db, $maxfilenamelength = 0) |
||
| 158 | { |
||
| 159 | // phpcs:enable |
||
| 160 | $liste=array(); |
||
| 161 | $sql =""; |
||
| 162 | |||
| 163 | $resql = $db->query($sql); |
||
| 164 | if ($resql) |
||
| 165 | { |
||
| 166 | $num = $db->num_rows($resql); |
||
| 167 | $i = 0; |
||
| 168 | while ($i < $num) |
||
| 169 | { |
||
| 170 | $row = $db->fetch_row($resql); |
||
| 171 | $liste[$row[0]]=$row[1]; |
||
| 172 | $i++; |
||
| 173 | } |
||
| 174 | } |
||
| 175 | else |
||
| 176 | { |
||
| 177 | return -1; |
||
| 178 | } |
||
| 179 | return $liste; |
||
| 180 | } |
||
| 181 | |||
| 182 | /** |
||
| 183 | * Return description of module parameters |
||
| 184 | * |
||
| 185 | * @param Translate $langs Output language |
||
| 186 | * @param Societe $soc Third party object |
||
| 187 | * @param int $type -1=Nothing, 0=Customer, 1=Supplier |
||
| 188 | * @return string HTML translated description |
||
| 189 | */ |
||
| 190 | public function getToolTip($langs, $soc, $type) |
||
| 191 | { |
||
| 192 | global $conf; |
||
| 193 | |||
| 194 | $langs->load("admin"); |
||
| 195 | |||
| 196 | $s=''; |
||
| 197 | if ($type == -1) $s.=$langs->trans("Name").': <b>'.$this->getNom($langs).'</b><br>'; |
||
| 198 | if ($type == -1) $s.=$langs->trans("Version").': <b>'.$this->getVersion().'</b><br>'; |
||
| 199 | if ($type == 0) $s.=$langs->trans("CustomerCodeDesc").'<br>'; |
||
| 200 | if ($type == 1) $s.=$langs->trans("SupplierCodeDesc").'<br>'; |
||
| 201 | if ($type != -1) $s.=$langs->trans("ValidityControledByModule").': <b>'.$this->getNom($langs).'</b><br>'; |
||
| 202 | $s.='<br>'; |
||
| 203 | $s.='<u>'.$langs->trans("ThisIsModuleRules").':</u><br>'; |
||
| 204 | if ($type == 0) |
||
| 205 | { |
||
| 206 | $s.=$langs->trans("RequiredIfCustomer").': '; |
||
| 207 | if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='<strike>'; |
||
| 208 | $s.=yn(!$this->code_null, 1, 2); |
||
| 209 | if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')'; |
||
| 210 | $s.='<br>'; |
||
| 211 | } |
||
| 212 | if ($type == 1) |
||
| 213 | { |
||
| 214 | $s.=$langs->trans("RequiredIfSupplier").': '; |
||
| 215 | if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='<strike>'; |
||
| 216 | $s.=yn(!$this->code_null, 1, 2); |
||
| 217 | if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')'; |
||
| 218 | $s.='<br>'; |
||
| 219 | } |
||
| 220 | if ($type == -1) |
||
| 221 | { |
||
| 222 | $s.=$langs->trans("Required").': '; |
||
| 223 | if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='<strike>'; |
||
| 224 | $s.=yn(!$this->code_null, 1, 2); |
||
| 225 | if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')'; |
||
| 226 | $s.='<br>'; |
||
| 227 | } |
||
| 228 | $s.=$langs->trans("CanBeModifiedIfOk").': '; |
||
| 229 | $s.=yn($this->code_modifiable, 1, 2); |
||
| 230 | $s.='<br>'; |
||
| 231 | $s.=$langs->trans("CanBeModifiedIfKo").': '.yn($this->code_modifiable_invalide, 1, 2).'<br>'; |
||
| 232 | $s.=$langs->trans("AutomaticCode").': '.yn($this->code_auto, 1, 2).'<br>'; |
||
| 233 | $s.='<br>'; |
||
| 234 | if ($type == 0 || $type == -1) |
||
| 235 | { |
||
| 236 | $nextval=$this->getNextValue($soc, 0); |
||
| 237 | if (empty($nextval)) $nextval=$langs->trans("Undefined"); |
||
| 238 | $s.=$langs->trans("NextValue").($type == -1?' ('.$langs->trans("Customer").')':'').': <b>'.$nextval.'</b><br>'; |
||
| 239 | } |
||
| 240 | if ($type == 1 || $type == -1) |
||
| 241 | { |
||
| 242 | $nextval=$this->getNextValue($soc, 1); |
||
| 243 | if (empty($nextval)) $nextval=$langs->trans("Undefined"); |
||
| 244 | $s.=$langs->trans("NextValue").($type == -1?' ('.$langs->trans("Supplier").')':'').': <b>'.$nextval.'</b>'; |
||
| 245 | } |
||
| 246 | return $s; |
||
| 247 | } |
||
| 248 | |||
| 249 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
||
| 250 | /** |
||
| 251 | * Check if mask/numbering use prefix |
||
| 252 | * |
||
| 253 | * @return int 0=no, 1=yes |
||
| 254 | */ |
||
| 255 | public function verif_prefixIsUsed() |
||
| 259 | } |
||
| 260 | } |
||
| 261 | |||
| 262 | |||
| 263 | /** |
||
| 264 | * \class ModeleAccountancyCode |
||
| 265 | * \brief Parent class for third parties accountancy code generators |
||
| 266 | */ |
||
| 267 | abstract class ModeleAccountancyCode |
||
| 405 |