Failed Conditions
Push — master ( 472bc6...94471a )
by Sylvain
10:19
created

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