| Total Complexity | 64 |
| Total Lines | 216 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
Complex classes like SalesFooterMod 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 SalesFooterMod, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 31 | class SalesFooterMod implements SalesModInterface |
||
| 32 | { |
||
| 33 | public function apply(SalesDocument &$model, array $formData): void |
||
| 34 | { |
||
| 35 | |||
| 36 | } |
||
| 37 | |||
| 38 | public function applyBefore(SalesDocument &$model, array $formData): void |
||
| 47 | } |
||
| 48 | } |
||
| 49 | |||
| 50 | public function assets(): void |
||
| 51 | { |
||
| 52 | } |
||
| 53 | |||
| 54 | public function newBtnFields(): array |
||
| 55 | { |
||
| 56 | return []; |
||
| 57 | } |
||
| 58 | |||
| 59 | public function newFields(): array |
||
| 60 | { |
||
| 61 | return ['numeroncf', 'tipocomprobante', 'ncffechavencimiento', 'ncftipopago', 'ncftipomovimiento', 'ncftipoanulacion']; |
||
| 62 | } |
||
| 63 | |||
| 64 | public function newModalFields(): array |
||
| 65 | { |
||
| 66 | return []; |
||
| 67 | } |
||
| 68 | |||
| 69 | public function renderField(SalesDocument $model, string $field): ?string |
||
| 70 | { |
||
| 71 | if ($model->modelClassName() === 'FacturaCliente') { |
||
| 72 | $i18n = new Translator(); |
||
| 73 | switch ($field) { |
||
| 74 | case "numeroncf": |
||
| 75 | return self::numeroncf($i18n, $model); |
||
| 76 | case "tipocomprobante": |
||
| 77 | return self::tipoComprobante($i18n, $model); |
||
| 78 | case "ncffechavencimiento": |
||
| 79 | return self::ncfFechaVencimiento($i18n, $model); |
||
| 80 | case "ncftipopago": |
||
| 81 | return self::ncfTipoPago($i18n, $model); |
||
| 82 | case "ncftipomovimiento": |
||
| 83 | return self::ncfTipoMovimiento($i18n, $model); |
||
| 84 | case "ncftipoanulacion": |
||
| 85 | return self::ncfTipoAnulacion($i18n, $model); |
||
| 86 | default: |
||
| 87 | return null; |
||
| 88 | } |
||
| 89 | } |
||
| 90 | return null; |
||
| 91 | } |
||
| 92 | |||
| 93 | private static function infoCliente($codcliente) |
||
| 94 | { |
||
| 95 | $cliente = new Cliente(); |
||
| 96 | $actualCliente = $cliente::find($codcliente); |
||
| 97 | if ('' !== $actualCliente) { |
||
| 98 | return $actualCliente; |
||
| 99 | } |
||
| 100 | return null; |
||
| 101 | } |
||
| 102 | |||
| 103 | private static function tipoComprobante(Translator $i18n, SalesDocument $model): string |
||
| 104 | { |
||
| 105 | $tipoComprobante = NCFTipo::allVentas(); |
||
| 106 | if (count($tipoComprobante) === 0) { |
||
| 107 | return ''; |
||
| 108 | } |
||
| 109 | |||
| 110 | $cliente = self::infoCliente($model->codcliente); |
||
| 111 | $cliente->tipocomprobante = ($cliente->tipocomprobante === null) ? "02" : $cliente->tipocomprobante; |
||
| 112 | |||
| 113 | $invoiceTipoComprobante = ($model->tipocomprobante !== null) ? $model->tipocomprobante : $cliente->tipocomprobante; |
||
| 114 | if (!$model->editable) { |
||
| 115 | $invoiceTipoComprobante = $model->tipocomprobante; |
||
| 116 | } elseif ($model->editable === true && ($cliente->tipocomprobante !== $model->tipocomprobante) && $model->tipocomprobante !== null) { |
||
| 117 | $invoiceTipoComprobante = $model->tipocomprobante; |
||
| 118 | } elseif ($model->editable === true && ($cliente->tipocomprobante === $model->tipocomprobante) && $model->tipocomprobante !== null) { |
||
| 119 | $invoiceTipoComprobante = $cliente->tipocomprobante; |
||
| 120 | } |
||
| 121 | |||
| 122 | $options = ['<option value="">------</option>']; |
||
| 123 | foreach ($tipoComprobante as $row) { |
||
| 124 | $options[] = ($row->tipocomprobante === $invoiceTipoComprobante) ? |
||
| 125 | '<option value="' . $row->tipocomprobante . '" selected="">' . $row->descripcion . '</option>' : |
||
| 126 | '<option value="' . $row->tipocomprobante . '">' . $row->descripcion . '</option>'; |
||
| 127 | } |
||
| 128 | |||
| 129 | $attributes = ($model->editable || $model->numeroncf === '') ? |
||
| 130 | 'id="tipocomprobante" name="tipocomprobante" required="" onChange="verificarCorrelativoNCF(this.value,\'Ventas\')"' : |
||
| 131 | 'disabled=""'; |
||
| 132 | |||
| 133 | return '<div class="col-sm-3">' |
||
| 134 | . '<div class="mb-3">' |
||
| 135 | . $i18n->trans('tipocomprobante') |
||
| 136 | . '<select ' . $attributes . ' class="form-select">' . implode('', $options) . '</select>' |
||
| 137 | . '</div>' |
||
| 138 | . '</div>'; |
||
| 139 | } |
||
| 140 | |||
| 141 | private static function ncfTipoPago(Translator $i18n, SalesDocument $model): string |
||
| 142 | { |
||
| 143 | $NCFTipoPago = new NCFTipoPago(); |
||
| 144 | $tipoPago = $NCFTipoPago->findAllByTipopago('01'); |
||
| 145 | if (count($tipoPago) === 0) { |
||
| 146 | return ''; |
||
| 147 | } |
||
| 148 | |||
| 149 | $cliente = self::infoCliente($model->codcliente); |
||
| 150 | |||
| 151 | if ($model->ncftipopago) { |
||
| 152 | $invoiceTipoPago = $model->ncftipopago; |
||
| 153 | } else { |
||
| 154 | $invoiceTipoPago = ($cliente->ncftipopago !== '') ? $cliente->ncftipopago : "17"; |
||
| 155 | } |
||
| 156 | |||
| 157 | $options = ['<option value="">------</option>']; |
||
| 158 | foreach ($tipoPago as $row) { |
||
| 159 | $options[] = ($row->codigo === $invoiceTipoPago) ? |
||
| 160 | '<option value="' . $row->codigo . '" selected="">' . $row->descripcion . '</option>' : |
||
| 161 | '<option value="' . $row->codigo . '">' . $row->descripcion . '</option>'; |
||
| 162 | } |
||
| 163 | |||
| 164 | $attributes = $model->editable ? 'name="ncftipopago" required=""' : 'disabled=""'; |
||
| 165 | return '<div class="col-sm-2">' |
||
| 166 | . '<div class="mb-3">' |
||
| 167 | . $i18n->trans('ncf-payment-type') |
||
| 168 | . '<select ' . $attributes . ' class="form-select">' . implode('', $options) . '</select>' |
||
| 169 | . '</div>' |
||
| 170 | . '</div>'; |
||
| 171 | } |
||
| 172 | |||
| 173 | private static function ncfTipoMovimiento(Translator $i18n, SalesDocument $model): string |
||
| 174 | { |
||
| 175 | $NCFTipoMovimiento = new NCFTipoMovimiento(); |
||
| 176 | $tipoMovimiento = $NCFTipoMovimiento->findAllByTipomovimiento('VEN'); |
||
| 177 | if (count($tipoMovimiento) === 0) { |
||
| 178 | return ''; |
||
| 179 | } |
||
| 180 | |||
| 181 | $invoiceTipoMovimiento = ($model->ncftipomovimiento) ?: "1"; |
||
| 182 | |||
| 183 | $options = ['<option value="">------</option>']; |
||
| 184 | foreach ($tipoMovimiento as $row) { |
||
| 185 | $options[] = ($row->codigo === $invoiceTipoMovimiento) ? |
||
| 186 | '<option value="' . $row->codigo . '" selected="">' . $row->descripcion . '</option>' : |
||
| 187 | '<option value="' . $row->codigo . '">' . $row->descripcion . '</option>'; |
||
| 188 | } |
||
| 189 | |||
| 190 | $attributes = $model->editable ? 'name="ncftipomovimiento" required=""' : 'disabled=""'; |
||
| 191 | return '<div class="col-sm-3">' |
||
| 192 | . '<div class="mb-3">' |
||
| 193 | . $i18n->trans('ncf-movement-type') |
||
| 194 | . '<select ' . $attributes . ' class="form-select">' . implode('', $options) . '</select>' |
||
| 195 | . '</div>' |
||
| 196 | . '</div>'; |
||
| 197 | } |
||
| 198 | |||
| 199 | private static function ncfTipoAnulacion(Translator $i18n, SalesDocument $model): string |
||
| 200 | { |
||
| 201 | $NCFTipoAnulacion = new NCFTipoAnulacion(); |
||
| 202 | $tipoAnulacion = $NCFTipoAnulacion->all(); |
||
| 203 | if (count($tipoAnulacion) === 0) { |
||
| 204 | return ''; |
||
| 205 | } |
||
| 206 | |||
| 207 | $invoiceTipoAnulacion = ($model->ncftipoanulacion) ?: ""; |
||
| 208 | |||
| 209 | $options = ['<option value="">------</option>']; |
||
| 210 | foreach ($tipoAnulacion as $row) { |
||
| 211 | $options[] = ($row->codigo === $invoiceTipoAnulacion) ? |
||
| 212 | '<option value="' . $row->codigo . '" selected="">' . $row->descripcion . '</option>' : |
||
| 213 | '<option value="' . $row->codigo . '">' . $row->descripcion . '</option>'; |
||
| 214 | } |
||
| 215 | |||
| 216 | $attributes = $model->editable ? 'name="ncftipoanulacion"' : 'disabled=""'; |
||
| 217 | return '<div class="col-sm-2">' |
||
| 218 | . '<div class="mb-3">' |
||
| 219 | . $i18n->trans('ncf-cancellation-type') |
||
| 220 | . '<select ' . $attributes . ' class="form-select">' . implode('', $options) . '</select>' |
||
| 221 | . '</div>' |
||
| 222 | . '</div>'; |
||
| 223 | } |
||
| 224 | |||
| 225 | private static function ncfFechaVencimiento(Translator $i18n, SalesDocument $model): string |
||
| 236 | } |
||
| 237 | |||
| 238 | private static function numeroncf(Translator $i18n, SalesDocument $model): string |
||
| 239 | { |
||
| 240 | $attributes = ($model->editable) ? 'name="numeroncf" maxlength="20"' : 'disabled=""'; |
||
| 241 | return empty($model->codcliente) ? '' : '<div class="col-sm">' |
||
| 242 | . '<div class="mb-3">' |
||
| 243 | . $i18n->trans('desc-numeroncf-sales') |
||
| 247 | } |
||
| 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