| Total Complexity | 50 |
| Total Lines | 215 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like PurchasesLineHTMLMod 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 PurchasesLineHTMLMod, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 28 | class PurchasesLineHTMLMod implements PurchasesLineModInterface |
||
| 29 | { |
||
| 30 | |||
| 31 | public function apply(PurchaseDocument &$model, array &$lines, array $formData): void |
||
| 33 | // TODO: Implement apply() method. |
||
| 34 | } |
||
| 35 | |||
| 36 | public function applyToLine(array $formData, BusinessDocumentLine &$line, string $id): void |
||
| 37 | { |
||
| 38 | // TODO: Implement applyToLine() method. |
||
| 39 | $line->rdtaxcodisc = $formData['rdtaxcodisc_' . $id] ?? $line->rdtaxcodisc; |
||
| 40 | $line->rdtaxcodcdt = $formData['rdtaxcodcdt_' . $id] ?? $line->rdtaxcodcdt; |
||
| 41 | $line->rdtaxcodlegaltip = $formData['rdtaxcodlegaltip_' . $id] ?? $line->rdtaxcodlegaltip; |
||
| 42 | $line->rdtaxcodfirstplate = $formData['rdtaxcodfirstplate_' . $id] ?? $line->rdtaxcodfirstplate; |
||
| 43 | $line->totalplustaxes = $formData['totalplustaxes_' . $id] ?? $line->totalplustaxes; |
||
| 44 | } |
||
| 45 | |||
| 46 | public function assets(): void |
||
| 47 | { |
||
| 48 | // TODO: Implement assets() method. |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @param Translator $i18n |
||
| 53 | * @param string $attributes |
||
| 54 | * @param string $label |
||
| 55 | * @param int $idlinea |
||
| 56 | * @param array $options |
||
| 57 | * @return string |
||
| 58 | */ |
||
| 59 | private function getStr(Translator $i18n, string $attributes, string $label, $idlinea, array $options): string |
||
| 60 | { |
||
| 61 | $idlinea = (!$idlinea) ? 0 : $idlinea; |
||
| 62 | return '<div class="col-6">' |
||
| 63 | . '<div class="mb-2">' |
||
| 64 | . $i18n->trans($label) |
||
| 65 | . '<select onchange="return purchasesFormAction(\'recalculate-line\', \'' . $idlinea . '\');"' |
||
| 66 | . $attributes . ' class="form-select" >' . implode('', $options) . '</select>' |
||
| 67 | . '</div>' |
||
| 68 | . '</div>'; |
||
| 69 | } |
||
| 70 | |||
| 71 | public function getFastLine(PurchaseDocument $model, array $formData): ?BusinessDocumentLine |
||
| 72 | { |
||
| 73 | return null; |
||
| 74 | } |
||
| 75 | |||
| 76 | private function getLineAddedTaxes(BusinessDocumentLine $line): float |
||
| 77 | { |
||
| 78 | $rdtaxisc = isset($line->rdtaxisc) ? (float)$line->rdtaxisc : 0.0; |
||
| 79 | $rdtaxcdt = isset($line->rdtaxcdt) ? (float)$line->rdtaxcdt : 0.0; |
||
| 80 | $rdtaxlegaltip = isset($line->rdtaxlegaltip) ? (float)$line->rdtaxlegaltip : 0.0; |
||
| 81 | $rdtaxfirstplate = isset($line->rdtaxfirstplate) ? (float)$line->rdtaxfirstplate : 0.0; |
||
| 82 | $pvpsindto = isset($line->pvpsindto) ? (float)$line->pvpsindto : 0.0; |
||
| 83 | |||
| 84 | return $pvpsindto * ($rdtaxisc + $rdtaxcdt + $rdtaxlegaltip + $rdtaxfirstplate) / 100.0; |
||
| 85 | } |
||
| 86 | |||
| 87 | public function map(array $lines, PurchaseDocument $model): array |
||
| 88 | { |
||
| 89 | $map = []; |
||
| 90 | $num = 0; |
||
| 91 | foreach ($lines as $line) { |
||
| 92 | $num++; |
||
| 93 | $idlinea = $line->idlinea ?? 'n' . $num; |
||
| 94 | $map['rdtaxcodisc_' . $idlinea] = $line->rdtaxcodisc; |
||
| 95 | $map['rdtaxcodcdt_' . $idlinea] = $line->rdtaxcodcdt; |
||
| 96 | $map['rdtaxcodlegaltip_' . $idlinea] = $line->rdtaxcodlegaltip; |
||
| 97 | $map['rdtaxcodfirstplate_' . $idlinea] = $line->rdtaxcodfirstplate; |
||
| 98 | // El total de la línea es el totalplustaxes (pvptotal + IVA) |
||
| 99 | $map['totalplustaxes_' . $idlinea] = $line->totalplustaxes; |
||
| 100 | } |
||
| 101 | return $map; |
||
| 102 | } |
||
| 103 | |||
| 104 | public function newFields(): array |
||
| 105 | { |
||
| 106 | return ['totalplustaxes']; |
||
| 107 | } |
||
| 108 | |||
| 109 | public function newModalFields(): array |
||
| 110 | { |
||
| 111 | return ['rdtaxcodisc','rdtaxcodcdt','rdtaxcodlegaltip','rdtaxcodfirstplate']; |
||
| 112 | } |
||
| 113 | |||
| 114 | public function newTitles(): array |
||
| 115 | { |
||
| 116 | return ['totalplustaxes']; |
||
| 117 | } |
||
| 118 | |||
| 119 | public function renderField(string $idlinea, BusinessDocumentLine $line, PurchaseDocument $model, string $field): ?string |
||
| 120 | { |
||
| 121 | $i18n = new Translator(); |
||
| 122 | switch ($field) { |
||
| 123 | case "rdtaxcodisc": |
||
| 124 | return $this->loadCodeISC($idlinea, $line, $model->editable); |
||
| 125 | case "rdtaxcodcdt": |
||
| 126 | return $this->loadCodeCDT($idlinea, $line, $model->editable); |
||
| 127 | case "rdtaxcodlegaltip": |
||
| 128 | return $this->loadCodeLegalTip($idlinea, $line, $model->editable); |
||
| 129 | case "rdtaxcodfirstplate": |
||
| 130 | return $this->loadCodeFirstPlate($idlinea, $line, $model->editable); |
||
| 131 | case "totalplustaxes": |
||
| 132 | return $this->renderTotalField($idlinea, $line, $model, $model->editable); |
||
| 133 | default: |
||
| 134 | return null; |
||
| 135 | } |
||
| 136 | } |
||
| 137 | |||
| 138 | private function renderTotalField(string $idlinea, BusinessDocumentLine $line, PurchaseDocument $model): string |
||
| 139 | { |
||
| 140 | $nf0 = Tools::settings('default', 'decimals', 2); |
||
| 141 | |||
| 142 | return '<div class="col col-lg-1 order-8 columnTotalPlusTaxes" lang="es-DO">' |
||
| 143 | . '<div class="d-lg-none mt-2 small">' . Tools::trans('desc-total-plustaxes') . '</div>' |
||
| 144 | . '<input type="number" name="totalplustaxes_' . $idlinea . '" value="' . number_format($line->totalplustaxes, $nf0, '.', '') |
||
| 145 | . '" class="form-control form-control-sm text-lg-end border-0" readonly/></div>'; |
||
| 146 | } |
||
| 147 | |||
| 148 | public function loadCodeISC(string $idlinea, BusinessDocumentLine $line, $editable): string |
||
| 168 | } |
||
| 169 | public function loadCodeCDT(string $idlinea, BusinessDocumentLine $line, $editable): string |
||
| 190 | } |
||
| 191 | public function loadCodeLegalTip(string $idlinea, BusinessDocumentLine $line, $editable): string |
||
| 192 | { |
||
| 193 | $i18n = new Translator(); |
||
| 194 | $impuestosAdicionales = new ImpuestoAdicional(); |
||
| 195 | $where = [new DataBaseWhere('tipo_impuesto_short', 'Propina Legal')]; |
||
| 196 | $legalTipList = $impuestosAdicionales::all($where, ['codigo'=>'DESC']); |
||
| 197 | if (!$legalTipList) { |
||
| 198 | return ''; |
||
| 199 | } |
||
| 200 | |||
| 201 | $invoiceLineLegalTip = ($line->rdtaxcodlegaltip) ? $line->rdtaxcodlegaltip : ""; |
||
| 202 | |||
| 203 | $options = ['<option value="">----------</option>']; |
||
| 204 | foreach ($legalTipList as $row) { |
||
| 205 | $options[] = ($row->codigo === $invoiceLineLegalTip) ? |
||
| 206 | '<option value="' . $row->codigo . '" selected="">' . $row->tipo_impuesto_short . ' - ' . $row->descripcion . '</option>' : |
||
| 207 | '<option value="' . $row->codigo . '">' . $row->tipo_impuesto_short . ' - ' . $row->descripcion . '</option>'; |
||
| 208 | } |
||
| 209 | |||
| 210 | $attributes = ($editable) ? 'name="rdtaxcodlegaltip_' . $idlinea . '"' : 'name="rdtaxcodlegaltip_' . $idlinea . '" disabled=""'; |
||
| 211 | return $this->getStr($i18n, $attributes, "label-desc-rdtaxcodlegaltip", $idlinea, $options); |
||
| 212 | } |
||
| 213 | public function loadCodeFirstPlate(string $idlinea, BusinessDocumentLine $line, $editable): string |
||
| 234 | } |
||
| 235 | |||
| 236 | public function renderTitle(PurchaseDocument $model, string $field): ?string |
||
| 237 | { |
||
| 238 | switch ($field) { |
||
| 239 | case "totalplustaxes": |
||
| 240 | return '<div class="col-lg-1 text-end order-8 columTotalPlusTaxes">' .Tools::trans('desc-total-plustaxes') . '</div>'; |
||
| 241 | default: |
||
| 243 | } |
||
| 244 | } |
||
| 245 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths