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