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