| Total Complexity | 50 |
| Total Lines | 220 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like SalesLineHTMLMod 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 SalesLineHTMLMod, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 28 | class SalesLineHTMLMod implements SalesLineModInterface |
||
| 29 | { |
||
| 30 | |||
| 31 | public function apply(SalesDocument &$model, array &$lines, array $formData): void |
||
| 32 | { |
||
| 33 | // TODO: Implement apply() method. |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @param array $formData |
||
| 38 | * @param SalesDocumentLine $line |
||
| 39 | * @param string $id |
||
| 40 | * @return void |
||
| 41 | */ |
||
| 42 | public function applyToLine(array $formData, SalesDocumentLine &$line, string $id): void |
||
| 43 | { |
||
| 44 | $line->rdtaxcodisc = $formData['rdtaxcodisc_' . $id] ?? $line->rdtaxcodisc; |
||
| 45 | $line->rdtaxcodcdt = $formData['rdtaxcodcdt_' . $id] ?? $line->rdtaxcodcdt; |
||
| 46 | $line->rdtaxcodlegaltip = $formData['rdtaxcodlegaltip_' . $id] ?? $line->rdtaxcodlegaltip; |
||
| 47 | $line->rdtaxcodfirstplate = $formData['rdtaxcodfirstplate_' . $id] ?? $line->rdtaxcodfirstplate; |
||
| 48 | $line->totalplustaxes = $formData['totalplustaxes_' . $id] ?? $line->totalplustaxes; |
||
| 49 | } |
||
| 50 | |||
| 51 | public function assets(): void |
||
| 52 | { |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @param Translator $i18n |
||
| 57 | * @param string $attributes |
||
| 58 | * @param string $label |
||
| 59 | * @param int $idlinea |
||
| 60 | * @param array $options |
||
| 61 | * @return string |
||
| 62 | */ |
||
| 63 | private function getStr(Translator $i18n, string $attributes, string $label, $idlinea, array $options): string |
||
| 64 | { |
||
| 65 | $idlinea = (!$idlinea) ? 0 : $idlinea; |
||
| 66 | return '<div class="col-6">' |
||
| 67 | . '<div class="mb-2">' |
||
| 68 | . $i18n->trans($label) |
||
| 69 | . '<select onchange="return salesFormAction(\'recalculate-line\', \'' . $idlinea . '\');"' |
||
| 70 | . $attributes . ' class="form-select" >' . implode('', $options) . '</select>' |
||
| 71 | . '</div>' |
||
| 72 | . '</div>'; |
||
| 73 | } |
||
| 74 | |||
| 75 | private function getLineAddedTaxes(SalesDocumentLine $line): float |
||
| 76 | { |
||
| 77 | $rdtaxisc = isset($line->rdtaxisc) ? (float)$line->rdtaxisc : 0.0; |
||
| 78 | $rdtaxcdt = isset($line->rdtaxcdt) ? (float)$line->rdtaxcdt : 0.0; |
||
| 79 | $rdtaxlegaltip = isset($line->rdtaxlegaltip) ? (float)$line->rdtaxlegaltip : 0.0; |
||
| 80 | $rdtaxfirstplate = isset($line->rdtaxfirstplate) ? (float)$line->rdtaxfirstplate : 0.0; |
||
| 81 | $pvpsindto = isset($line->pvpsindto) ? (float)$line->pvpsindto : 0.0; |
||
| 82 | |||
| 83 | return $pvpsindto * ($rdtaxisc + $rdtaxcdt + $rdtaxlegaltip + $rdtaxfirstplate) / 100.0; |
||
| 84 | } |
||
| 85 | |||
| 86 | public function map(array $lines, SalesDocument $model): array |
||
| 87 | { |
||
| 88 | $map = []; |
||
| 89 | $num = 0; |
||
| 90 | foreach ($lines as $line) { |
||
| 91 | $num++; |
||
| 92 | $idlinea = $line->idlinea ?? 'n' . $num; |
||
| 93 | $map['rdtaxcodisc_' . $idlinea] = $line->rdtaxcodisc; |
||
| 94 | $map['rdtaxcodcdt_' . $idlinea] = $line->rdtaxcodcdt; |
||
| 95 | $map['rdtaxcodlegaltip_' . $idlinea] = $line->rdtaxcodlegaltip; |
||
| 96 | $map['rdtaxcodfirstplate_' . $idlinea] = $line->rdtaxcodfirstplate; |
||
| 97 | // El total de la línea es el totalplustaxes (pvptotal + IVA) |
||
| 98 | $map['totalplustaxes_' . $idlinea] = $line->totalplustaxes; |
||
| 99 | } |
||
| 100 | return $map; |
||
| 101 | } |
||
| 102 | |||
| 103 | public function newModalFields(): array |
||
| 104 | { |
||
| 105 | return ['rdtaxcodisc','rdtaxcodcdt','rdtaxcodlegaltip','rdtaxcodfirstplate']; |
||
| 106 | } |
||
| 107 | |||
| 108 | public function newFields(): array |
||
| 109 | { |
||
| 110 | return ['totalplustaxes']; |
||
| 111 | } |
||
| 112 | |||
| 113 | public function newTitles(): array |
||
| 114 | { |
||
| 115 | return ['totalplustaxes']; |
||
| 116 | } |
||
| 117 | |||
| 118 | public function renderField(string $idlinea, SalesDocumentLine $line, SalesDocument $model, string $field): ?string |
||
| 119 | { |
||
| 120 | switch ($field) { |
||
| 121 | case "rdtaxcodisc": |
||
| 122 | return $this->loadCodeISC($idlinea, $line, $model->editable); |
||
| 123 | case "rdtaxcodcdt": |
||
| 124 | return $this->loadCodeCDT($idlinea, $line, $model->editable); |
||
| 125 | case "rdtaxcodlegaltip": |
||
| 126 | return $this->loadCodeLegalTip($idlinea, $line, $model->editable); |
||
| 127 | case "rdtaxcodfirstplate": |
||
| 128 | return $this->loadCodeFirstPlate($idlinea, $line, $model->editable); |
||
| 129 | case "totalplustaxes": |
||
| 130 | return $this->renderTotalField($idlinea, $line, $model, $model->editable); |
||
| 131 | default: |
||
| 132 | return null; |
||
| 133 | } |
||
| 134 | } |
||
| 135 | |||
| 136 | private function renderTotalField(string $idlinea, SalesDocumentLine $line, SalesDocument $model): string |
||
| 137 | { |
||
| 138 | $nf0 = Tools::settings('default', 'decimals', 2); |
||
| 139 | |||
| 140 | return '<div class="col col-lg-1 order-8 columnTotalPlusTaxes" lang="es-DO">' |
||
| 141 | . '<div class="d-lg-none mt-2 small">' . Tools::trans('desc-total-plustaxes') . '</div>' |
||
| 142 | . '<input type="number" name="totalplustaxes_' . $idlinea . '" value="' . number_format($line->totalplustaxes, $nf0,'.', '') |
||
| 143 | . '" class="form-control form-control-sm text-lg-end border-0" readonly/>' |
||
| 144 | . '</div>'; |
||
| 145 | } |
||
| 146 | |||
| 147 | public function renderTitle(SalesDocument $model, string $field): ?string |
||
| 148 | { |
||
| 149 | switch ($field) { |
||
| 150 | case "totalplustaxes": |
||
| 151 | return '<div class="col-lg-1 text-end order-8 columTotalPlusTaxes">' .Tools::trans('desc-total-plustaxes') . '</div>'; |
||
| 152 | default: |
||
| 153 | return null; |
||
| 154 | } |
||
| 155 | } |
||
| 156 | |||
| 157 | public function getFastLine(SalesDocument $model, array $formData): ?SalesDocumentLine |
||
| 158 | { |
||
| 159 | return null; |
||
| 160 | } |
||
| 161 | |||
| 162 | public function loadCodeISC(string $idlinea, SalesDocumentLine $line, $editable): string |
||
| 163 | { |
||
| 164 | $i18n = new Translator(); |
||
| 165 | $impuestosAdicionales = new ImpuestoAdicional(); |
||
| 166 | $where = [new DataBaseWhere('tipo_impuesto_short', 'ISC')]; |
||
| 167 | $iscList = $impuestosAdicionales::all($where, ['codigo'=>'DESC']); |
||
| 168 | if (!$iscList) { |
||
| 169 | return ''; |
||
| 170 | } |
||
| 171 | |||
| 172 | $invoiceLineISC = ($line->rdtaxcodisc) ? $line->rdtaxcodisc : ""; |
||
| 173 | $options = ['<option value="">----------'.$invoiceLineISC.'</option>']; |
||
| 174 | foreach ($iscList as $row) { |
||
| 175 | $options[] = ($row->codigo === $invoiceLineISC) ? |
||
| 176 | '<option value="' . $row->codigo . '" selected="">' . $row->tipo_impuesto_short . ' - ' . $row->descripcion . '</option>' : |
||
| 177 | '<option value="' . $row->codigo . '">' . $row->tipo_impuesto_short . ' - ' . $row->descripcion . '</option>'; |
||
| 178 | } |
||
| 179 | |||
| 180 | $attributes = ($editable) ? 'name="rdtaxcodisc_' . $idlinea . '"' : 'name="rdtaxcodisc_' . $idlinea . '" disabled=""'; |
||
| 181 | return $this->getStr($i18n, $attributes, "label-desc-rdtaxcodisc", $idlinea, $options); |
||
| 182 | } |
||
| 183 | public function loadCodeCDT(string $idlinea, SalesDocumentLine $line, $editable): string |
||
| 184 | { |
||
| 185 | $i18n = new Translator(); |
||
| 186 | $impuestosAdicionales = new ImpuestoAdicional(); |
||
| 187 | $where = [new DataBaseWhere('tipo_impuesto_short', 'CDT')]; |
||
| 188 | $cdtList = $impuestosAdicionales::all($where, ['codigo'=>'DESC']); |
||
| 189 | if (!$cdtList) { |
||
| 190 | return ''; |
||
| 191 | } |
||
| 192 | |||
| 193 | $invoiceLineCDT = ($line->rdtaxcodcdt) ? $line->rdtaxcodcdt : ""; |
||
| 194 | |||
| 195 | $options = ['<option value="">----------</option>']; |
||
| 196 | foreach ($cdtList as $row) { |
||
| 197 | $options[] = ($row->codigo === $invoiceLineCDT) ? |
||
| 198 | '<option value="' . $row->codigo . '" selected="">' . $row->tipo_impuesto_short . ' - ' . $row->descripcion . '</option>' : |
||
| 199 | '<option value="' . $row->codigo . '">' . $row->tipo_impuesto_short . ' - ' . $row->descripcion . '</option>'; |
||
| 200 | } |
||
| 201 | |||
| 202 | $attributes = ($editable) ? 'name="rdtaxcodcdt_' . $idlinea . '"' : 'disabled=""'; |
||
| 203 | return $this->getStr($i18n, $attributes, "label-desc-rdtaxcodcdt", $idlinea, $options); |
||
| 204 | } |
||
| 205 | public function loadCodeLegalTip(string $idlinea, SalesDocumentLine $line, $editable): string |
||
| 226 | } |
||
| 227 | public function loadCodeFirstPlate(string $idlinea, SalesDocumentLine $line, $editable): string |
||
| 228 | { |
||
| 229 | $i18n = new Translator(); |
||
| 230 | $impuestosAdicionales = new ImpuestoAdicional(); |
||
| 231 | $where = [new DataBaseWhere('tipo_impuesto_short', 'Primera Placa')]; |
||
| 232 | $firstPlateList = $impuestosAdicionales::all($where, ['codigo'=>'DESC']); |
||
| 233 | if (!$firstPlateList) { |
||
| 234 | return ''; |
||
| 235 | } |
||
| 248 | } |
||
| 249 | } |
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