Passed
Push — master ( 048cfc...89074f )
by
unknown
12:32
created

Transaction::setCategory()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 4
nc 4
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Model;
6
7
use Application\Traits\HasName;
8
use Application\Traits\HasRemarks;
9
use Cake\Chronos\Date;
10
use Doctrine\ORM\Mapping as ORM;
11
12
/**
13
 * A monetary transaction
14
 *
15
 * @ORM\Entity(repositoryClass="Application\Repository\TransactionRepository")
16
 */
17
class Transaction extends AbstractModel
18
{
19
    use hasName;
20
    use hasRemarks;
21
22
    /**
23
     * @var Account
24
     *
25
     * @ORM\ManyToOne(targetEntity="Account", inversedBy="transactions")
26
     * @ORM\JoinColumns({
27
     *     @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
28
     * })
29
     */
30
    private $account;
31
32
    /**
33
     * @var float
34
     *
35
     * @ORM\Column(type="decimal", precision=7, scale=2)
36
     */
37
    private $amount;
38
39
    /**
40
     * @var Date
41
     * @ORM\Column(name="transactionDate", type="date")
42
     */
43
    private $transactionDate;
44
45
    /**
46
     * @var string
47
     *
48
     * @ORM\Column(type="text", length=65535)
49
     */
50
    private $internalRemarks = '';
51
52
    /**
53
     * @var ExpenseClaim
54
     *
55
     * @ORM\ManyToOne(targetEntity="ExpenseClaim", inversedBy="transactions")
56
     * @ORM\JoinColumns({
57
     *     @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
58
     * })
59
     */
60
    private $expenseClaim;
61
62
    /**
63
     * @var Category
64
     *
65
     * @ORM\ManyToOne(targetEntity="Category", inversedBy="transactions")
66
     * @ORM\JoinColumns({
67
     *     @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
68
     * })
69
     */
70
    private $category;
71
72
    /**
73
     * Set account
74
     *
75
     * @param Account $account
76
     */
77
    public function setAccount(Account $account): void
78
    {
79
        if ($this->account) {
80
            $this->account->transactionRemoved($this);
81
        }
82
        $this->account = $account;
83
        $this->account && $this->account->transactionAdded($this);
84
    }
85
86
    /**
87
     * Get account
88
     *
89
     * @return Account
90
     */
91
    public function getAccount(): Account
92
    {
93
        return $this->account;
94
    }
95
96
    /**
97
     * Set amount
98
     *
99
     * @param float $amount
100
     */
101
    public function setAmount(float $amount): void
102
    {
103
        $this->amount = $amount;
104
    }
105
106
    /**
107
     * @return float
108
     */
109
    public function getAmount(): float
110
    {
111
        return $this->amount;
112
    }
113
114
    /**
115
     * Set date of transaction
116
     *
117
     * @param Date $transactionDate
118
     */
119
    public function setTransactionDate(Date $transactionDate): void
120
    {
121
        $this->transactionDate = $transactionDate;
122
    }
123
124
    /**
125
     * Get date of transaction
126
     *
127
     * @return Date
128
     */
129
    public function getTransactionDate(): Date
130
    {
131
        return $this->transactionDate;
132
    }
133
134
    /**
135
     * Set remarks for internal use
136
     *
137
     * @param string $internalRemarks
138
     */
139
    public function setInternalRemarks(string $internalRemarks): void
140
    {
141
        $this->internalRemarks = $internalRemarks;
142
    }
143
144
    /**
145
     * Get remarks for internal use
146
     *
147
     * @return string
148
     */
149
    public function getInternalRemarks(): string
150
    {
151
        return $this->internalRemarks;
152
    }
153
154
    /**
155
     * Set expense claim
156
     *
157
     * @param null|ExpenseClaim $expenseClaim
158
     */
159
    public function setExpenseClaim(?ExpenseClaim $expenseClaim): void
160
    {
161
        if ($this->expenseClaim && $expenseClaim !== $this->expenseClaim) {
162
            $this->expenseClaim->transactionRemoved($this);
163
        }
164
165
        $this->expenseClaim = $expenseClaim;
166
        $this->expenseClaim && $this->expenseClaim->transactionAdded($this);
167
    }
168
169
    /**
170
     * Get expense claim
171
     *
172
     * @return null|ExpenseClaim
173
     */
174
    public function getExpenseClaim(): ?ExpenseClaim
175
    {
176
        return $this->expenseClaim;
177
    }
178
179
    /**
180
     * Set category
181
     *
182
     * @param null|Category $category
183
     */
184
    public function setCategory(?Category $category): void
185
    {
186
        if ($this->category && $category !== $this->category) {
187
            $this->category->transactionRemoved($this);
188
        }
189
190
        $this->category = $category;
191
        $this->category && $this->category->transactionAdded($this);
192
    }
193
194
    /**
195
     * Get category
196
     *
197
     * @return null|Category
198
     */
199
    public function getCategory(): ?Category
200
    {
201
        return $this->category;
202
    }
203
}
204