Passed
Pull Request — master (#17)
by Carlos C
02:31
created

CodigoPostal::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
c 1
b 0
f 0
nc 2
nop 8
dl 0
loc 19
ccs 9
cts 9
cp 1
crap 2
rs 10

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpCfdi\SatCatalogos\CFDI;
6
7
use PhpCfdi\SatCatalogos\Common\AbstractEntryIdentifiable;
8
use PhpCfdi\SatCatalogos\Common\EntryIdentifiable;
9
use PhpCfdi\SatCatalogos\Exceptions\SatCatalogosLogicException;
10
11
class CodigoPostal extends AbstractEntryIdentifiable implements EntryIdentifiable
12
{
13
    /** @var string */
14
    private $estado;
15
16
    /** @var string */
17
    private $municipio;
18
19
    /** @var string */
20
    private $localidad;
21
22
    /** @var int */
23
    private $estimuloFrontera;
24
25
    /** @var HusoHorario */
26
    private $husoHorario;
27
28 7
    public function __construct(
29
        string $id,
30
        string $estado,
31
        string $municipio,
32
        string $localidad,
33
        int $estimuloFrontera,
34
        HusoHorario $husoHorario,
35
        int $vigenteDesde,
36
        int $vigenteHasta
37
    ) {
38 7
        parent::__construct($id, $id, $vigenteDesde, $vigenteHasta);
39 7
        if ('' === $estado) {
40 1
            throw new SatCatalogosLogicException('El campo estado no puede ser una cadena de caracteres vacía');
41
        }
42 6
        $this->estado = $estado;
43 6
        $this->municipio = $municipio;
44 6
        $this->localidad = $localidad;
45 6
        $this->estimuloFrontera = $estimuloFrontera;
46 6
        $this->husoHorario = $husoHorario;
47
    }
48
49 2
    public function estado(): string
50
    {
51 2
        return $this->estado;
52
    }
53
54 2
    public function municipio(): string
55
    {
56 2
        return $this->municipio;
57
    }
58
59 2
    public function localidad(): string
60
    {
61 2
        return $this->localidad;
62
    }
63
64 4
    public function estimuloFrontera(): int
65
    {
66 4
        return $this->estimuloFrontera;
67
    }
68
69 3
    public function hasEstimuloFrontera(): bool
70
    {
71 3
        return 0 !== $this->estimuloFrontera;
72
    }
73
74 1
    public function husoHorario(): HusoHorario
75
    {
76 1
        return $this->husoHorario;
77
    }
78
}
79