Issues (20)

src/Requests/CancelRequest.php (2 issues)

Severity
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
$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
$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