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
/**
* FrontpageChartGenerator.php
* Copyright (c) 2020 james@firefly-iii.org
@@ -23,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Chart\Budget;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
@@ -64,9 +66,9 @@ class FrontpageChartGenerator
{
$budgets = $this->budgetRepository->getActiveBudgets();
$data = [
['label' => (string) trans('firefly.spent_in_budget'), 'entries' => [], 'type' => 'bar'],
['label' => (string) trans('firefly.left_to_spend'), 'entries' => [], 'type' => 'bar'],
['label' => (string) trans('firefly.overspent'), 'entries' => [], 'type' => 'bar'],
['label' => (string)trans('firefly.spent_in_budget'), 'entries' => [], 'type' => 'bar'],
['label' => (string)trans('firefly.left_to_spend'), 'entries' => [], 'type' => 'bar'],
['label' => (string)trans('firefly.overspent'), 'entries' => [], 'type' => 'bar'],
];
// loop al budgets:
@@ -83,8 +85,8 @@ class FrontpageChartGenerator
* When no limits are present, the time range is used to collect information on money spent.
* If limits are present, each limit is processed individually.
*
* @param array $data
* @param Budget $budget
* @param array $data
* @param Budget $budget
*
* @return array
*/
@@ -105,8 +107,8 @@ class FrontpageChartGenerator
* When no limits are present, the expenses of the whole period are collected and grouped.
* This is grouped per currency. Because there is no limit set, "left to spend" and "overspent" are empty.
*
* @param array $data
* @param Budget $budget
* @param array $data
* @param Budget $budget
*
* @return array
*/
@@ -127,9 +129,9 @@ class FrontpageChartGenerator
/**
* If a budget has budget limit, each limit is processed individually.
*
* @param array $data
* @param Budget $budget
* @param Collection $limits
* @param array $data
* @param Budget $budget
* @param Collection $limits
*
* @return array
*/
@@ -146,9 +148,9 @@ class FrontpageChartGenerator
/**
* For each limit, the expenses from the time range of the limit are collected. Each row from the result is processed individually.
*
* @param array $data
* @param Budget $budget
* @param BudgetLimit $limit
* @param array $data
* @param Budget $budget
* @param BudgetLimit $limit
*
* @return array
*/
@@ -158,7 +160,7 @@ class FrontpageChartGenerator
/** @var array $entry */
foreach ($spent as $entry) {
// only spent the entry where the entry's currency matches the budget limit's currency
if ($entry['currency_id'] === (int) $limit->transaction_currency_id) {
if ($entry['currency_id'] === (int)$limit->transaction_currency_id) {
$data = $this->processRow($data, $budget, $limit, $entry);
}
}
@@ -172,10 +174,10 @@ class FrontpageChartGenerator
* Each one is added to the $data array. If the limit's date range is different from the global $start and $end dates,
* for example when a limit only partially falls into this month, the title is expanded to clarify.
*
* @param array $data
* @param Budget $budget
* @param BudgetLimit $limit
* @param array $entry
* @param array $data
* @param Budget $budget
* @param BudgetLimit $limit
* @param array $entry
*
* @return array
*/
@@ -201,7 +203,7 @@ class FrontpageChartGenerator
}
/**
* @param Carbon $end
* @param Carbon $end
*/
public function setEnd(Carbon $end): void
{
@@ -209,7 +211,7 @@ class FrontpageChartGenerator
}
/**
* @param Carbon $start
* @param Carbon $start
*/
public function setStart(Carbon $start): void
{
@@ -219,8 +221,8 @@ class FrontpageChartGenerator
/**
* A basic setter for the user. Also updates the repositories with the right user.
*
* @param User $user
* @throws \FireflyIII\Exceptions\FireflyException
* @param User $user
* @throws FireflyException
*/
public function setUser(User $user): void
{
@@ -230,6 +232,6 @@ class FrontpageChartGenerator
$this->opsRepository->setUser($user);
$locale = app('steam')->getLocale();
$this->monthAndDayFormat = (string) trans('config.month_and_day_js', [], $locale);
$this->monthAndDayFormat = (string)trans('config.month_and_day_js', [], $locale);
}
}

View File

