Completed
Push — master ( 0a0c4a...11fa4c )
by Adrien
11:33
created

ExpenseClaim::setUser()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 1
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 3
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A ExpenseClaim::getAmount() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Model;
6
7
use Application\DBAL\Types\ExpenseClaimStatusType;
8
use Application\Traits\HasDescription;
9
use Application\Traits\HasName;
10
use Application\Traits\HasRemarks;
11
use Doctrine\Common\Collections\ArrayCollection;
12
use Doctrine\Common\Collections\Collection;
13
use Doctrine\ORM\Mapping as ORM;
14
use GraphQL\Doctrine\Annotation as API;
15
16
/**
17
 * An expense claim to be refunded to an user
18
 *
19
 * @ORM\Entity(repositoryClass="Application\Repository\ExpenseClaimRepository")
20
 * @ORM\AssociationOverrides({
21
 *     @ORM\AssociationOverride(name="owner",
22
 *         joinColumns=@ORM\JoinColumn(nullable=false)
23
 *     )
24
 * })
25
 */
26
class ExpenseClaim extends AbstractModel
27
{
28
    use hasName;
29
    use hasDescription;
30
    use hasRemarks;
31
32
    /**
33
     * @var float
34
     *
35
     * @ORM\Column(type="decimal", precision=7, scale=2)
36
     */
37
    private $amount;
38
39
    /**
40
     * @var Collection
41
     * @ORM\OneToMany(targetEntity="Transaction", mappedBy="expenseClaim")
42
     */
43
    private $transactions;
44
45
    /**
46
     * @var Collection
47
     * @ORM\OneToMany(targetEntity="AccountingDocument", mappedBy="expenseClaim")
48
     */
49
    private $accountingDocuments;
50
51
    /**
52
     * @var string
53
     *
54
     * @ORM\Column(type="ExpenseClaimStatus", length=10, options={"default" = ExpenseClaimStatusType::NEW})
55
     */
56
    private $status = ExpenseClaimStatusType::NEW;
57
58
    /**
59
     * Constructor
60
     */
61
    public function __construct()
62
    {
63
        $this->transactions = new ArrayCollection();
64
        $this->accountingDocuments = new ArrayCollection();
65
    }
66 3
67
    /**
68 3
     * Set amount
69 3
     *
70 3
     * @param float $amount
71
     */
72
    public function setAmount(float $amount): void
73
    {
74
        $this->amount = $amount;
75
    }
76
77 1
    /**
78
     * Get amount
79 1
     *
80 1
     * @return float
81
     */
82
    public function getAmount(): float
83 1
    {
84 1
        return (float) $this->amount;
85 1
    }
86
87
    /**
88
     * Set status
89
     *
90
     * @API\Input(type="ExpenseClaimStatus")
91
     *
92
     * @param string $status
93
     */
94
    public function setStatus(string $status): void
95
    {
96
        $this->status = $status;
97
    }
98
99
    /**
100
     * Get status
101
     *
102
     * @API\Field(type="ExpenseClaimStatus")
103
     *
104
     * @return string
105
     */
106
    public function getStatus(): string
107
    {
108
        return $this->status;
109
    }
110
111
    /**
112
     * Notify the expense claim that a transaction was added
113
     * This should only be called by Transaction::setExpenseClaim()
114
     *
115
     * @param Transaction $transaction
116
     */
117
    public function transactionAdded(Transaction $transaction): void
118
    {
119
        $this->transactions->add($transaction);
120
    }
121
122
    /**
123
     * Notify the expense claim that a transaction was removed
124
     * This should only be called by Transaction::setExpenseClaim()
125
     *
126
     * @param Transaction $transaction
127
     */
128
    public function transactionRemoved(Transaction $transaction): void
129
    {
130
        $this->transactions->removeElement($transaction);
131
    }
132
133
    /**
134
     * Get the transactions created from this expense claim
135
     *
136
     * @return Collection
137
     */
138
    public function getTransactions(): Collection
139
    {
140
        return $this->transactions;
141
    }
142
143
    /**
144
     * Notify the expense that an accounting document was added
145
     * This should only be called by AccountingDocument::setExpenseClaim()
146
     *
147 1
     * @param AccountingDocument $document
148
     */
149 1
    public function accountingDocumentAdded(AccountingDocument $document): void
150 1
    {
151
        $this->accountingDocuments->add($document);
152
    }
153
154
    /**
155
     * Notify the expense that an accounting document was removed
156
     * This should only be called by AccountingDocument::setExpenseClaim()
157
     *
158 1
     * @param AccountingDocument $document
159
     */
160 1
    public function accountingDocumentRemoved(AccountingDocument $document): void
161 1
    {
162
        $this->accountingDocuments->removeElement($document);
163
    }
164
165
    /**
166
     * Get accounting documents
167
     *
168 1
     * @return Collection
169
     */
170 1
    public function getAccountingDocuments(): Collection
171
    {
172
        return $this->accountingDocuments;
173
    }
174
}
175