Passed
Push — master ( 224db0...04cfc9 )
by Thiago
33s
created

Charge::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
namespace MrPrompt\ShipmentCommon\Base;
3
4
/**
5
 * Charge
6
 *
7
 * @author Thiago Paes <[email protected]>
8
 */
9
class Charge
10
{
11
    /**
12
     * Billet
13
     *
14
     * @const string
15
     */
16
    const BILLET        = 'B';
17
18
    /**
19
     * Credit card
20
     *
21
     * @const string
22
     */
23
    const CREDIT_CARD   = 'C';
24
25
    /**
26
     * Debit on bank account
27
     *
28
     * @const string
29
     */
30
    const DEBIT         = 'D';
31
32
    /**
33
     * Energy account
34
     *
35
     * @const string
36
     */
37
    const ENERGY        = 'E';
38
39
    /**
40
     * Batch File
41
     *
42
     * @const string
43
     */
44
    const BATCH_FILE    = 'F';
45
46
    /**
47
     * Payment Slip
48
     *
49
     * @const string
50
     */
51
    const PAYMENT_SLIP  = 'P';
52
53
    /**
54
     * Charging type
55
     *
56
     * Types:
57
     *  - B = Boleto Bancário
58
     *  - E = Energia
59
     *  - C = Cartão de Crédito
60
     *  - D = Débito Automático
61
     *  - D = Arquivo de Remessa
62
     *  - P = Bloqueto
63
     *
64
     * @var string
65
     */
66
    private $charging;
67
68
    /**
69
     * Occurrence
70
     *
71
     * @var Ocurrence
72
     */
73
    private $occurrence;
74
75
    /**
76
     * Valid types
77
     * 
78
     * @var array
79
     */
80
    private $validTypes = [
81
        self::BILLET,
82
        self::CREDIT_CARD,
83
        self::DEBIT,
84
        self::ENERGY,
85
        self::BATCH_FILE,
86
        self::PAYMENT_SLIP
87
    ];
88
89 5
    public function __construct(
90
        string $charging = self::CREDIT_CARD,
91
        Occurrence $occurrence = null
92
    ) {
93 5
        $this->charging = $charging;
94 5
        $this->occurrence = $occurrence ?? new Occurrence();
0 ignored issues
show
Documentation Bug introduced by
It seems like $occurrence ?? new \MrPr...ommon\Base\Occurrence() of type object<MrPrompt\ShipmentCommon\Base\Occurrence> is incompatible with the declared type object<MrPrompt\ShipmentCommon\Base\Ocurrence> of property $occurrence.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
95 5
    }
96
97
    /**
98
     * @return the $charging
99
     */
100 1
    public function getCharging(): string
101
    {
102 1
        return $this->charging;
103
    }
104
105
    /**
106
     * @param string $charging
107
     */
108 2
    public function setCharging(string $charging)
109
    {
110 2
        if (!in_array($charging, $this->validTypes)) {
111 1
            throw new \InvalidArgumentException(sprintf('Invalid charge type: %s', $charging));
112
        }
113
114 1
        $this->charging = $charging;
115 1
    }
116
117
    /**
118
     * @return Occurrence
119
     */
120 1
    public function getOccurrence(): Occurrence
121
    {
122 1
        return $this->occurrence;
123
    }
124
125
    /**
126
     * @param Occurrence $occurrence
127
     */
128 1
    public function setOccurrence(Occurrence $occurrence)
129
    {
130 1
        $this->occurrence = $occurrence;
0 ignored issues
show
Documentation Bug introduced by
It seems like $occurrence of type object<MrPrompt\ShipmentCommon\Base\Occurrence> is incompatible with the declared type object<MrPrompt\ShipmentCommon\Base\Ocurrence> of property $occurrence.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
131 1
    }
132
}
133