@@ -52,8 +52,8 @@ class FrontpageChartGenerator
/**
* FrontpageChartGenerator constructor.
*
* @param Carbon $start
* @param Carbon $end
* @param Carbon $start
* @param Carbon $end
*/
public function __construct(Carbon $start, Carbon $end)
{
@@ -99,8 +99,8 @@ class FrontpageChartGenerator
}
/**
* @param Category $category
* @param Collection $accounts
* @param Category $category
* @param Collection $accounts
*
* @return array
*/
@@ -113,8 +113,8 @@ class FrontpageChartGenerator
$tempData[] = [
'name' => $category->name,
'sum' => $currency['sum'],
'sum_float' => round((float) $currency['sum'], $currency['currency_decimal_places']),
'currency_id' => (int) $currency['currency_id'],
'sum_float' => round((float)$currency['sum'], $currency['currency_decimal_places']),
'currency_id' => (int)$currency['currency_id'],
];
}
@@ -122,23 +122,23 @@ class FrontpageChartGenerator
}
/**
* @param array $currency
* @param array $currency
*/
private function addCurrency(array $currency): void
{
$currencyId = (int) $currency['currency_id'];
$currencyId = (int)$currency['currency_id'];
$this->currencies[$currencyId] = $this->currencies[$currencyId] ?? [
'currency_id' => $currencyId,
'currency_name' => $currency['currency_name'],
'currency_symbol' => $currency['currency_symbol'],
'currency_code' => $currency['currency_code'],
'currency_decimal_places' => $currency['currency_decimal_places'],
];
'currency_id' => $currencyId,
'currency_name' => $currency['currency_name'],
'currency_symbol' => $currency['currency_symbol'],
'currency_code' => $currency['currency_code'],
'currency_decimal_places' => $currency['currency_decimal_places'],
];
}
/**
* @param Collection $accounts
* @param Collection $accounts
*
* @return array
*/
@@ -151,8 +151,8 @@ class FrontpageChartGenerator
$tempData[] = [
'name' => trans('firefly.no_category'),
'sum' => $currency['sum'],
'sum_float' => round((float) $currency['sum'], $currency['currency_decimal_places'] ?? 2), // intentional float
'currency_id' => (int) $currency['currency_id'],
'sum_float' => round((float)$currency['sum'], $currency['currency_decimal_places'] ?? 2), // intentional float
'currency_id' => (int)$currency['currency_id'],
];
}
@@ -160,7 +160,7 @@ class FrontpageChartGenerator
}
/**
* @param array $data
* @param array $data
*
* @return array
*/
@@ -174,7 +174,7 @@ class FrontpageChartGenerator
foreach ($this->currencies as $currencyId => $currency) {
$key = sprintf('spent-%d', $currencyId);
$return[$key] = [
'label' => sprintf('%s (%s)', (string) trans('firefly.spent'), $currency['currency_name']),
'label' => sprintf('%s (%s)', (string)trans('firefly.spent'), $currency['currency_name']),
'type' => 'bar',
'currency_symbol' => $currency['currency_symbol'],
'entries' => $names,
@@ -185,8 +185,8 @@ class FrontpageChartGenerator
}
/**
* @param array $currencyData
* @param array $monetaryData
* @param array $currencyData
* @param array $monetaryData
*
* @return array
*/

View File

@@ -36,9 +36,9 @@ use Illuminate\Support\Collection;
class WholePeriodChartGenerator
{
/**
* @param Category $category
* @param Carbon $start
* @param Carbon $end
* @param Category $category
* @param Carbon $start
* @param Carbon $end
*
* @return array
*/
@@ -77,14 +77,14 @@ class WholePeriodChartGenerator
$code = $currency['currency_code'];
$name = $currency['currency_name'];
$chartData[sprintf('spent-in-%s', $code)] = [
'label' => (string) trans('firefly.box_spent_in_currency', ['currency' => $name]),
'label' => (string)trans('firefly.box_spent_in_currency', ['currency' => $name]),
'entries' => [],
'type' => 'bar',
'backgroundColor' => 'rgba(219, 68, 55, 0.5)', // red
];
$chartData[sprintf('earned-in-%s', $code)] = [
'label' => (string) trans('firefly.box_earned_in_currency', ['currency' => $name]),
'label' => (string)trans('firefly.box_earned_in_currency', ['currency' => $name]),
'entries' => [],
'type' => 'bar',
'backgroundColor' => 'rgba(0, 141, 76, 0.5)', // green
@@ -117,8 +117,8 @@ class WholePeriodChartGenerator
/**
* TODO this method is duplicated
*
* @param Carbon $start
* @param Carbon $end
* @param Carbon $start
* @param Carbon $end
*
* @return string
*/
@@ -143,7 +143,7 @@ class WholePeriodChartGenerator
* Loop array of spent/earned info, and extract which currencies are present.
* Key is the currency ID.
*
* @param array $array
* @param array $array
*
* @return array
*/
@@ -153,12 +153,12 @@ class WholePeriodChartGenerator
foreach ($array as $block) {
foreach ($block as $currencyId => $currencyRow) {
$return[$currencyId] = $return[$currencyId] ?? [
'currency_id' => $currencyId,
'currency_name' => $currencyRow['currency_name'],
'currency_symbol' => $currencyRow['currency_symbol'],
'currency_code' => $currencyRow['currency_code'],
'currency_decimal_places' => $currencyRow['currency_decimal_places'],
];
'currency_id' => $currencyId,
'currency_name' => $currencyRow['currency_name'],
'currency_symbol' => $currencyRow['currency_symbol'],
'currency_code' => $currencyRow['currency_code'],
'currency_decimal_places' => $currencyRow['currency_decimal_places'],
];
}
}