mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-14 16:13:54 +00:00
Small code cleanup [skip ci]
This commit is contained in:
@@ -76,7 +76,9 @@ class IndexController extends Controller
|
|||||||
public function index(Request $request, string $moment = null)
|
public function index(Request $request, string $moment = null)
|
||||||
{
|
{
|
||||||
$range = app('preferences')->get('viewRange', '1M')->data;
|
$range = app('preferences')->get('viewRange', '1M')->data;
|
||||||
|
/** @var Carbon $start */
|
||||||
$start = session('start', new Carbon);
|
$start = session('start', new Carbon);
|
||||||
|
/** @var Carbon $end */
|
||||||
$end = session('end', new Carbon);
|
$end = session('end', new Carbon);
|
||||||
$page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');
|
$page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');
|
||||||
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
||||||
@@ -86,6 +88,7 @@ class IndexController extends Controller
|
|||||||
if ('' !== (string)$moment) {
|
if ('' !== (string)$moment) {
|
||||||
try {
|
try {
|
||||||
$start = new Carbon($moment);
|
$start = new Carbon($moment);
|
||||||
|
/** @var Carbon $end */
|
||||||
$end = app('navigation')->endOfPeriod($start, $range);
|
$end = app('navigation')->endOfPeriod($start, $range);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
// start and end are already defined.
|
// start and end are already defined.
|
||||||
|
@@ -433,8 +433,8 @@ class AccountController extends Controller
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
* @SuppressWarnigns(PHPMD.CyclomaticComplexity)
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||||
* @SuppressWarnigns(PHPMD.ExcessiveMethodLength)
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||||
*/
|
*/
|
||||||
private function accountBalanceChart(Collection $accounts, Carbon $start, Carbon $end): array
|
private function accountBalanceChart(Collection $accounts, Carbon $start, Carbon $end): array
|
||||||
{
|
{
|
||||||
|
@@ -43,6 +43,9 @@ use Illuminate\Support\Collection;
|
|||||||
/**
|
/**
|
||||||
* Class BudgetController.
|
* Class BudgetController.
|
||||||
*
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
|
||||||
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
class BudgetController extends Controller
|
class BudgetController extends Controller
|
||||||
{
|
{
|
||||||
@@ -91,13 +94,11 @@ class BudgetController extends Controller
|
|||||||
return response()->json($cache->get()); // @codeCoverageIgnore
|
return response()->json($cache->get()); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
// depending on diff, do something with range of chart.
|
$step = $this->calculateStep($start, $end); // depending on diff, do something with range of chart.
|
||||||
$step = $this->calculateStep($start, $end);
|
|
||||||
$budgetCollection = new Collection([$budget]);
|
$budgetCollection = new Collection([$budget]);
|
||||||
$chartData = [];
|
$chartData = [];
|
||||||
$current = clone $start;
|
$current = clone $start;
|
||||||
$current = app('navigation')->startOfPeriod($current, $step);
|
$current = app('navigation')->startOfPeriod($current, $step);
|
||||||
|
|
||||||
while ($end >= $current) {
|
while ($end >= $current) {
|
||||||
/** @var Carbon $currentEnd */
|
/** @var Carbon $currentEnd */
|
||||||
$currentEnd = app('navigation')->endOfPeriod($current, $step);
|
$currentEnd = app('navigation')->endOfPeriod($current, $step);
|
||||||
@@ -172,6 +173,8 @@ class BudgetController extends Controller
|
|||||||
* @param BudgetLimit|null $budgetLimit
|
* @param BudgetLimit|null $budgetLimit
|
||||||
*
|
*
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||||
*/
|
*/
|
||||||
public function expenseAsset(Budget $budget, ?BudgetLimit $budgetLimit): JsonResponse
|
public function expenseAsset(Budget $budget, ?BudgetLimit $budgetLimit): JsonResponse
|
||||||
{
|
{
|
||||||
@@ -218,6 +221,8 @@ class BudgetController extends Controller
|
|||||||
* @param BudgetLimit|null $budgetLimit
|
* @param BudgetLimit|null $budgetLimit
|
||||||
*
|
*
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||||
*/
|
*/
|
||||||
public function expenseCategory(Budget $budget, ?BudgetLimit $budgetLimit): JsonResponse
|
public function expenseCategory(Budget $budget, ?BudgetLimit $budgetLimit): JsonResponse
|
||||||
{
|
{
|
||||||
@@ -253,7 +258,6 @@ class BudgetController extends Controller
|
|||||||
foreach ($result as $categoryId => $amount) {
|
foreach ($result as $categoryId => $amount) {
|
||||||
$chartData[$names[$categoryId]] = $amount;
|
$chartData[$names[$categoryId]] = $amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $this->generator->pieChart($chartData);
|
$data = $this->generator->pieChart($chartData);
|
||||||
$cache->store($data);
|
$cache->store($data);
|
||||||
|
|
||||||
@@ -266,6 +270,8 @@ class BudgetController extends Controller
|
|||||||
* @param BudgetLimit|null $budgetLimit
|
* @param BudgetLimit|null $budgetLimit
|
||||||
*
|
*
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||||
*/
|
*/
|
||||||
public function expenseExpense(Budget $budget, ?BudgetLimit $budgetLimit): JsonResponse
|
public function expenseExpense(Budget $budget, ?BudgetLimit $budgetLimit): JsonResponse
|
||||||
{
|
{
|
||||||
@@ -312,6 +318,9 @@ class BudgetController extends Controller
|
|||||||
* Shows a budget list with spent/left/overspent.
|
* Shows a budget list with spent/left/overspent.
|
||||||
*
|
*
|
||||||
* @return \Symfony\Component\HttpFoundation\Response
|
* @return \Symfony\Component\HttpFoundation\Response
|
||||||
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||||
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||||
*/
|
*/
|
||||||
public function frontpage(): \Symfony\Component\HttpFoundation\Response
|
public function frontpage(): \Symfony\Component\HttpFoundation\Response
|
||||||
{
|
{
|
||||||
@@ -524,6 +533,8 @@ class BudgetController extends Controller
|
|||||||
* @param Carbon $end
|
* @param Carbon $end
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||||
*/
|
*/
|
||||||
private function getExpensesForBudget(Collection $limits, Budget $budget, Carbon $start, Carbon $end): array
|
private function getExpensesForBudget(Collection $limits, Budget $budget, Carbon $start, Carbon $end): array
|
||||||
{
|
{
|
||||||
@@ -564,6 +575,9 @@ class BudgetController extends Controller
|
|||||||
* @param Collection $limits
|
* @param Collection $limits
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
private function spentInPeriodMulti(Budget $budget, Collection $limits): array
|
private function spentInPeriodMulti(Budget $budget, Collection $limits): array
|
||||||
{
|
{
|
||||||
@@ -584,15 +598,9 @@ class BudgetController extends Controller
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
* amount: amount of budget limit
|
|
||||||
* left: amount of budget limit min spent, or 0 when < 0.
|
|
||||||
* spent: spent, or amount of budget limit when > amount
|
|
||||||
*/
|
|
||||||
$amount = $budgetLimit->amount;
|
$amount = $budgetLimit->amount;
|
||||||
$leftInLimit = bcsub($amount, $expenses);
|
$leftInLimit = bcsub($amount, $expenses);
|
||||||
$hasOverspent = bccomp($leftInLimit, '0') === -1;
|
$hasOverspent = bccomp($leftInLimit, '0') === -1;
|
||||||
|
|
||||||
$left = $hasOverspent ? '0' : bcsub($amount, $expenses);
|
$left = $hasOverspent ? '0' : bcsub($amount, $expenses);
|
||||||
$spent = $hasOverspent ? $amount : $expenses;
|
$spent = $hasOverspent ? $amount : $expenses;
|
||||||
$overspent = $hasOverspent ? app('steam')->positive($leftInLimit) : '0';
|
$overspent = $hasOverspent ? app('steam')->positive($leftInLimit) : '0';
|
||||||
|
@@ -43,6 +43,8 @@ use Illuminate\Support\Collection;
|
|||||||
* Separate controller because many helper functions are shared.
|
* Separate controller because many helper functions are shared.
|
||||||
*
|
*
|
||||||
* Class BudgetReportController
|
* Class BudgetReportController
|
||||||
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||||
*/
|
*/
|
||||||
class BudgetReportController extends Controller
|
class BudgetReportController extends Controller
|
||||||
{
|
{
|
||||||
@@ -76,6 +78,8 @@ class BudgetReportController extends Controller
|
|||||||
* @param string $others
|
* @param string $others
|
||||||
*
|
*
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
|
||||||
*/
|
*/
|
||||||
public function accountExpense(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end, string $others): JsonResponse
|
public function accountExpense(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end, string $others): JsonResponse
|
||||||
{
|
{
|
||||||
@@ -101,6 +105,8 @@ class BudgetReportController extends Controller
|
|||||||
* @param string $others
|
* @param string $others
|
||||||
*
|
*
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
|
||||||
*/
|
*/
|
||||||
public function budgetExpense(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end, string $others): JsonResponse
|
public function budgetExpense(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end, string $others): JsonResponse
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user