Completed
Push — master ( 5594ea...e43a77 )
by Laurent
03:34 queued 01:39
created

CreateExpenseNoteCommand   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 104
rs 10
c 0
b 0
f 0
wmc 9
lcom 0
cbo 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 26 4
A getYear() 0 4 1
A getQuartile() 0 4 1
A getUserValidatorId() 0 4 1
A getPrivateNote() 0 4 1
A getPublicNote() 0 4 1
1
<?php
2
/**
3
 *
4
 */
5
6
namespace flightlog\command;
7
8
use flightlog\exceptions\PeriodNotFinishedException;
9
use Webmozart\Assert\Assert;
10
11
/**
12
 * CreateExpenseNoteCommand class
13
 *
14
 * @author Laurent De Coninck <[email protected]>
15
 */
16
class CreateExpenseNoteCommand
17
{
18
19
    /**
20
     * @var int
21
     */
22
    private $year;
23
24
    /**
25
     * @var int
26
     */
27
    private $quartile;
28
29
    /**
30
     * @var int
31
     */
32
    private $userValidatorId;
33
34
    /**
35
     * @var string
36
     */
37
    private $privateNote;
38
39
    /**
40
     * @var string
41
     */
42
    private $publicNote;
43
44
    /**
45
     * @param int    $year
46
     * @param int    $quartile
47
     * @param int    $userValidatorId
48
     * @param string $privateNote
49
     * @param string $publicNote
50
     *
51
     * @throws PeriodNotFinishedException
52
     */
53
    public function __construct($year, $quartile, $userValidatorId, $privateNote, $publicNote)
54
    {
55
        $currentYear = date('Y');
56
        $currentQuarter = floor((date('n') - 1) / 3) + 1;
57
58
        Assert::integerish($year);
59
        Assert::greaterThan($year, 0);
60
61
        Assert::notNull($quartile);
62
        Assert::integerish($quartile);
63
        Assert::greaterThan($quartile, 0);
64
        Assert::lessThanEq($quartile, 4);
65
66
        Assert::integerish($userValidatorId);
67
        Assert::greaterThan($userValidatorId, 0);
68
69
        if (!($year < $currentYear || ($year == $currentYear && $quartile < $currentQuarter))) {
70
            throw new PeriodNotFinishedException('');
71
        }
72
73
        $this->year = (int) $year;
74
        $this->quartile = (int) $quartile;
75
        $this->userValidatorId = (int) $userValidatorId;
76
        $this->privateNote = $privateNote;
77
        $this->publicNote = $publicNote;
78
    }
79
80
    /**
81
     * @return int
82
     */
83
    public function getYear()
84
    {
85
        return $this->year;
86
    }
87
88
    /**
89
     * @return int
90
     */
91
    public function getQuartile()
92
    {
93
        return $this->quartile;
94
    }
95
96
    /**
97
     * @return int
98
     */
99
    public function getUserValidatorId()
100
    {
101
        return $this->userValidatorId;
102
    }
103
104
    /**
105
     * @return string
106
     */
107
    public function getPrivateNote()
108
    {
109
        return $this->privateNote;
110
    }
111
112
    /**
113
     * @return string
114
     */
115
    public function getPublicNote()
116
    {
117
        return $this->publicNote;
118
    }
119
}