| Total Complexity | 43 |
| Total Lines | 321 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Complex classes like residentes_pdf 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 residentes_pdf, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 26 | class residentes_pdf extends fs_pdf |
||
|
|
|||
| 27 | { |
||
| 28 | const LOGO_X = 40; |
||
| 29 | const LOGO_Y = 700; |
||
| 30 | |||
| 31 | public $cliente_residente; |
||
| 32 | |||
| 33 | public function calcular_tamanyo_logo() |
||
| 49 | } |
||
| 50 | |||
| 51 | public function generar_tipo_doc($tipo_documento) |
||
| 52 | { |
||
| 53 | return ucfirst(str_replace('_', ' ', $tipo_documento)); |
||
| 54 | } |
||
| 55 | |||
| 56 | public function generar_pdf_cabecera(&$empresa, &$lppag) |
||
| 57 | { |
||
| 58 | /// ¿Añadimos el logo? |
||
| 59 | if ($this->logo !== false) { |
||
| 60 | if (function_exists('imagecreatefromstring')) { |
||
| 61 | $lppag -= 2; /// si metemos el logo, caben menos líneas |
||
| 62 | |||
| 63 | $tamanyo = $this->calcular_tamanyo_logo(); |
||
| 64 | if (strtolower(substr($this->logo, -4)) === '.png') { |
||
| 65 | $this->pdf->addPngFromFile($this->logo, self::LOGO_X, self::LOGO_Y, $tamanyo[0], $tamanyo[1]); |
||
| 66 | } elseif (function_exists('imagepng')) { |
||
| 67 | /** |
||
| 68 | * La librería ezpdf tiene problemas al redimensionar jpegs, |
||
| 69 | * así que hacemos la conversión a png para evitar estos problemas. |
||
| 70 | */ |
||
| 71 | if (imagepng(imagecreatefromstring(file_get_contents($this->logo)), FS_MYDOCS |
||
|
1 ignored issue
–
show
|
|||
| 72 | . 'images/logo.png')) { |
||
| 73 | $this->pdf->addPngFromFile( |
||
| 74 | FS_MYDOCS . 'images/logo.png', |
||
| 75 | self::LOGO_X, |
||
| 76 | self::LOGO_Y, |
||
| 77 | $tamanyo[0], |
||
| 78 | $tamanyo[1] |
||
| 79 | ); |
||
| 80 | } else { |
||
| 81 | $this->pdf->addJpegFromFile($this->logo, self::LOGO_X, self::LOGO_Y, $tamanyo[0], $tamanyo[1]); |
||
| 82 | } |
||
| 83 | } else { |
||
| 84 | $this->pdf->addJpegFromFile($this->logo, self::LOGO_X, self::LOGO_Y, $tamanyo[0], $tamanyo[1]); |
||
| 85 | } |
||
| 86 | |||
| 87 | $this->pdf->ez['rightMargin'] = 40; |
||
| 88 | $this->pdf->ezText( |
||
| 89 | "<b>" . fs_fix_html($empresa->nombre) . "</b>", |
||
| 90 | 12, |
||
| 91 | array('justification' => 'right') |
||
| 92 | ); |
||
| 93 | $this->pdf->ezText(FS_CIFNIF . ": " . $empresa->cifnif, 8, array('justification' => 'right')); |
||
|
1 ignored issue
–
show
|
|||
| 94 | |||
| 95 | $direccion = $empresa->direccion . "\n"; |
||
| 96 | if ($empresa->apartado) { |
||
| 97 | $direccion .= ucfirst(FS_APARTADO) . ': ' . $empresa->apartado . ' - '; |
||
|
1 ignored issue
–
show
|
|||
| 98 | } |
||
| 99 | |||
| 100 | if ($empresa->codpostal) { |
||
| 101 | $direccion .= 'CP: ' . $empresa->codpostal . ' - '; |
||
| 102 | } |
||
| 103 | |||
| 104 | if ($empresa->ciudad) { |
||
| 105 | $direccion .= $empresa->ciudad . ' - '; |
||
| 106 | } |
||
| 107 | |||
| 108 | if ($empresa->provincia) { |
||
| 109 | $direccion .= '(' . $empresa->provincia . ')'; |
||
| 110 | } |
||
| 111 | |||
| 112 | if ($empresa->telefono) { |
||
| 113 | $direccion .= "\nTeléfono: " . $empresa->telefono; |
||
| 114 | } |
||
| 115 | |||
| 116 | $this->pdf->ezText(fs_fix_html($direccion) . "\n", 8, array('justification' => 'right')); |
||
| 117 | $this->set_y(self::LOGO_Y + 10); |
||
| 118 | } else { |
||
| 119 | die('ERROR: no se encuentra la función imagecreatefromstring(). ' |
||
| 120 | . 'Y por tanto no se puede usar el logotipo en los documentos.'); |
||
| 121 | } |
||
| 122 | } else { |
||
| 123 | $this->pdf->ezText( |
||
| 124 | "<b>" . fs_fix_html($empresa->nombre) . "</b>", |
||
| 125 | 12, |
||
| 126 | array('justification' => 'center') |
||
| 127 | ); |
||
| 128 | $this->pdf->ezText(FS_CIFNIF . ": " . $empresa->cifnif, 8, array('justification' => 'center')); |
||
| 129 | |||
| 130 | $direccion = $empresa->direccion; |
||
| 131 | if ($empresa->apartado) { |
||
| 132 | $direccion .= ' - ' . ucfirst(FS_APARTADO) . ': ' . $empresa->apartado; |
||
| 133 | } |
||
| 134 | |||
| 135 | if ($empresa->codpostal) { |
||
| 136 | $direccion .= ' - CP: ' . $empresa->codpostal; |
||
| 137 | } |
||
| 138 | |||
| 139 | if ($empresa->ciudad) { |
||
| 140 | $direccion .= ' - ' . $empresa->ciudad; |
||
| 141 | } |
||
| 142 | |||
| 143 | if ($empresa->provincia) { |
||
| 144 | $direccion .= ' (' . $empresa->provincia . ')'; |
||
| 145 | } |
||
| 146 | |||
| 147 | if ($empresa->telefono) { |
||
| 148 | $direccion .= ' - Teléfono: ' . $empresa->telefono; |
||
| 149 | } |
||
| 150 | |||
| 151 | $this->pdf->ezText(fs_fix_html($direccion), 8, array('justification' => 'center')); |
||
| 152 | } |
||
| 153 | } |
||
| 154 | |||
| 155 | public function generar_datos_residente(&$pdf_doc, $tipo_documento, &$lppag, $table_width = 560) |
||
| 156 | { |
||
| 157 | $width_campo1 = 110; |
||
| 158 | $tipo_doc = $this->generar_tipo_doc($tipo_documento); |
||
| 159 | $tipo_residente = ($this->cliente_residente->informacion->propietario) ? 'Propietario' : 'Inquilino'; |
||
| 160 | /* |
||
| 161 | * Esta es la tabla con los datos del cliente: |
||
| 162 | * Informe Cobros Fecha: |
||
| 163 | * Cliente: Tipo Residente: |
||
| 164 | * Dirección: Teléfonos: |
||
| 165 | */ |
||
| 166 | $pdf_doc->new_table(); |
||
| 167 | $pdf_doc->add_table_row( |
||
| 168 | array( |
||
| 169 | 'campo1' => "<b>" . $tipo_doc . "</b>", |
||
| 170 | 'dato1' => '', |
||
| 171 | 'campo2' => "<b>Fecha Impresión:</b> " . \date('d-m-Y H:i:s') |
||
| 172 | ) |
||
| 173 | ); |
||
| 174 | |||
| 175 | $pdf_doc->add_table_row( |
||
| 176 | array( |
||
| 177 | 'campo1' => "<b>Residente:</b>", |
||
| 178 | 'dato1' => fs_fix_html($this->cliente_residente->nombre), |
||
| 179 | 'campo2' => "<b>Tipo Residente:</b> " . $tipo_residente |
||
| 180 | ) |
||
| 181 | ); |
||
| 182 | |||
| 183 | $row = array( |
||
| 184 | 'campo1' => "<b>Inmueble:</b>", |
||
| 185 | 'dato1' => fs_fix_html($this->cliente_residente->inmueble->codigo_externo() . |
||
| 186 | ' - ' . $this->cliente_residente->inmueble->numero), |
||
| 187 | 'campo2' => '' |
||
| 188 | ); |
||
| 189 | |||
| 190 | if (!$this->cliente_residente) { |
||
| 191 | /// nada |
||
| 192 | } elseif ($this->cliente_residente->telefono1) { |
||
| 193 | $row['campo2'] = "<b>Teléfonos:</b> " . $this->cliente_residente->telefono1; |
||
| 194 | if ($this->cliente_residente->telefono2) { |
||
| 195 | $row['campo2'] .= "\n" . $this->cliente_residente->telefono2; |
||
| 196 | $lppag -= 2; |
||
| 197 | } |
||
| 198 | } elseif ($this->cliente_residente->telefono2) { |
||
| 199 | $row['campo2'] = "<b>Teléfonos:</b> " . $this->cliente_residente->telefono2; |
||
| 200 | } |
||
| 201 | $pdf_doc->add_table_row($row); |
||
| 202 | |||
| 203 | $pdf_doc->save_table( |
||
| 204 | array( |
||
| 205 | 'cols' => array( |
||
| 206 | 'campo1' => array('width' => $width_campo1, 'justification' => 'right'), |
||
| 207 | 'dato1' => array('justification' => 'left'), |
||
| 208 | 'campo2' => array('justification' => 'right') |
||
| 209 | ), |
||
| 210 | 'showLines' => 0, |
||
| 211 | 'width' => $table_width, |
||
| 212 | 'shaded' => 0, |
||
| 213 | 'fontSize' => 8 |
||
| 214 | ) |
||
| 215 | ); |
||
| 216 | $pdf_doc->pdf->ezText("\n", 10); |
||
| 217 | } |
||
| 218 | |||
| 219 | public function generar_pdf_lineas(&$pdf_doc, &$items, &$linea_actual, &$lppag, $tipo, $table_width = 540) |
||
| 220 | { |
||
| 221 | /// calculamos el número de páginas |
||
| 222 | if (!isset($this->numpaginas)) { |
||
| 223 | $this->numpaginas = 0; |
||
| 224 | $lineas = 0; |
||
| 225 | while ($lineas < count($items)) { |
||
| 226 | $lppag2 = $lppag; |
||
| 227 | $this->verificar_longitud_linea($items, $lineas, $lppag2); |
||
| 228 | $lineas += $lppag2; |
||
| 229 | $this->numpaginas++; |
||
| 230 | } |
||
| 231 | |||
| 232 | if ($this->numpaginas === 0) { |
||
| 233 | $this->numpaginas = 1; |
||
| 234 | } |
||
| 235 | } |
||
| 236 | |||
| 237 | /// leemos las líneas para ver si hay que mostrar mas información |
||
| 238 | $this->verificar_longitud_linea($items, $linea_actual, $lppag); |
||
| 239 | |||
| 240 | /* |
||
| 241 | * Creamos la tabla con las lineas de pendientes |
||
| 242 | */ |
||
| 243 | $pdf_doc->new_table(); |
||
| 244 | [$table_header, $array_cols] = $this->generar_pdf_lineas_tablas($tipo); |
||
| 245 | $pdf_doc->add_table_header($table_header); |
||
| 246 | |||
| 247 | for ($i = $linea_actual; (($linea_actual < ($lppag + $i)) && ( $linea_actual < count($items)));) { |
||
| 248 | $fila = $this->generar_pdf_lineas_fila($tipo, $items, $linea_actual); |
||
| 249 | $pdf_doc->add_table_row($fila); |
||
| 250 | $linea_actual++; |
||
| 251 | } |
||
| 252 | |||
| 253 | $pdf_doc->save_table( |
||
| 254 | array( |
||
| 255 | 'fontSize' => 8, |
||
| 256 | 'cols' => $array_cols, |
||
| 257 | 'width' => $table_width, |
||
| 258 | 'shaded' => 1, |
||
| 259 | 'shadeCol' => array(0.95, 0.95, 0.95), |
||
| 260 | 'lineCol' => array(0.3, 0.3, 0.3), |
||
| 261 | ) |
||
| 262 | ); |
||
| 263 | } |
||
| 264 | |||
| 265 | public function generar_pdf_lineas_tablas($tipo) |
||
| 266 | { |
||
| 267 | $table_header = array( |
||
| 268 | 'item' => '<b>Pendiente de Pago</b>', 'fecha' => '<b>Fecha</b>', |
||
| 269 | 'vencimiento' => '<b>Vencimiento</b>', 'importe' => '<b>Monto</b>', |
||
| 270 | 'descuento' => '<b>Descuento</b>', 'total' => '<b>Total</b>', 'atraso' => '<b>Atraso</b>', |
||
| 271 | ); |
||
| 272 | $array_cols = array( |
||
| 273 | 'item' => array('justification' => 'left'), 'fecha' => array('justification' => 'center'), |
||
| 274 | 'vencimiento' => array('justification' => 'center'), 'importe' => array('justification' => 'right'), |
||
| 275 | 'descuento' => array('justification' => 'right'), |
||
| 276 | 'total' => array('justification' => 'right'), 'atraso' => array('justification' => 'center') |
||
| 277 | ); |
||
| 278 | if ($tipo === 'pagado') { |
||
| 279 | $table_header = array( |
||
| 280 | 'item' => '<b>Pagos Realizados</b>', 'fecha' => '<b>Fecha</b>', |
||
| 281 | 'importe' => '<b>Monto</b>', 'f_pago' => '<b>F. Pago</b>' |
||
| 282 | ); |
||
| 283 | $array_cols = array( |
||
| 284 | 'item' => array('justification' => 'left'), 'fecha' => array('justification' => 'center'), |
||
| 285 | 'importe' => array('justification' => 'right'), 'f_pago' => array('justification' => 'center') |
||
| 286 | ); |
||
| 287 | } |
||
| 288 | |||
| 289 | return array($table_header,$array_cols); |
||
| 290 | } |
||
| 291 | |||
| 292 | public function generar_pdf_lineas_fila($tipo, $items, $linea_actual) |
||
| 329 | } |
||
| 330 | |||
| 331 | public function verificar_longitud_linea($items, &$lineas, &$lppag2) |
||
| 347 | } |
||
| 348 | } |
||
| 349 | } |
||
| 350 | } |
||
| 351 | } |
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