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

RefundResponse   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 5
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