mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Various code cleanup.
This commit is contained in:
@@ -37,7 +37,6 @@ class CLIToken implements BinderInterface
|
||||
/**
|
||||
* @return mixed
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public static function routeBinder(string $value, Route $route)
|
||||
{
|
||||
|
@@ -62,7 +62,7 @@ class WholePeriodChartGenerator
|
||||
$currentEnd = app('navigation')->endOfPeriod($current, $step);
|
||||
$spent[$key] = $opsRepository->sumExpenses($current, $currentEnd, $accounts, $collection);
|
||||
$earned[$key] = $opsRepository->sumIncome($current, $currentEnd, $accounts, $collection);
|
||||
$current = app('navigation')->addPeriod($current, $step, 0);
|
||||
$current = app('navigation')->addPeriod($current, $step);
|
||||
}
|
||||
|
||||
$currencies = $this->extractCurrencies($spent) + $this->extractCurrencies($earned);
|
||||
@@ -104,7 +104,7 @@ class WholePeriodChartGenerator
|
||||
$chartData[$spentInfoKey]['entries'][$label] = app('steam')->bcround($spentAmount, $currency['currency_decimal_places']);
|
||||
$chartData[$earnedInfoKey]['entries'][$label] = app('steam')->bcround($earnedAmount, $currency['currency_decimal_places']);
|
||||
}
|
||||
$current = app('navigation')->addPeriod($current, $step, 0);
|
||||
$current = app('navigation')->addPeriod($current, $step);
|
||||
}
|
||||
|
||||
return $chartData;
|
||||
|
@@ -62,6 +62,8 @@ use Illuminate\Support\Facades\Log;
|
||||
use League\Csv\CannotInsertRecord;
|
||||
use League\Csv\Exception;
|
||||
use League\Csv\Writer;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
/**
|
||||
* Class ExportDataGenerator
|
||||
@@ -105,7 +107,12 @@ class ExportDataGenerator
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws CannotInsertRecord
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws Exception
|
||||
* @throws FireflyException
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function export(): array
|
||||
{
|
||||
@@ -747,9 +754,12 @@ class ExportDataGenerator
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws CannotInsertRecord
|
||||
* @throws Exception
|
||||
* @throws FireflyException
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
private function exportTags(): string
|
||||
{
|
||||
|
@@ -165,8 +165,6 @@ class CurrencyForm
|
||||
}
|
||||
|
||||
/**
|
||||
* @phpstan-param view-string $view
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
protected function currencyField(string $name, string $view, mixed $value = null, ?array $options = null): string
|
||||
|
@@ -243,7 +243,7 @@ class ExchangeRateConverter
|
||||
private function getRate(TransactionCurrency $from, TransactionCurrency $to, Carbon $date): string
|
||||
{
|
||||
$key = $this->getCacheKey($from, $to, $date);
|
||||
$res = Cache::get($key, null);
|
||||
$res = Cache::get($key);
|
||||
|
||||
// find in cache
|
||||
if (null !== $res) {
|
||||
|
@@ -219,7 +219,7 @@ trait AugumentData
|
||||
$entry->pc_spent = $spent;
|
||||
|
||||
// normal amount:
|
||||
$expenses = $opsRepository->sumExpenses($currentStart, $currentEnd, null, $budgetCollection, $entry->transactionCurrency, false);
|
||||
$expenses = $opsRepository->sumExpenses($currentStart, $currentEnd, null, $budgetCollection, $entry->transactionCurrency);
|
||||
$spent = $expenses[$entry->transactionCurrency->id]['sum'] ?? '0';
|
||||
$entry->spent = $spent;
|
||||
|
||||
|
@@ -118,7 +118,7 @@ trait GetConfigurationData
|
||||
$previousEnd = app('navigation')->endOfPeriod($previousStart, $viewRange);
|
||||
$ranges[$index] = [$previousStart, $previousEnd];
|
||||
|
||||
$nextDate = app('navigation')->addPeriod($start, $viewRange, 0);
|
||||
$nextDate = app('navigation')->addPeriod($start, $viewRange);
|
||||
$index = app('navigation')->periodShow($nextDate, $viewRange);
|
||||
$nextStart = app('navigation')->startOfPeriod($nextDate, $viewRange);
|
||||
$nextEnd = app('navigation')->endOfPeriod($nextStart, $viewRange);
|
||||
|
@@ -153,8 +153,8 @@ class AvailableBudgetEnrichment implements EnrichmentInterface
|
||||
$id = (int)$availableBudget->id;
|
||||
$currencyId = $this->currencyIds[$id];
|
||||
$currency = $this->currencies[$currencyId];
|
||||
$filteredSpentInBudgets = $this->opsRepository->sumCollectedExpenses($spentInBudgets, $availableBudget->start_date, $availableBudget->end_date, $currency, false);
|
||||
$filteredSpentOutsideBudgets = $this->opsRepository->sumCollectedExpenses($spentOutsideBudgets, $availableBudget->start_date, $availableBudget->end_date, $currency, false);
|
||||
$filteredSpentInBudgets = $this->opsRepository->sumCollectedExpenses($spentInBudgets, $availableBudget->start_date, $availableBudget->end_date, $currency);
|
||||
$filteredSpentOutsideBudgets = $this->opsRepository->sumCollectedExpenses($spentOutsideBudgets, $availableBudget->start_date, $availableBudget->end_date, $currency);
|
||||
$this->spentInBudgets[$id] = array_values($filteredSpentInBudgets);
|
||||
$this->spentOutsideBudgets[$id] = array_values($filteredSpentOutsideBudgets);
|
||||
|
||||
|
@@ -156,10 +156,10 @@ class BudgetEnrichment implements EnrichmentInterface
|
||||
$opsRepository->setUserGroup($this->userGroup);
|
||||
// $spent = $this->beautify();
|
||||
// $set = $this->opsRepository->sumExpenses($start, $end, null, new Collection()->push($budget))
|
||||
$expenses = $opsRepository->collectExpenses($this->start, $this->end, null, $this->collection, null);
|
||||
$expenses = $opsRepository->collectExpenses($this->start, $this->end, null, $this->collection);
|
||||
foreach ($this->collection as $item) {
|
||||
$id = (int)$item->id;
|
||||
$this->spent[$id] = array_values($opsRepository->sumCollectedExpensesByBudget($expenses, $item, false));
|
||||
$this->spent[$id] = array_values($opsRepository->sumCollectedExpensesByBudget($expenses, $item));
|
||||
$this->pcSpent[$id] = array_values($opsRepository->sumCollectedExpensesByBudget($expenses, $item, true));
|
||||
}
|
||||
}
|
||||
|
@@ -41,7 +41,7 @@ use Illuminate\Support\Facades\Log;
|
||||
class BudgetLimitEnrichment implements EnrichmentInterface
|
||||
{
|
||||
private Collection $collection;
|
||||
private bool $convertToPrimary = true; // @phpstan-ignore-line
|
||||
private bool $convertToPrimary; // @phpstan-ignore-line
|
||||
private array $currencies = [];
|
||||
private array $currencyIds = [];
|
||||
private Carbon $end;
|
||||
@@ -120,14 +120,14 @@ class BudgetLimitEnrichment implements EnrichmentInterface
|
||||
|
||||
$repository = app(OperationsRepository::class);
|
||||
$repository->setUser($this->user);
|
||||
$expenses = $repository->collectExpenses($this->start, $this->end, null, $budgets, null);
|
||||
$expenses = $repository->collectExpenses($this->start, $this->end, null, $budgets);
|
||||
|
||||
/** @var BudgetLimit $budgetLimit */
|
||||
foreach ($this->collection as $budgetLimit) {
|
||||
Log::debug(sprintf('Filtering expenses for budget limit #%d (budget #%d)', $budgetLimit->id, $budgetLimit->budget_id));
|
||||
$id = (int)$budgetLimit->id;
|
||||
$filteredExpenses = $this->filterToBudget($expenses, $budgetLimit->budget_id);
|
||||
$filteredExpenses = $repository->sumCollectedExpenses($filteredExpenses, $budgetLimit->start_date, $budgetLimit->end_date, $budgetLimit->transactionCurrency, false);
|
||||
$filteredExpenses = $repository->sumCollectedExpenses($filteredExpenses, $budgetLimit->start_date, $budgetLimit->end_date, $budgetLimit->transactionCurrency);
|
||||
$this->expenses[$id] = array_values($filteredExpenses);
|
||||
|
||||
if (true === $this->convertToPrimary && $budgetLimit->transactionCurrency->id !== $this->primaryCurrency->id) {
|
||||
|
@@ -145,11 +145,11 @@ class CategoryEnrichment implements EnrichmentInterface
|
||||
$transfers = $opsRepository->collectTransfers($this->start, $this->end, null, $this->collection);
|
||||
foreach ($this->collection as $item) {
|
||||
$id = (int)$item->id;
|
||||
$this->spent[$id] = array_values($opsRepository->sumCollectedTransactionsByCategory($expenses, $item, 'negative', false));
|
||||
$this->spent[$id] = array_values($opsRepository->sumCollectedTransactionsByCategory($expenses, $item, 'negative'));
|
||||
$this->pcSpent[$id] = array_values($opsRepository->sumCollectedTransactionsByCategory($expenses, $item, 'negative', true));
|
||||
$this->earned[$id] = array_values($opsRepository->sumCollectedTransactionsByCategory($income, $item, 'positive', false));
|
||||
$this->earned[$id] = array_values($opsRepository->sumCollectedTransactionsByCategory($income, $item, 'positive'));
|
||||
$this->pcEarned[$id] = array_values($opsRepository->sumCollectedTransactionsByCategory($income, $item, 'positive', true));
|
||||
$this->transfers[$id] = array_values($opsRepository->sumCollectedTransactionsByCategory($transfers, $item, 'positive', false));
|
||||
$this->transfers[$id] = array_values($opsRepository->sumCollectedTransactionsByCategory($transfers, $item, 'positive'));
|
||||
$this->pcTransfers[$id] = array_values($opsRepository->sumCollectedTransactionsByCategory($transfers, $item, 'positive', true));
|
||||
}
|
||||
}
|
||||
|
@@ -159,7 +159,9 @@ class PiggyBankEnrichment implements EnrichmentInterface
|
||||
|
||||
// get suggested per month.
|
||||
$meta['save_per_month'] = Steam::bcround($this->getSuggestedMonthlyAmount($this->date, $item->target_date, $meta['target_amount'], $meta['current_amount']), $currency->decimal_places);
|
||||
$meta['pc_save_per_month'] = Steam::bcround($this->getSuggestedMonthlyAmount($this->date, $item->target_date, $meta['pc_target_amount'], $meta['pc_current_amount']), $currency->decimal_places);
|
||||
if(null !== $meta['pc_current_amount']) {
|
||||
$meta['pc_save_per_month'] = Steam::bcround($this->getSuggestedMonthlyAmount($this->date, $item->target_date, $meta['pc_target_amount'], $meta['pc_current_amount']), $currency->decimal_places);
|
||||
}
|
||||
|
||||
$item->meta = $meta;
|
||||
|
||||
|
@@ -60,8 +60,8 @@ class RecurringEnrichment implements EnrichmentInterface
|
||||
private Collection $collection;
|
||||
// private array $transactionTypeIds = [];
|
||||
// private array $transactionTypes = [];
|
||||
private bool $convertToPrimary = false;
|
||||
private array $currencies = [];
|
||||
private bool $convertToPrimary;
|
||||
private array $currencies = [];
|
||||
private array $currencyIds = [];
|
||||
private array $destinationAccountIds = [];
|
||||
private array $foreignCurrencyIds = [];
|
||||
|
@@ -98,7 +98,7 @@ class BillDateCalculator
|
||||
$diffEOM = $daysUntilEOM - $nextUntilEOM;
|
||||
if ($diffEOM > 0) {
|
||||
Log::debug(sprintf('Bill start is %d days from the end of the month. nextExceptedMatch is %d days from the end of the month.', $daysUntilEOM, $nextUntilEOM));
|
||||
$nextExpectedMatch->subDays(1);
|
||||
$nextExpectedMatch->subDays();
|
||||
Log::debug(sprintf('Subtract %d days from next expected match, which is now %s', $diffEOM, $nextExpectedMatch->format('Y-m-d')));
|
||||
}
|
||||
}
|
||||
|
@@ -227,7 +227,7 @@ trait RecalculatesAvailableBudgetsTrait
|
||||
}
|
||||
|
||||
// prep for next loop
|
||||
$current = app('navigation')->addPeriod($current, $viewRange, 0);
|
||||
$current = app('navigation')->addPeriod($current, $viewRange);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -30,6 +30,7 @@ use Carbon\Exceptions\InvalidFormatException;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
use Safe\Exceptions\PcreException;
|
||||
use function Safe\preg_match;
|
||||
|
||||
/**
|
||||
@@ -72,8 +73,11 @@ class ParseDateString
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
* @param string $date
|
||||
*
|
||||
* @return Carbon
|
||||
* @throws FireflyException
|
||||
* @throws PcreException
|
||||
* @SuppressWarnings("PHPMD.NPathComplexity")
|
||||
*/
|
||||
public function parseDate(string $date): Carbon
|
||||
|
@@ -231,7 +231,6 @@ class Preferences
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function lastActivity(): string
|
||||
{
|
||||
|
@@ -133,7 +133,6 @@ class BudgetReportGenerator
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
|
@@ -80,7 +80,7 @@ trait CalculateXOccurrencesSince
|
||||
while ($total < $count) {
|
||||
$domCorrected = min($dayOfMonth, $mutator->daysInMonth);
|
||||
$mutator->day = $domCorrected;
|
||||
$mutator->setTime(0, 0, 0);
|
||||
$mutator->setTime(0, 0);
|
||||
if (0 === $attempts % $skipMod && $mutator->gte($afterDate)) {
|
||||
Log::debug(sprintf('Mutator is now %s and is added to the list.', $mutator->toAtomString()));
|
||||
$return[] = clone $mutator;
|
||||
|
@@ -370,7 +370,6 @@ class OperatorQuerySearch implements SearchInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function parseDateRange(string $type, string $value): array
|
||||
{
|
||||
|
@@ -31,6 +31,7 @@ use Gdbots\QueryParser\Node as GdbotsNode;
|
||||
use Gdbots\QueryParser\QueryParser as BaseQueryParser;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use LogicException;
|
||||
use Safe\Exceptions\FilesystemException;
|
||||
use TypeError;
|
||||
|
||||
use function Safe\fwrite;
|
||||
@@ -45,7 +46,11 @@ class GdbotsQueryParser implements QueryParserInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
*
|
||||
* @return NodeGroup
|
||||
* @throws FireflyException
|
||||
* @throws FilesystemException
|
||||
*/
|
||||
public function parse(string $query): NodeGroup
|
||||
{
|
||||
|
@@ -37,6 +37,8 @@ use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Str;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use ValueError;
|
||||
|
||||
use function Safe\parse_url;
|
||||
@@ -534,7 +536,6 @@ class Steam
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function getHostName(string $ipAddress): string
|
||||
{
|
||||
@@ -557,7 +558,10 @@ class Steam
|
||||
/**
|
||||
* Get user's language.
|
||||
*
|
||||
* @return string
|
||||
* @throws FireflyException
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function getLanguage(): string // get preference
|
||||
{
|
||||
|
@@ -32,6 +32,7 @@ use Laravel\Passport\Console\KeysCommand;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
use Safe\Exceptions\FilesystemException;
|
||||
use function Safe\file_get_contents;
|
||||
use function Safe\file_put_contents;
|
||||
|
||||
@@ -79,7 +80,11 @@ class OAuthKeys
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws FireflyException
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws FilesystemException
|
||||
*/
|
||||
public static function restoreKeysFromDB(): bool
|
||||
{
|
||||
|
Reference in New Issue
Block a user