Various code cleanup.

This commit is contained in:
James Cole
2025-10-05 12:57:58 +02:00
parent 072212c112
commit 6341743cf9
169 changed files with 482 additions and 305 deletions

View File

@@ -37,7 +37,6 @@ class CLIToken implements BinderInterface
/**
* @return mixed
*
* @throws FireflyException
*/
public static function routeBinder(string $value, Route $route)
{

View File

@@ -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;

View File

@@ -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
{

View File

@@ -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

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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);

View File

@@ -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);

View File

@@ -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));
}
}

View File

@@ -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) {

View File

@@ -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));
}
}

View File

@@ -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;

View File

@@ -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 = [];

View File

@@ -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')));
}
}

View File

@@ -227,7 +227,7 @@ trait RecalculatesAvailableBudgetsTrait
}
// prep for next loop
$current = app('navigation')->addPeriod($current, $viewRange, 0);
$current = app('navigation')->addPeriod($current, $viewRange);
}
}
}

View File

@@ -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

View File

@@ -231,7 +231,6 @@ class Preferences
}
/**
* @throws FireflyException
*/
public function lastActivity(): string
{

View File

@@ -133,7 +133,6 @@ class BudgetReportGenerator
}
/**
* @throws FireflyException
*/
public function setUser(User $user): void
{

View File

@@ -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;

View File

@@ -370,7 +370,6 @@ class OperatorQuerySearch implements SearchInterface
}
/**
* @throws FireflyException
*/
private function parseDateRange(string $type, string $value): array
{

View File

@@ -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
{

View File

@@ -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
{

View File

@@ -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
{