mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Refactor old methods.
This commit is contained in:
@@ -37,7 +37,7 @@ abstract class AbstractTransformer extends TransformerAbstract
|
||||
/**
|
||||
* @return ParameterBag
|
||||
*/
|
||||
public function getParameters(): ParameterBag
|
||||
final public function getParameters(): ParameterBag
|
||||
{
|
||||
return $this->parameters;
|
||||
}
|
||||
@@ -45,7 +45,7 @@ abstract class AbstractTransformer extends TransformerAbstract
|
||||
/**
|
||||
* @param ParameterBag $parameters
|
||||
*/
|
||||
public function setParameters(ParameterBag $parameters): void
|
||||
final public function setParameters(ParameterBag $parameters): void
|
||||
{
|
||||
$this->parameters = $parameters;
|
||||
}
|
||||
|
@@ -206,8 +206,6 @@ class AccountTransformer extends AbstractTransformer
|
||||
* @param Account $account
|
||||
* @param string $accountType
|
||||
*
|
||||
* @param int $decimalPlaces
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* TODO refactor call to getOpeningBalanceAmount / Date because its extra queries.
|
||||
|
@@ -22,11 +22,11 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Transformers;
|
||||
|
||||
use FireflyIII\Models\AvailableBudget;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\NoBudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Class AvailableBudgetTransformer
|
||||
@@ -97,11 +97,9 @@ class AvailableBudgetTransformer extends AbstractTransformer
|
||||
private function getSpentInBudgets(): array
|
||||
{
|
||||
$allActive = $this->repository->getActiveBudgets();
|
||||
$sums = $this->opsRepository->sumExpenses($this->parameters->get('start'), $this->parameters->get('end'), null, $allActive);
|
||||
|
||||
return $this->opsRepository->spentInPeriodMc(
|
||||
$allActive, new Collection, $this->parameters->get('start'), $this->parameters->get('end')
|
||||
);
|
||||
|
||||
return array_values($sums);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,7 +107,8 @@ class AvailableBudgetTransformer extends AbstractTransformer
|
||||
*/
|
||||
private function spentOutsideBudgets(): array
|
||||
{
|
||||
return $this->noBudgetRepository->spentInPeriodWoBudgetMc(new Collection, $this->parameters->get('start'), $this->parameters->get('end'));
|
||||
}
|
||||
$sums = $this->noBudgetRepository->sumExpenses($this->parameters->get('start'), $this->parameters->get('end'));
|
||||
|
||||
return array_values($sums);
|
||||
}
|
||||
}
|
||||
|
@@ -212,7 +212,7 @@ class BillTransformer extends AbstractTransformer
|
||||
return $default; // @codeCoverageIgnore
|
||||
}
|
||||
$latest = $dates->first()->date;
|
||||
/** @var TransactionJournal $date */
|
||||
/** @var TransactionJournal $journal */
|
||||
foreach ($dates as $journal) {
|
||||
if ($journal->date->gte($latest)) {
|
||||
$latest = $journal->date;
|
||||
|
@@ -1,67 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* CurrencyExchangeRateTransformer.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Transformers;
|
||||
use FireflyIII\Models\CurrencyExchangeRate;
|
||||
|
||||
/**
|
||||
* Class CurrencyExchangeRateTransformer
|
||||
*/
|
||||
class CurrencyExchangeRateTransformer extends AbstractTransformer
|
||||
{
|
||||
/**
|
||||
* @param CurrencyExchangeRate $rate
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function transform(CurrencyExchangeRate $rate): array
|
||||
{
|
||||
$result = number_format((float)$rate->rate * (float)$this->parameters->get('amount'), $rate->toCurrency->decimal_places, '.', '');
|
||||
$result = 0.0 === $result ? null : $result;
|
||||
|
||||
return [
|
||||
'id' => (int)$rate->id,
|
||||
'created_at' => $rate->created_at->toAtomString(),
|
||||
'updated_at' => $rate->updated_at->toAtomString(),
|
||||
'from_currency_id' => (int)$rate->fromCurrency->id,
|
||||
'from_currency_name' => $rate->fromCurrency->name,
|
||||
'from_currency_code' => $rate->fromCurrency->code,
|
||||
'from_currency_symbol' => $rate->fromCurrency->symbol,
|
||||
'from_currency_decimal_places' => (int)$rate->fromCurrency->decimal_places,
|
||||
'to_currency_id' => (int)$rate->toCurrency->id,
|
||||
'to_currency_name' => $rate->toCurrency->name,
|
||||
'to_currency_code' => $rate->toCurrency->code,
|
||||
'to_currency_symbol' => $rate->toCurrency->symbol,
|
||||
'to_currency_decimal_places' => (int)$rate->toCurrency->decimal_places,
|
||||
'date' => $rate->date->format('Y-m-d'),
|
||||
'rate' => (float)$rate->rate,
|
||||
'amount' => $result,
|
||||
'links' => [
|
||||
[
|
||||
'rel' => 'self',
|
||||
'uri' => '/currency_exchange_rates/' . $rate->id,
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
@@ -276,7 +276,6 @@ class RecurrenceTransformer extends AbstractTransformer
|
||||
$array['category_name'] = $category->name;
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case 'category_name':
|
||||
$category = $this->factory->findOrCreate(null, $transactionMeta->value);
|
||||
if (null !== $category) {
|
||||
|
@@ -304,7 +304,7 @@ class TransactionGroupTransformer extends AbstractTransformer
|
||||
} catch (FireflyException $e) {
|
||||
Log::error($e->getMessage());
|
||||
Log::error($e->getTraceAsString());
|
||||
throw new FireflyException(sprintf('Transaction group #%d is broken. Please check out your log files.', $group->id));
|
||||
throw new FireflyException(sprintf('Transaction group #%d is broken. Please check out your log files.', $group->id), 0, $e);
|
||||
}
|
||||
|
||||
// do something else.
|
||||
|
Reference in New Issue
Block a user