1 | <?php |
||
2 | /** |
||
3 | * BudgetLimitTransformer.php |
||
4 | * Copyright (c) 2019 [email protected] |
||
5 | * |
||
6 | * This file is part of Firefly III (https://github.com/firefly-iii). |
||
7 | * |
||
8 | * This program is free software: you can redistribute it and/or modify |
||
9 | * it under the terms of the GNU Affero General Public License as |
||
10 | * published by the Free Software Foundation, either version 3 of the |
||
11 | * License, or (at your option) any later version. |
||
12 | * |
||
13 | * This program is distributed in the hope that it will be useful, |
||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
16 | * GNU Affero General Public License for more details. |
||
17 | * |
||
18 | * You should have received a copy of the GNU Affero General Public License |
||
19 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
||
20 | */ |
||
21 | |||
22 | declare(strict_types=1); |
||
23 | |||
24 | namespace FireflyIII\Transformers; |
||
25 | |||
26 | use FireflyIII\Models\BudgetLimit; |
||
27 | use Log; |
||
28 | |||
29 | /** |
||
30 | * Class BudgetLimitTransformer |
||
31 | */ |
||
32 | class BudgetLimitTransformer extends AbstractTransformer |
||
33 | { |
||
34 | /** |
||
35 | * CurrencyTransformer constructor. |
||
36 | * |
||
37 | * @codeCoverageIgnore |
||
38 | */ |
||
39 | public function __construct() |
||
40 | { |
||
41 | if ('testing' === config('app.env')) { |
||
42 | Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this))); |
||
43 | } |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * Transform the note. |
||
48 | * |
||
49 | * @param BudgetLimit $budgetLimit |
||
50 | * |
||
51 | * @return array |
||
52 | */ |
||
53 | public function transform(BudgetLimit $budgetLimit): array |
||
54 | { |
||
55 | $currency = $budgetLimit->transactionCurrency; |
||
56 | $amount = $budgetLimit->amount; |
||
57 | $currencyId = null; |
||
58 | $currencyName = null; |
||
59 | $currencyCode = null; |
||
60 | $currencySymbol = null; |
||
61 | if (null !== $currency) { |
||
62 | $amount = round($budgetLimit->amount, $budgetLimit->transactionCurrency->decimal_places); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
63 | $currencyId = $currency->id; |
||
64 | $currencyName = $currency->name; |
||
65 | $currencyCode = $currency->code; |
||
66 | $currencySymbol = $currency->symbol; |
||
67 | } |
||
68 | $data = [ |
||
69 | 'id' => (int)$budgetLimit->id, |
||
70 | 'created_at' => $budgetLimit->created_at->toAtomString(), |
||
71 | 'updated_at' => $budgetLimit->updated_at->toAtomString(), |
||
72 | 'start' => $budgetLimit->start_date->format('Y-m-d'), |
||
73 | 'end' => $budgetLimit->end_date->format('Y-m-d'), |
||
74 | 'budget_id' => $budgetLimit->budget_id, |
||
75 | 'currency_id' => $currencyId, |
||
76 | 'currency_code' => $currencyCode, |
||
77 | 'currency_name' => $currencyName, |
||
78 | 'currency_symbol' => $currencySymbol, |
||
79 | 'amount' => $amount, |
||
80 | 'links' => [ |
||
81 | [ |
||
82 | 'rel' => 'self', |
||
83 | 'uri' => '/budgets/limits/' . $budgetLimit->id, |
||
84 | ], |
||
85 | ], |
||
86 | ]; |
||
87 | |||
88 | return $data; |
||
89 | } |
||
90 | } |
||
91 |