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 | 2 | } |
|
46 | 6 | $entry->setId($data['userId']) |
|
47 | 6 | ->setUserId($data['userId']) |
|
48 | 6 | ->setCategory(new Category($data['category'])) |
|
49 | 6 | ->setAmount($data['amount']) |
|
50 | 6 | ->setDate($data['date']) |
|
51 | 6 | ->setDescription($data['description']) |
|
52 | 6 | ->setNote($data['note']); |
|
53 | 6 | return $entry; |
|
54 | } |
||
55 | |||
56 | /** |
||
57 | * @return Expenditure |
||
58 | */ |
||
59 | 4 | public function createExpenditureFromArray(array $data) |
|
66 | |||
67 | /** |
||
68 | * @return Income |
||
69 | */ |
||
70 | 3 | public function createIncomeFromArray(array $data) |
|
77 | |||
78 | /** |
||
79 | * Pass an Income, Expenditure, or Expense Claim |
||
80 | * @return array |
||
81 | */ |
||
82 | 1 | public function toArray(EntryInterface $entry) |
|
97 | |||
98 | /** |
||
99 | * @param Income $income |
||
100 | * @return Income |
||
101 | */ |
||
102 | 2 | public function saveIncome(Income $income) |
|
106 | |||
107 | /** |
||
108 | * @param Income $income |
||
109 | */ |
||
110 | 2 | public function deleteIncome(Income $income) |
|
114 | |||
115 | /** |
||
116 | * @param $id |
||
117 | * @return Income |
||
118 | */ |
||
119 | 1 | public function findIncomeById($id) |
|
125 | |||
126 | /** |
||
127 | * @param Expenditure $expenditure |
||
128 | * @return Expenditure |
||
129 | */ |
||
130 | 2 | public function saveExpenditure(Expenditure $expenditure) |
|
134 | |||
135 | /** |
||
136 | * @param Expenditure $expenditure |
||
137 | */ |
||
138 | 2 | public function deleteExpenditure(Expenditure $expenditure) |
|
142 | |||
143 | /** |
||
144 | * @param $id |
||
145 | * @return Expenditure |
||
146 | */ |
||
147 | 1 | public function findExpenditureById($id) |
|
153 | |||
154 | /** |
||
155 | * @param EntryCriteria $criteria |
||
156 | * @return array |
||
157 | */ |
||
158 | 1 | public function findByCriteria(EntryCriteria $criteria) |
|
162 | |||
163 | /** |
||
164 | * @param EntryInterface $entry |
||
165 | */ |
||
166 | 3 | public function deleteEntry(EntryInterface $entry) |
|
170 | |||
171 | /** |
||
172 | * @return float |
||
173 | */ |
||
174 | public function getVatRate() |
||
178 | |||
179 | /** |
||
180 | * @param float $vatRate |
||
181 | * @return ExpensesService |
||
182 | */ |
||
183 | public function setVatRate($vatRate) |
||
188 | } |
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.