Failed Conditions
Push — master ( 44ffdf...976c98 )
by Sam
06:49
created

Transaction::getBookable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
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 Bookable
34
     *
35
     * @ORM\ManyToOne(targetEntity="Bookable", inversedBy="transactions")
36
     * @ORM\JoinColumns({
37
     *     @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
38
     * })
39
     */
40
    private $bookable;
41
42
    /**
43
     * @var string
44
     *
45
     * @ORM\Column(type="decimal", precision=7, scale=2)
46
     */
47
    private $amount;
48
49
    /**
50
     * @var Date
51
     * @ORM\Column(name="transactionDate", type="date")
52
     */
53
    private $transactionDate;
54
55
    /**
56
     * @var string
57
     *
58
     * @ORM\Column(type="text", length=65535)
59
     */
60
    private $internalRemarks = '';
61
62
    /**
63
     * @var ExpenseClaim
64
     *
65
     * @ORM\ManyToOne(targetEntity="ExpenseClaim", inversedBy="transactions")
66
     * @ORM\JoinColumns({
67
     *     @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
68
     * })
69
     */
70
    private $expenseClaim;
71
72
    /**
73
     * @var Category
74
     *
75
     * @ORM\ManyToOne(targetEntity="Category", inversedBy="transactions")
76
     * @ORM\JoinColumns({
77
     *     @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
78
     * })
79
     */
80
    private $category;
81
82
    /**
83
     * Set account
84
     *
85
     * @param Account $account
86
     */
87 1
    public function setAccount(Account $account): void
88
    {
89 1
        if ($this->account) {
90 1
            $this->account->transactionRemoved($this);
91
        }
92 1
        $this->account = $account;
93 1
        $this->account && $this->account->transactionAdded($this);
94 1
    }
95
96
    /**
97
     * Get account
98
     *
99
     * @return Account
100
     */
101 1
    public function getAccount(): Account
102
    {
103 1
        return $this->account;
104
    }
105
106
    /**
107
     * Get account
108
     *
109
     * @return null|Bookable
110
     */
111
    public function getBookable(): ?Bookable
112
    {
113
        return $this->bookable;
114
    }
115
116
    /**
117
     * Set bookable
118
     *
119
     * @param null|Bookable $bookable
120
     */
121 1
    public function setBookable(?Bookable $bookable): void
122
    {
123 1
        if ($this->bookable) {
124 1
            $this->bookable->transactionRemoved($this);
125
        }
126 1
        $this->bookable = $bookable;
127 1
        $this->bookable && $this->bookable->transactionAdded($this);
128 1
    }
129
130
    /**
131
     * Set amount
132
     *
133
     * @param string $amount
134
     */
135
    public function setAmount(string $amount): void
136
    {
137
        $this->amount = $amount;
138
    }
139
140
    /**
141
     * @return string
142
     */
143
    public function getAmount(): string
144
    {
145
        return $this->amount;
146
    }
147
148
    /**
149
     * Set date of transaction
150
     *
151
     * @param Date $transactionDate
152
     */
153
    public function setTransactionDate(Date $transactionDate): void
154
    {
155
        $this->transactionDate = $transactionDate;
156
    }
157
158
    /**
159
     * Get date of transaction
160
     *
161
     * @return Date
162
     */
163
    public function getTransactionDate(): Date
164
    {
165
        return $this->transactionDate;
166
    }
167
168
    /**
169
     * Set remarks for internal use
170
     *
171
     * @param string $internalRemarks
172
     */
173
    public function setInternalRemarks(string $internalRemarks): void
174
    {
175
        $this->internalRemarks = $internalRemarks;
176
    }
177
178
    /**
179
     * Get remarks for internal use
180
     *
181
     * @return string
182
     */
183
    public function getInternalRemarks(): string
184
    {
185
        return $this->internalRemarks;
186
    }
187
188
    /**
189
     * Set expense claim
190
     *
191
     * @param null|ExpenseClaim $expenseClaim
192
     */
193 1
    public function setExpenseClaim(?ExpenseClaim $expenseClaim): void
194
    {
195 1
        if ($this->expenseClaim && $expenseClaim !== $this->expenseClaim) {
196 1
            $this->expenseClaim->transactionRemoved($this);
197
        }
198
199 1
        $this->expenseClaim = $expenseClaim;
200 1
        $this->expenseClaim && $this->expenseClaim->transactionAdded($this);
201 1
    }
202
203
    /**
204
     * Get expense claim
205
     *
206
     * @return null|ExpenseClaim
207
     */
208
    public function getExpenseClaim(): ?ExpenseClaim
209
    {
210
        return $this->expenseClaim;
211
    }
212
213
    /**
214
     * Set category
215
     *
216
     * @param null|Category $category
217
     */
218 1
    public function setCategory(?Category $category): void
219
    {
220 1
        if ($this->category && $category !== $this->category) {
221 1
            $this->category->transactionRemoved($this);
222
        }
223
224 1
        $this->category = $category;
225 1
        $this->category && $this->category->transactionAdded($this);
226 1
    }
227
228
    /**
229
     * Get category
230
     *
231
     * @return null|Category
232
     */
233 1
    public function getCategory(): ?Category
234
    {
235 1
        return $this->category;
236
    }
237
}
238