1 | <?php |
||
14 | class ExpensesService |
||
15 | { |
||
16 | /** @var float $vatRate */ |
||
17 | private $vatRate; |
||
18 | |||
19 | /** @var EntryRepository $repository */ |
||
20 | protected $repository; |
||
21 | |||
22 | 6 | public function __construct(EntryRepository $repository, $vatRate = 20) |
|
27 | |||
28 | /** |
||
29 | * @return EntryRepository |
||
30 | */ |
||
31 | 3 | private function getRepository() |
|
35 | |||
36 | /** |
||
37 | * @param array $data |
||
38 | * @param EntryInterface $entry |
||
39 | * @return EntryInterface |
||
40 | */ |
||
41 | 6 | private function setFromArray(array $data, EntryInterface $entry) |
|
42 | { |
||
43 | 6 | if(!$data['date'] instanceof DateTime) { |
|
44 | 2 | $data['date'] = new DateTime($data['date']); |
|
45 | } |
||
46 | 6 | isset($data['id']) ? $entry->setId($data['id']) : null; |
|
47 | 6 | $entry->setUserId($data['userId']) |
|
48 | 6 | ->setCategory(new Category($data['category'])) |
|
49 | 6 | ->setVatRate($data['vatRate']) |
|
50 | 6 | ->setAmount($data['amount'], $data['vat']) |
|
51 | 6 | ->setDate($data['date']) |
|
52 | 6 | ->setDescription($data['description']) |
|
53 | 6 | ->setNote($data['note']); |
|
54 | 6 | return $entry; |
|
55 | } |
||
56 | |||
57 | /** |
||
58 | * @return Expenditure |
||
59 | */ |
||
60 | 4 | public function createExpenditureFromArray(array $data) |
|
67 | |||
68 | /** |
||
69 | * @return Income |
||
70 | */ |
||
71 | 3 | public function createIncomeFromArray(array $data) |
|
78 | |||
79 | /** |
||
80 | * Pass an Income, Expenditure, or Expense Claim |
||
81 | * @return array |
||
82 | */ |
||
83 | 1 | public function toArray(EntryInterface $entry) |
|
84 | { |
||
85 | return [ |
||
86 | 1 | 'id' => $entry->getId(), |
|
87 | 1 | 'userId' => $entry->getUserId(), |
|
88 | 1 | 'date' => $entry->getDate(), |
|
89 | 1 | 'amount' => $entry->getAmount(), |
|
90 | 1 | 'vatRate' => $entry->getVatRate(), |
|
91 | 1 | 'vat' => $entry->getVat(), |
|
92 | 1 | 'total' => $entry->getTotal(), |
|
93 | 1 | 'description' => $entry->getDescription(), |
|
94 | 1 | 'category' => $entry->getCategory()->getValue(), |
|
95 | 1 | 'note' => $entry->getNote(), |
|
96 | ]; |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * @param Income $income |
||
101 | * @return Income |
||
102 | */ |
||
103 | 2 | public function saveIncome(Income $income) |
|
107 | |||
108 | /** |
||
109 | * @param Income $income |
||
110 | */ |
||
111 | 2 | public function deleteIncome(Income $income) |
|
115 | |||
116 | /** |
||
117 | * @param $id |
||
118 | * @return Income |
||
119 | */ |
||
120 | 1 | public function findIncomeById($id) |
|
126 | |||
127 | /** |
||
128 | * @param Expenditure $expenditure |
||
129 | * @return Expenditure |
||
130 | */ |
||
131 | 2 | public function saveExpenditure(Expenditure $expenditure) |
|
135 | |||
136 | /** |
||
137 | * @param Expenditure $expenditure |
||
138 | */ |
||
139 | 2 | public function deleteExpenditure(Expenditure $expenditure) |
|
143 | |||
144 | /** |
||
145 | * @param $id |
||
146 | * @return Expenditure |
||
147 | */ |
||
148 | 1 | public function findExpenditureById($id) |
|
154 | |||
155 | /** |
||
156 | * @param EntryCriteria $criteria |
||
157 | * @return array |
||
158 | */ |
||
159 | 1 | public function findByCriteria(EntryCriteria $criteria) |
|
163 | |||
164 | /** |
||
165 | * @param EntryInterface $entry |
||
166 | */ |
||
167 | 3 | public function deleteEntry(EntryInterface $entry) |
|
171 | |||
172 | /** |
||
173 | * @return float |
||
174 | */ |
||
175 | public function getVatRate() |
||
179 | |||
180 | /** |
||
181 | * @param float $vatRate |
||
182 | * @return ExpensesService |
||
183 | */ |
||
184 | public function setVatRate($vatRate) |
||
189 | } |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.