| Total Complexity | 68 |
| Total Lines | 271 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like PurchasesFooterMod 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 PurchasesFooterMod, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 32 | class PurchasesFooterMod implements PurchasesModInterface |
||
| 33 | { |
||
| 34 | public function apply(PurchaseDocument &$model, array $formData): void |
||
| 35 | { |
||
| 36 | } |
||
| 37 | |||
| 38 | public function applyBefore(PurchaseDocument &$model, array $formData): void |
||
| 39 | { |
||
| 40 | if ($model->modelClassName() === 'FacturaProveedor') { |
||
| 41 | $model->numeroncf = isset($formData['numeroncf']) ? (string)$formData['numeroncf'] : $model->numeroncf; |
||
| 42 | $model->tipocomprobante = isset($formData['tipocomprobante']) ? (string)$formData['tipocomprobante'] : $model->tipocomprobante; |
||
| 43 | $model->ncffechavencimiento = isset($formData['ncffechavencimiento']) ? (string)$formData['ncffechavencimiento'] : $model->ncffechavencimiento; |
||
| 44 | $model->ncftipopago = isset($formData['ncftipopago']) ? (string)$formData['ncftipopago'] : $model->ncftipopago; |
||
| 45 | $model->ncftipomovimiento = isset($formData['ncftipomovimiento']) ? (string)$formData['ncftipomovimiento'] : $model->ncftipomovimiento; |
||
| 46 | $model->ncftipoanulacion = isset($formData['ncftipoanulacion']) ? (string)$formData['ncftipoanulacion'] : $model->ncftipoanulacion; |
||
| 47 | $model->ecf_fecha_firma = isset($formData['ecf_fecha_firma']) ? (string)$formData['ecf_fecha_firma'] : $model->ecf_fecha_firma; |
||
| 48 | $model->ecf_codigo_seguridad = isset($formData['ecf_codigo_seguridad']) ? (string)$formData['ecf_codigo_seguridad'] : $model->ecf_codigo_seguridad; |
||
| 49 | } |
||
| 50 | } |
||
| 51 | |||
| 52 | public function assets(): void |
||
| 53 | { |
||
| 54 | } |
||
| 55 | |||
| 56 | public function newBtnFields(): array |
||
| 57 | { |
||
| 58 | return ['btnLoadXmlEcf','btnLoadXmlAck','btnLoadPdfEcf']; |
||
| 59 | } |
||
| 60 | |||
| 61 | public function newFields(): array |
||
| 62 | { |
||
| 63 | return ['numeroncf', 'tipocomprobante', 'ncffechavencimiento', 'ncftipopago', 'ncftipomovimiento', 'ncftipoanulacion', 'ecf_xml_firmado','ecf_fecha_firma','ecf_codigo_seguridad']; |
||
| 64 | } |
||
| 65 | |||
| 66 | public function newModalFields(): array |
||
| 67 | { |
||
| 68 | return []; |
||
| 69 | } |
||
| 70 | |||
| 71 | public function renderField(PurchaseDocument $model, string $field): ?string |
||
| 72 | { |
||
| 73 | $i18n = new Translator(); |
||
| 74 | if ($model->modelClassName() === 'FacturaProveedor') { |
||
| 75 | switch ($field) { |
||
| 76 | case "numeroncf": |
||
| 77 | return self::numeroNCF($i18n, $model); |
||
| 78 | case "tipocomprobante": |
||
| 79 | return self::tipoComprobante($i18n, $model); |
||
| 80 | case "ncffechavencimiento": |
||
| 81 | return self::ncfFechaVencimiento($i18n, $model); |
||
| 82 | case "ncftipopago": |
||
| 83 | return self::ncfTipoPago($i18n, $model); |
||
| 84 | case "ncftipomovimiento": |
||
| 85 | return self::ncfTipoMovimiento($i18n, $model); |
||
| 86 | case "ncftipoanulacion": |
||
| 87 | return self::ncfTipoAnulacion($i18n, $model); |
||
| 88 | case "ecf_fecha_firma": |
||
| 89 | return self::ecfFechaFirma($i18n, $model); |
||
| 90 | case "ecf_codigo_seguridad": |
||
| 91 | return self::ecfCodigoSeguridad($i18n, $model); |
||
| 92 | case "btnLoadXmlEcf": |
||
| 93 | return self::btnLoadXmlEcf($i18n, $model); |
||
| 94 | default: |
||
| 95 | return null; |
||
| 96 | } |
||
| 97 | } |
||
| 98 | return null; |
||
| 99 | } |
||
| 100 | |||
| 101 | private static function btnLoadXmlEcf(Translator $i18n, PurchaseDocument $model): string |
||
| 102 | { |
||
| 103 | $html = '<div class="row align-items-start">' |
||
| 104 | . '<div class="col-sm-5 text-start">' |
||
| 105 | . '<label for="xmlFile" class="form-label">' |
||
| 106 | . '<i class="fa-solid fa-file-code me-1 text-primary"></i> Archivo XML de e-Factura' |
||
| 107 | . '</label>' |
||
| 108 | . '<div class="input-group">' |
||
| 109 | . ' <input type="file" class="form-control" id="xmlFile" name="xmlFile" onchange="enableParseIfReady()" accept=".xml,text/xml,application/xml">' |
||
| 110 | // . ' <label class="input-group-text" for="xmlFile"><i class="fa-solid fa-upload"></i></label>' |
||
| 111 | . ' <div class="invalid-feedback">Seleccione un archivo XML válido.</div>' |
||
| 112 | // . '</div>' |
||
| 113 | // . '<div class="form-group text-start">' |
||
| 114 | . '<button type="button" id="btnParseXml" onclick="btnParseClick()" class="btn btn-danger" disabled>' |
||
| 115 | . '<i class="fas fa-fw fa-file-code"></i>' |
||
| 116 | . $i18n->trans('btn-load-xml-ecf') |
||
| 117 | . '</input>' |
||
| 118 | . '</div>' |
||
| 119 | . '</div></div>'; |
||
| 120 | |||
| 121 | return $html; |
||
| 122 | } |
||
| 123 | |||
| 124 | private static function infoProveedor($codproveedor) |
||
| 125 | { |
||
| 126 | $proveedor = new Proveedor(); |
||
| 127 | $actualProveedor = $proveedor::find($codproveedor); |
||
| 128 | if ('' !== $actualProveedor) { |
||
| 129 | return $actualProveedor; |
||
| 130 | } |
||
| 131 | return null; |
||
| 132 | } |
||
| 133 | |||
| 134 | private static function tipoComprobante(Translator $i18n, PurchaseDocument $model): string |
||
| 135 | { |
||
| 136 | $tipoComprobante = NCFTipo::allCompras(); |
||
| 137 | if (count($tipoComprobante) === 0) { |
||
| 138 | return ''; |
||
| 139 | } |
||
| 140 | |||
| 141 | $invoiceTipoComprobante = ($model->tipocomprobante) ? $model->tipocomprobante : ""; |
||
| 142 | |||
| 143 | $options = ['<option value="">------</option>']; |
||
| 144 | foreach ($tipoComprobante as $row) { |
||
| 145 | $options[] = ($row->tipocomprobante === $invoiceTipoComprobante) ? |
||
| 146 | '<option value="' . $row->tipocomprobante . '" selected="">' . $row->descripcion . '</option>' : |
||
| 147 | '<option value="' . $row->tipocomprobante . '">' . $row->descripcion . '</option>'; |
||
| 148 | } |
||
| 149 | |||
| 150 | $attributes = ($model->editable || $model->numeroncf === '') ? 'name="tipocomprobante" required=""' : 'disabled=""'; |
||
| 151 | return '<div class="col-sm-3">' |
||
| 152 | . '<div class="mb-3">' |
||
| 153 | . $i18n->trans('tipocomprobante') |
||
| 154 | . '<select ' . $attributes . ' class="form-select">' . implode('', $options) . '</select>' |
||
| 155 | . '</div>' |
||
| 156 | . '</div>'; |
||
| 157 | } |
||
| 158 | |||
| 159 | private static function ncfTipoPago(Translator $i18n, PurchaseDocument $model): string |
||
| 160 | { |
||
| 161 | $NCFTipoPago = new NCFTipoPago(); |
||
| 162 | $tipoPago = $NCFTipoPago->findAllByTipopago('02'); |
||
| 163 | if (count($tipoPago) === 0) { |
||
| 164 | return ''; |
||
| 165 | } |
||
| 166 | |||
| 167 | $proveedor = self::infoProveedor($model->codproveedor); |
||
| 168 | |||
| 169 | if ($model->ncftipopago) { |
||
| 170 | $invoiceTipoPago = $model->ncftipopago; |
||
| 171 | } else { |
||
| 172 | $invoiceTipoPago = ($proveedor->ncftipopago !== '') ? $proveedor->ncftipopago : "01"; |
||
| 173 | } |
||
| 174 | |||
| 175 | $options = ['<option value="">------</option>']; |
||
| 176 | foreach ($tipoPago as $row) { |
||
| 177 | $options[] = ($row->codigo === $invoiceTipoPago) ? |
||
| 178 | '<option value="' . $row->codigo . '" selected="">' . $row->descripcion . '</option>' : |
||
| 179 | '<option value="' . $row->codigo . '">' . $row->descripcion . '</option>'; |
||
| 180 | } |
||
| 181 | |||
| 182 | $attributes = $model->editable ? 'name="ncftipopago" required=""' : 'disabled=""'; |
||
| 183 | return '<div class="col-sm-2">' |
||
| 184 | . '<div class="mb-3">' |
||
| 185 | . $i18n->trans('ncf-payment-type') |
||
| 186 | . '<select ' . $attributes . ' class="form-select">' . implode('', $options) . '</select>' |
||
| 187 | . '</div>' |
||
| 188 | . '</div>'; |
||
| 189 | } |
||
| 190 | |||
| 191 | private static function ncfTipoMovimiento(Translator $i18n, PurchaseDocument $model): string |
||
| 192 | { |
||
| 193 | $NCFTipoMovimiento = new NCFTipoMovimiento(); |
||
| 194 | $tipoMovimiento = $NCFTipoMovimiento->findAllByTipomovimiento('COM'); |
||
| 195 | if (count($tipoMovimiento) === 0) { |
||
| 196 | return ''; |
||
| 197 | } |
||
| 198 | |||
| 199 | $invoiceTipoMovimiento = ($model->ncftipomovimiento) ?: "09"; |
||
| 200 | |||
| 201 | $options = ['<option value="">------</option>']; |
||
| 202 | foreach ($tipoMovimiento as $row) { |
||
| 203 | $options[] = ($row->codigo === $invoiceTipoMovimiento) ? |
||
| 204 | '<option value="' . $row->codigo . '" selected="">' . $row->descripcion . '</option>' : |
||
| 205 | '<option value="' . $row->codigo . '">' . $row->descripcion . '</option>'; |
||
| 206 | } |
||
| 207 | |||
| 208 | $attributes = $model->editable ? 'name="ncftipomovimiento" required=""' : 'disabled=""'; |
||
| 209 | return '<div class="col-sm-3">' |
||
| 210 | . '<div class="mb-3">' |
||
| 211 | . $i18n->trans('ncf-movement-type') |
||
| 212 | . '<select ' . $attributes . ' class="form-select">' . implode('', $options) . '</select>' |
||
| 213 | . '</div>' |
||
| 214 | . '</div>'; |
||
| 215 | } |
||
| 216 | |||
| 217 | private static function ncfTipoAnulacion(Translator $i18n, PurchaseDocument $model): string |
||
| 218 | { |
||
| 219 | $NCFTipoAnulacion = new NCFTipoAnulacion(); |
||
| 220 | $tipoAnulacion = $NCFTipoAnulacion->all(); |
||
| 221 | if (count($tipoAnulacion) === 0) { |
||
| 222 | return ''; |
||
| 223 | } |
||
| 224 | |||
| 225 | $invoiceTipoAnulacion = ($model->ncftipoanulacion) ?: ""; |
||
| 226 | |||
| 227 | $options = ['<option value="">------</option>']; |
||
| 228 | foreach ($tipoAnulacion as $row) { |
||
| 229 | $options[] = ($row->codigo === $invoiceTipoAnulacion) ? |
||
| 230 | '<option value="' . $row->codigo . '" selected="">' . $row->descripcion . '</option>' : |
||
| 231 | '<option value="' . $row->codigo . '">' . $row->descripcion . '</option>'; |
||
| 232 | } |
||
| 233 | |||
| 234 | $attributes = $model->editable ? 'name="ncftipoanulacion"' : 'name="ncftipoanulacion" readonly=""'; |
||
| 235 | return '<div class="col-sm-2">' |
||
| 236 | . '<div class="mb-3">' |
||
| 237 | . $i18n->trans('ncf-cancellation-type') |
||
| 238 | . '<select ' . $attributes . ' class="form-select">' . implode('', $options) . '</select>' |
||
| 239 | . '</div>' |
||
| 240 | . '</div>'; |
||
| 241 | } |
||
| 242 | |||
| 243 | private static function ncfFechaVencimiento(Translator $i18n, PurchaseDocument $model): string |
||
| 244 | { |
||
| 245 | $attributes = ($model->editable) ? 'name="ncffechavencimiento"' : 'disabled=""'; |
||
| 246 | $ncfFechaVencimiento = ($model->ncffechavencimiento) |
||
| 247 | ? date('Y-m-d', strtotime($model->ncffechavencimiento)) |
||
| 248 | : ''; |
||
| 249 | return '<div class="col-sm-2">' |
||
| 250 | . '<div class="mb-3">' . $i18n->trans('due-date') |
||
| 251 | . '<input type="date" ' . $attributes . ' value="' |
||
| 252 | . $ncfFechaVencimiento . '" class="form-control"/>' |
||
| 253 | . '</div>' |
||
| 254 | . '</div>'; |
||
| 255 | } |
||
| 256 | |||
| 257 | private static function numeroNCF(Translator $i18n, PurchaseDocument $model): string |
||
| 258 | { |
||
| 259 | $attributes = ($model->editable) ? 'name="numeroncf" maxlength="20"' : 'disabled=""'; |
||
| 260 | $btnColor = (in_array($model->numeroncf, ['', null], true)) ? "btn-secondary" : "btn-success"; |
||
| 261 | return empty($model->codproveedor) ? '' : '<div class="col-sm">' |
||
| 262 | . '<div class="mb-3">' |
||
| 263 | . $i18n->trans('desc-numeroncf-purchases') |
||
| 264 | . '<div class="input-group">' |
||
| 265 | . '<input type="text" ' . $attributes . ' value="' . $model->numeroncf . '" class="form-control"/>' |
||
| 266 | . '<button class="btn ' . $btnColor . ' btn-spin-action" id="btnVerifyNCF"' |
||
| 267 | . 'onclick="purchasesNCFVerify()" ' |
||
| 268 | . 'title="' . $i18n->trans('verify-numproveedor') |
||
| 269 | . '" type="button">' |
||
| 270 | . '<i id="iconBtnVerify" class="fa-solid fa-search fa-fw"></i>' |
||
| 271 | . '</button>' |
||
| 272 | . '</div>' |
||
| 273 | . '</div>' |
||
| 274 | . '</div>'; |
||
| 275 | } |
||
| 276 | |||
| 277 | private static function ecfFechaFirma(Translator $i18n, PurchaseDocument $model): string |
||
| 289 | } |
||
| 290 | |||
| 291 | private static function ecfCodigoSeguridad(Translator $i18n, PurchaseDocument $model): string |
||
| 292 | { |
||
| 303 | } |
||
| 304 | } |
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