Various PSR12 code cleanup

This commit is contained in:
James Cole
2022-12-29 19:42:26 +01:00
parent dbf3e76ecc
commit 6cfdc58cb1
415 changed files with 7462 additions and 6874 deletions

View File

@@ -1,4 +1,5 @@
<?php
/*
* BudgetReportGenerator.php
* Copyright (c) 2020 james@firefly-iii.org
@@ -23,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Report\Budget;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account;
use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit;
@@ -33,6 +35,7 @@ use FireflyIII\Repositories\Budget\NoBudgetRepositoryInterface;
use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
use FireflyIII\User;
use Illuminate\Support\Collection;
use JsonException;
/**
* Class BudgetReportGenerator
@@ -75,11 +78,11 @@ class BudgetReportGenerator
foreach ($this->accounts as $account) {
$accountId = $account->id;
$this->report[$accountId] = $this->report[$accountId] ?? [
'name' => $account->name,
'id' => $account->id,
'iban' => $account->iban,
'currencies' => [],
];
'name' => $account->name,
'id' => $account->id,
'iban' => $account->iban,
'currencies' => [],
];
}
// loop expenses.
@@ -91,7 +94,7 @@ class BudgetReportGenerator
/**
* Process each row of expenses collected for the "Account per budget" partial
*
* @param array $expenses
* @param array $expenses
*/
private function processExpenses(array $expenses): void
{
@@ -103,24 +106,24 @@ class BudgetReportGenerator
/**
* Process each set of transactions for each row of expenses.
*
* @param array $expenses
* @param array $budget
* @param array $expenses
* @param array $budget
*/
private function processBudgetExpenses(array $expenses, array $budget): void
{
$budgetId = (int) $budget['id'];
$currencyId = (int) $expenses['currency_id'];
$budgetId = (int)$budget['id'];
$currencyId = (int)$expenses['currency_id'];
foreach ($budget['transaction_journals'] as $journal) {
$sourceAccountId = $journal['source_account_id'];
$this->report[$sourceAccountId]['currencies'][$currencyId]
= $this->report[$sourceAccountId]['currencies'][$currencyId] ?? [
'currency_id' => $expenses['currency_id'],
'currency_symbol' => $expenses['currency_symbol'],
'currency_name' => $expenses['currency_name'],
'currency_decimal_places' => $expenses['currency_decimal_places'],
'budgets' => [],
];
'currency_id' => $expenses['currency_id'],
'currency_symbol' => $expenses['currency_symbol'],
'currency_name' => $expenses['currency_name'],
'currency_decimal_places' => $expenses['currency_decimal_places'],
'budgets' => [],
];
$this->report[$sourceAccountId]['currencies'][$currencyId]['budgets'][$budgetId]
= $this->report[$sourceAccountId]['currencies'][$currencyId]['budgets'][$budgetId] ?? '0';
@@ -161,17 +164,17 @@ class BudgetReportGenerator
/**
* Process expenses etc. for a single budget for the budgets block on the default report.
*
* @param Budget $budget
* @param Budget $budget
*/
private function processBudget(Budget $budget): void
{
$budgetId = (int) $budget->id;
$budgetId = (int)$budget->id;
$this->report['budgets'][$budgetId] = $this->report['budgets'][$budgetId] ?? [
'budget_id' => $budgetId,
'budget_name' => $budget->name,
'no_budget' => false,
'budget_limits' => [],
];
'budget_id' => $budgetId,
'budget_name' => $budget->name,
'no_budget' => false,
'budget_limits' => [],
];
// get all budget limits for budget in period:
$limits = $this->blRepository->getBudgetLimits($budget, $this->start, $this->end);
@@ -184,50 +187,50 @@ class BudgetReportGenerator
/**
* Process a single budget limit for the budgets block on the default report.
*
* @param Budget $budget
* @param BudgetLimit $limit
* @param Budget $budget
* @param BudgetLimit $limit
*/
private function processLimit(Budget $budget, BudgetLimit $limit): void
{
$budgetId = (int) $budget->id;
$limitId = (int) $limit->id;
$budgetId = (int)$budget->id;
$limitId = (int)$limit->id;
$limitCurrency = $limit->transactionCurrency ?? $this->currency;
$currencyId = (int) $limitCurrency->id;
$currencyId = (int)$limitCurrency->id;
$expenses = $this->opsRepository->sumExpenses($limit->start_date, $limit->end_date, $this->accounts, new Collection([$budget]));
$spent = $expenses[$currencyId]['sum'] ?? '0';
$left = -1 === bccomp(bcadd($limit->amount, $spent), '0') ? '0' : bcadd($limit->amount, $spent);
$overspent = 1 === bccomp(bcmul($spent, '-1'), $limit->amount) ? bcadd($spent, $limit->amount) : '0';
$this->report['budgets'][$budgetId]['budget_limits'][$limitId] = $this->report['budgets'][$budgetId]['budget_limits'][$limitId] ?? [
'budget_limit_id' => $limitId,
'start_date' => $limit->start_date,
'end_date' => $limit->end_date,
'budgeted' => $limit->amount,
'budgeted_pct' => '0',
'spent' => $spent,
'spent_pct' => '0',
'left' => $left,
'overspent' => $overspent,
'currency_id' => $currencyId,
'currency_code' => $limitCurrency->code,
'currency_name' => $limitCurrency->name,
'currency_symbol' => $limitCurrency->symbol,
'currency_decimal_places' => $limitCurrency->decimal_places,
];
'budget_limit_id' => $limitId,
'start_date' => $limit->start_date,
'end_date' => $limit->end_date,
'budgeted' => $limit->amount,
'budgeted_pct' => '0',
'spent' => $spent,
'spent_pct' => '0',
'left' => $left,
'overspent' => $overspent,
'currency_id' => $currencyId,
'currency_code' => $limitCurrency->code,
'currency_name' => $limitCurrency->name,
'currency_symbol' => $limitCurrency->symbol,
'currency_decimal_places' => $limitCurrency->decimal_places,
];
// make sum information:
$this->report['sums'][$currencyId]
= $this->report['sums'][$currencyId] ?? [
'budgeted' => '0',
'spent' => '0',
'left' => '0',
'overspent' => '0',
'currency_id' => $currencyId,
'currency_code' => $limitCurrency->code,
'currency_name' => $limitCurrency->name,
'currency_symbol' => $limitCurrency->symbol,
'currency_decimal_places' => $limitCurrency->decimal_places,
];
'budgeted' => '0',
'spent' => '0',
'left' => '0',
'overspent' => '0',
'currency_id' => $currencyId,
'currency_code' => $limitCurrency->code,
'currency_name' => $limitCurrency->name,
'currency_symbol' => $limitCurrency->symbol,
'currency_decimal_places' => $limitCurrency->decimal_places,
];
$this->report['sums'][$currencyId]['budgeted'] = bcadd($this->report['sums'][$currencyId]['budgeted'], $limit->amount);
$this->report['sums'][$currencyId]['spent'] = bcadd($this->report['sums'][$currencyId]['spent'], $spent);
$this->report['sums'][$currencyId]['left'] = bcadd($this->report['sums'][$currencyId]['left'], bcadd($limit->amount, $spent));
@@ -250,7 +253,7 @@ class BudgetReportGenerator
$noBudget = $this->nbRepository->sumExpenses($this->start, $this->end, $this->accounts);
foreach ($noBudget as $noBudgetEntry) {
// currency information:
$nbCurrencyId = (int) ($noBudgetEntry['currency_id'] ?? $this->currency->id);
$nbCurrencyId = (int)($noBudgetEntry['currency_id'] ?? $this->currency->id);
$nbCurrencyCode = $noBudgetEntry['currency_code'] ?? $this->currency->code;
$nbCurrencyName = $noBudgetEntry['currency_name'] ?? $this->currency->name;
$nbCurrencySymbol = $noBudgetEntry['currency_symbol'] ?? $this->currency->symbol;
@@ -295,9 +298,9 @@ class BudgetReportGenerator
// make percentages based on total amount.
foreach ($this->report['budgets'] as $budgetId => $data) {
foreach ($data['budget_limits'] as $limitId => $entry) {
$budgetId = (int) $budgetId;
$limitId = (int) $limitId;
$currencyId = (int) $entry['currency_id'];
$budgetId = (int)$budgetId;
$limitId = (int)$limitId;
$currencyId = (int)$entry['currency_id'];
$spent = $entry['spent'];
$totalSpent = $this->report['sums'][$currencyId]['spent'] ?? '0';
$spentPct = '0';
@@ -306,10 +309,10 @@ class BudgetReportGenerator
$budgetedPct = '0';
if (0 !== bccomp($spent, '0') && 0 !== bccomp($totalSpent, '0')) {
$spentPct = round((float) bcmul(bcdiv($spent, $totalSpent), '100'));
$spentPct = round((float)bcmul(bcdiv($spent, $totalSpent), '100'));
}
if (0 !== bccomp($budgeted, '0') && 0 !== bccomp($totalBudgeted, '0')) {
$budgetedPct = round((float) bcmul(bcdiv($budgeted, $totalBudgeted), '100'));
$budgetedPct = round((float)bcmul(bcdiv($budgeted, $totalBudgeted), '100'));
}
$this->report['sums'][$currencyId]['budgeted'] = $this->report['sums'][$currencyId]['budgeted'] ?? '0';
$this->report['budgets'][$budgetId]['budget_limits'][$limitId]['spent_pct'] = $spentPct;
@@ -327,7 +330,7 @@ class BudgetReportGenerator
}
/**
* @param Collection $accounts
* @param Collection $accounts
*/
public function setAccounts(Collection $accounts): void
{
@@ -335,7 +338,7 @@ class BudgetReportGenerator
}
/**
* @param Collection $budgets
* @param Collection $budgets
*/
public function setBudgets(Collection $budgets): void
{
@@ -343,7 +346,7 @@ class BudgetReportGenerator
}
/**
* @param Carbon $end
* @param Carbon $end
*/
public function setEnd(Carbon $end): void
{
@@ -351,7 +354,7 @@ class BudgetReportGenerator
}
/**
* @param Carbon $start
* @param Carbon $start
*/
public function setStart(Carbon $start): void
{
@@ -359,9 +362,9 @@ class BudgetReportGenerator
}
/**
* @param User $user
* @throws \FireflyIII\Exceptions\FireflyException
* @throws \JsonException
* @param User $user
* @throws FireflyException
* @throws JsonException
*/
public function setUser(User $user): void
{

View File

@@ -88,12 +88,12 @@ class CategoryReportGenerator
/**
* Process one of the spent arrays from the operations method.
*
* @param array $data
* @param array $data
*/
private function processOpsArray(array $data): void
{
/**
* @var int $currencyId
* @var int $currencyId
* @var array $currencyRow
*/
foreach ($data as $currencyId => $currencyRow) {
@@ -102,24 +102,24 @@ class CategoryReportGenerator
}
/**
* @param int $currencyId
* @param array $currencyRow
* @param int $currencyId
* @param array $currencyRow
*/
private function processCurrencyArray(int $currencyId, array $currencyRow): void
{
$this->report['sums'][$currencyId] = $this->report['sums'][$currencyId] ?? [
'spent' => '0',
'earned' => '0',
'sum' => '0',
'currency_id' => $currencyRow['currency_id'],
'currency_symbol' => $currencyRow['currency_symbol'],
'currency_name' => $currencyRow['currency_name'],
'currency_code' => $currencyRow['currency_code'],
'currency_decimal_places' => $currencyRow['currency_decimal_places'],
];
'spent' => '0',
'earned' => '0',
'sum' => '0',
'currency_id' => $currencyRow['currency_id'],
'currency_symbol' => $currencyRow['currency_symbol'],
'currency_name' => $currencyRow['currency_name'],
'currency_code' => $currencyRow['currency_code'],
'currency_decimal_places' => $currencyRow['currency_decimal_places'],
];
/**
* @var int $categoryId
* @var int $categoryId
* @var array $categoryRow
*/
foreach ($currencyRow['categories'] as $categoryId => $categoryRow) {
@@ -128,26 +128,26 @@ class CategoryReportGenerator
}
/**
* @param int $currencyId
* @param array $currencyRow
* @param int $categoryId
* @param array $categoryRow
* @param int $currencyId
* @param array $currencyRow
* @param int $categoryId
* @param array $categoryRow
*/
private function processCategoryRow(int $currencyId, array $currencyRow, int $categoryId, array $categoryRow): void
{
$key = sprintf('%s-%s', $currencyId, $categoryId);
$this->report['categories'][$key] = $this->report['categories'][$key] ?? [
'id' => $categoryId,
'title' => $categoryRow['name'],
'currency_id' => $currencyRow['currency_id'],
'currency_symbol' => $currencyRow['currency_symbol'],
'currency_name' => $currencyRow['currency_name'],
'currency_code' => $currencyRow['currency_code'],
'currency_decimal_places' => $currencyRow['currency_decimal_places'],
'spent' => '0',
'earned' => '0',
'sum' => '0',
];
'id' => $categoryId,
'title' => $categoryRow['name'],
'currency_id' => $currencyRow['currency_id'],
'currency_symbol' => $currencyRow['currency_symbol'],
'currency_name' => $currencyRow['currency_name'],
'currency_code' => $currencyRow['currency_code'],
'currency_decimal_places' => $currencyRow['currency_decimal_places'],
'spent' => '0',
'earned' => '0',
'sum' => '0',
];
// loop journals:
foreach ($categoryRow['transaction_journals'] as $journal) {
// sum of sums
@@ -179,7 +179,7 @@ class CategoryReportGenerator
}
/**
* @param Collection $accounts
* @param Collection $accounts
*/
public function setAccounts(Collection $accounts): void
{
@@ -187,7 +187,7 @@ class CategoryReportGenerator
}
/**
* @param Carbon $end
* @param Carbon $end
*/
public function setEnd(Carbon $end): void
{
@@ -195,7 +195,7 @@ class CategoryReportGenerator
}
/**
* @param Carbon $start
* @param Carbon $start
*/
public function setStart(Carbon $start): void
{
@@ -203,7 +203,7 @@ class CategoryReportGenerator
}
/**
* @param User $user
* @param User $user
*/
public function setUser(User $user): void
{