Passed
Push — master ( f4ebb6...c31285 )
by Gaël
11:14
created

RefundResponse::__construct()   A

Complexity

Conditions 5
Paths 7

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 9
nc 7
nop 1
dl 0
loc 15
rs 9.6111
c 0
b 0
f 0
1
<?php
2
3
namespace DansMaCulotte\Monetico\Responses;
4
5
use DansMaCulotte\Monetico\Exceptions\Exception;
6
7
class RefundResponse extends AbstractResponse
8
{
9
    /** @var string */
10
    public $fileNumber;
11
12
    /** @var string */
13
    public $invoiceType;
14
15
    /** @var array */
16
    const INVOICE_TYPES = [
17
        'preauto',
18
        'noshow',
19
        'complementaire',
20
    ];
21
22
    /**
23
     * RefundResponse constructor.
24
     *
25
     * @param array $data
26
     * @throws Exception
27
     */
28
    public function __construct(array $data = [])
29
    {
30
        parent::__construct($data);
31
32
        if (isset($data['numero_dossier'])) {
33
            $this->fileNumber = $data['numero_dossier'];
34
            if (strlen($this->fileNumber) > 12) {
35
                throw Exception::invalidResponseFileNumber($this->fileNumber);
36
            }
37
        }
38
39
        if (isset($data['type_facture'])) {
40
            $this->invoiceType = $data['type_facture'];
41
            if (!in_array($this->invoiceType, self::INVOICE_TYPES)) {
42
                throw Exception::invalidResponseInvoiceType($this->invoiceType);
43
            }
44
        }
45
    }
46
}
47