|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace DansMaCulotte\Monetico\Responses; |
|
4
|
|
|
|
|
5
|
|
|
use DansMaCulotte\Monetico\Exceptions\Exception; |
|
6
|
|
|
use DansMaCulotte\Monetico\Exceptions\RecoveryException; |
|
7
|
|
|
use DateTime; |
|
8
|
|
|
|
|
9
|
|
|
class RecoveryResponse extends AbstractResponse |
|
10
|
|
|
{ |
|
11
|
|
|
/** @var string */ |
|
12
|
|
|
public $authorisationNumber; |
|
13
|
|
|
|
|
14
|
|
|
/** @var string */ |
|
15
|
|
|
public $phone; |
|
16
|
|
|
|
|
17
|
|
|
/** @var float */ |
|
18
|
|
|
public $estimatedAmount; |
|
19
|
|
|
|
|
20
|
|
|
/** @var \DateTime */ |
|
21
|
|
|
public $authorisationDate; |
|
22
|
|
|
|
|
23
|
|
|
/** @var string */ |
|
24
|
|
|
public $currency; |
|
25
|
|
|
|
|
26
|
|
|
/** @var float */ |
|
27
|
|
|
public $amountDebited; |
|
28
|
|
|
|
|
29
|
|
|
/** @var \DateTime */ |
|
30
|
|
|
public $debitDate; |
|
31
|
|
|
|
|
32
|
|
|
/** @var string */ |
|
33
|
|
|
public $fileNumber; |
|
34
|
|
|
|
|
35
|
|
|
/** @var string */ |
|
36
|
|
|
public $invoiceType; |
|
37
|
|
|
|
|
38
|
|
|
/** @var array */ |
|
39
|
|
|
const INVOICE_TYPES = [ |
|
40
|
|
|
'preauto', |
|
41
|
|
|
'noshow', |
|
42
|
|
|
]; |
|
43
|
|
|
|
|
44
|
|
|
/** @var string */ |
|
45
|
|
|
const DATE_FORMAT = 'Y-m-d'; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* RecoveryResponse constructor. |
|
49
|
|
|
* |
|
50
|
|
|
* @param array $data |
|
51
|
|
|
* @throws Exception |
|
52
|
|
|
* @throws RecoveryException |
|
53
|
|
|
*/ |
|
54
|
|
|
public function __construct(array $data = []) |
|
55
|
|
|
{ |
|
56
|
|
|
parent::__construct($data); |
|
57
|
|
|
|
|
58
|
|
|
$this->setOptions($data); |
|
59
|
|
|
$this->setDates($data); |
|
60
|
|
|
$this->setAmounts($data); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param array $data |
|
65
|
|
|
* @throws RecoveryException |
|
66
|
|
|
*/ |
|
67
|
|
|
private function setDates($data): void |
|
68
|
|
|
{ |
|
69
|
|
|
if (isset($data['date_autorisation'])) { |
|
70
|
|
|
$this->authorisationDate = DateTime::createFromFormat(self::DATE_FORMAT, $data['date_autorisation']); |
|
|
|
|
|
|
71
|
|
|
if (!$this->authorisationDate) { |
|
72
|
|
|
throw RecoveryException::invalidResponseAuthorizationDate(); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
if (isset($data['date_debit'])) { |
|
77
|
|
|
$this->debitDate = DateTime::createFromFormat(self::DATE_FORMAT, $data['date_debit']); |
|
|
|
|
|
|
78
|
|
|
if (!$this->authorisationDate) { |
|
79
|
|
|
throw RecoveryException::invalidResponseDebitDate(); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @param array $data |
|
86
|
|
|
* @throws Exception |
|
87
|
|
|
*/ |
|
88
|
|
|
public function setOptions(array $data): void |
|
89
|
|
|
{ |
|
90
|
|
|
if (isset($data['aut'])) { |
|
91
|
|
|
$this->authorisationNumber = $data['aut']; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
if (isset($data['numero_dossier'])) { |
|
95
|
|
|
$this->fileNumber = $data['numero_dossier']; |
|
96
|
|
|
if (strlen($this->fileNumber) > 12) { |
|
97
|
|
|
throw Exception::invalidResponseFileNumber($this->fileNumber); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
if (isset($data['type_facture'])) { |
|
102
|
|
|
$this->invoiceType = $data['type_facture']; |
|
103
|
|
|
if (!in_array($this->invoiceType, self::INVOICE_TYPES)) { |
|
104
|
|
|
throw Exception::invalidResponseInvoiceType($this->invoiceType); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
if (isset($data['phonie'])) { |
|
109
|
|
|
$this->phone = $data['phonie']; |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @param array $data |
|
115
|
|
|
*/ |
|
116
|
|
|
private function setAmounts(array $data): void |
|
117
|
|
|
{ |
|
118
|
|
|
if (isset($data['montant_estime'])) { |
|
119
|
|
|
$this->estimatedAmount = $data['montant_estime']; |
|
120
|
|
|
} |
|
121
|
|
|
if (isset($data['montant_debite'])) { |
|
122
|
|
|
$this->amountDebited = $data['montant_debite']; |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.