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