PersonalStatementRequest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 17
c 1
b 0
f 1
dl 0
loc 77
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getAccountID() 0 3 1
A setAccountID() 0 5 1
A __construct() 0 14 3
A getTo() 0 3 1
A getFrom() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Monobank\Request;
6
7
use DateTimeInterface;
8
use Monobank\ValueObject\AccountID;
9
use Monobank\Exception\RequestException;
10
11
/**
12
 * @see https://api.monobank.ua/docs/
13
 */
14
class PersonalStatementRequest
15
{
16
    private const MAX_PERIOD_IN_SECONDS = 2678400;
17
18
    /**
19
     * @var DateTimeInterface
20
     */
21
    private $from;
22
23
    /**
24
     * @var DateTimeInterface
25
     */
26
    private $to;
27
28
    /**
29
     * @var AccountID
30
     */
31
    private $accountID;
32
33
    /**
34
     * The maximum time for which it is possible to extract is 31 days (2678400 seconds).
35
     *
36
     * @param DateTimeInterface $from
37
     * @param DateTimeInterface $to
38
     *
39
     * @throws RequestException
40
     */
41
    public function __construct(DateTimeInterface $from, DateTimeInterface $to)
42
    {
43
        if ($from > $to) {
44
            throw RequestException::invalidPersonalStatementPeriod();
45
        }
46
47
        $diffInSeconds = $to->getTimestamp() - $from->getTimestamp();
48
49
        if ($diffInSeconds > self::MAX_PERIOD_IN_SECONDS) {
50
            throw RequestException::maxPersonalStatementPeriod();
51
        }
52
53
        $this->from = $from;
54
        $this->to = $to;
55
    }
56
57
    /**
58
     * @return DateTimeInterface
59
     */
60
    public function getFrom(): DateTimeInterface
61
    {
62
        return $this->from;
63
    }
64
65
    /**
66
     * @return DateTimeInterface
67
     */
68
    public function getTo(): DateTimeInterface
69
    {
70
        return $this->to;
71
    }
72
73
    /**
74
     * @return AccountID|null
75
     */
76
    public function getAccountID(): ?AccountID
77
    {
78
        return $this->accountID;
79
    }
80
81
    /**
82
     * @param AccountID $accountID
83
     *
84
     * @return PersonalStatementRequest
85
     */
86
    public function setAccountID(AccountID $accountID): self
87
    {
88
        $this->accountID = $accountID;
89
90
        return $this;
91
    }
92
}
93