CancelRequest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 19 5
A __construct() 0 6 1
1
<?php
2
3
namespace DansMaCulotte\Monetico\Requests;
4
5
use DansMaCulotte\Monetico\Exceptions\Exception;
6
use DansMaCulotte\Monetico\Exceptions\RecoveryException;
7
use DateTime;
8
9
class CancelRequest extends RecoveryRequest
10
{
11
    /**
12
     * Cancel constructor.
13
     * @param array $data
14
     * @throws Exception
15
     * @throws RecoveryException
16
     */
17
    public function __construct(array $data = [])
18
    {
19
        $data['amountLeft'] = 0;
20
        $data['amountToRecover'] = 0;
21
22
        parent::__construct($data);
23
    }
24
25
    /**
26
     * @return bool
27
     * @throws Exception
28
     */
29
    public function validate(): bool
30
    {
31
        if (!$this->dateTime instanceof DateTime) {
0 ignored issues
show
introduced by
$this->dateTime is always a sub-type of DateTime.
Loading history...
32
            throw Exception::invalidDatetime();
33
        }
34
35
        if (!$this->orderDate instanceof DateTime) {
0 ignored issues
show
introduced by
$this->orderDate is always a sub-type of DateTime.
Loading history...
36
            throw Exception::invalidOrderDate();
37
        }
38
39
        if (strlen($this->reference) > 12) {
40
            throw Exception::invalidReference($this->reference);
41
        }
42
43
        if (strlen($this->language) !== 2) {
44
            throw Exception::invalidLanguage($this->language);
45
        }
46
47
        return true;
48
    }
49
}
50