Various code cleanup.

This commit is contained in:
James Cole
2021-04-07 07:28:43 +02:00
parent 4ddcb0c965
commit f12744ad8c
180 changed files with 714 additions and 721 deletions

View File

@@ -95,7 +95,7 @@ class AccountController extends Controller
$cache->addProperty($end);
$cache->addProperty('chart.account.expense-accounts');
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
return response()->json($cache->get());
}
$start->subDay();
@@ -203,7 +203,7 @@ class AccountController extends Controller
$cache->addProperty($end);
$cache->addProperty('chart.account.expense-budget');
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
return response()->json($cache->get());
}
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
@@ -217,7 +217,7 @@ class AccountController extends Controller
$budgetId = (int)$journal['budget_id'];
$key = sprintf('%d-%d', $budgetId, $journal['currency_id']);
$budgetIds[] = $budgetId;
if (!isset($result[$key])) {
if (!array_key_exists($key, $result)) {
$result[$key] = [
'total' => '0',
'budget_id' => $budgetId,
@@ -277,7 +277,7 @@ class AccountController extends Controller
$cache->addProperty($end);
$cache->addProperty('chart.account.expense-category');
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
return response()->json($cache->get());
}
/** @var GroupCollectorInterface $collector */
@@ -290,7 +290,7 @@ class AccountController extends Controller
/** @var array $journal */
foreach ($journals as $journal) {
$key = sprintf('%d-%d', $journal['category_id'], $journal['currency_id']);
if (!isset($result[$key])) {
if (!array_key_exists($key, $result)) {
$result[$key] = [
'total' => '0',
'category_id' => (int)$journal['category_id'],
@@ -373,7 +373,7 @@ class AccountController extends Controller
$cache->addProperty($end);
$cache->addProperty('chart.account.income-category');
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
return response()->json($cache->get());
}
// grab all journals:
@@ -387,7 +387,7 @@ class AccountController extends Controller
/** @var array $journal */
foreach ($journals as $journal) {
$key = sprintf('%d-%d', $journal['category_id'], $journal['currency_id']);
if (!isset($result[$key])) {
if (!array_key_exists($key, $result)) {
$result[$key] = [
'total' => '0',
'category_id' => $journal['category_id'],
@@ -431,7 +431,7 @@ class AccountController extends Controller
$cache->addProperty($end);
$cache->addProperty($account->id);
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
return response()->json($cache->get());
}
$currencies = $this->accountRepository->getUsedCurrencies($account);
@@ -488,7 +488,7 @@ class AccountController extends Controller
$current->addDay();
}
break;
// @codeCoverageIgnoreStart
case '1W':
case '1M':
case '1Y':
@@ -499,7 +499,7 @@ class AccountController extends Controller
$current = app('navigation')->addPeriod($current, $step, 0);
}
break;
// @codeCoverageIgnoreEnd
}
$result['entries'] = $entries;
@@ -540,7 +540,7 @@ class AccountController extends Controller
$cache->addProperty($end);
$cache->addProperty('chart.account.revenue-accounts');
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
return response()->json($cache->get());
}
$start->subDay();

View File

@@ -67,7 +67,7 @@ class BillController extends Controller
$cache->addProperty($end);
$cache->addProperty('chart.bill.frontpage');
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
return response()->json($cache->get());
}
/** @var CurrencyRepositoryInterface $currencyRepository */
$currencyRepository = app(CurrencyRepositoryInterface::class);
@@ -109,7 +109,7 @@ class BillController extends Controller
$cache->addProperty('chart.bill.single');
$cache->addProperty($bill->id);
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
return response()->json($cache->get());
}
$locale = app('steam')->getLocale();
@@ -147,7 +147,7 @@ class BillController extends Controller
$chartData[1]['entries'][$date] = $bill->amount_max; // maximum amount of bill
// append amount because there are more than one per moment:
if (!isset($chartData[2]['entries'][$date])) {
if (!array_key_exists($date, $chartData[2]['entries'])) {
$chartData[2]['entries'][$date] = '0';
}
$amount = bcmul($journal['amount'], '-1');

View File

@@ -98,7 +98,7 @@ class BudgetController extends Controller
$cache->addProperty($budget->id);
if ($cache->has()) {
//return response()->json($cache->get()); // @codeCoverageIgnore
//return response()->json($cache->get());
}
$step = $this->calculateStep($start, $end); // depending on diff, do something with range of chart.
$collection = new Collection([$budget]);
@@ -169,7 +169,7 @@ class BudgetController extends Controller
$cache->addProperty($budget->id);
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
return response()->json($cache->get());
}
$locale = app('steam')->getLocale();
$entries = [];
@@ -224,7 +224,7 @@ class BudgetController extends Controller
$cache->addProperty($end);
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
return response()->json($cache->get());
}
$collector->setRange($start, $end);
$collector->setBudget($budget);
@@ -291,7 +291,7 @@ class BudgetController extends Controller
$cache->addProperty($end);
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
return response()->json($cache->get());
}
$collector->setRange($start, $end);
$collector->setBudget($budget)->withCategoryInformation();
@@ -355,7 +355,7 @@ class BudgetController extends Controller
$cache->addProperty($end);
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
return response()->json($cache->get());
}
$collector->setRange($start, $end);
$collector->setTypes([TransactionType::WITHDRAWAL])->setBudget($budget)->withAccountInformation();
@@ -410,7 +410,7 @@ class BudgetController extends Controller
$cache->addProperty($end);
$cache->addProperty('chart.budget.frontpage');
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
return response()->json($cache->get());
}
$chartGenerator = app(FrontpageChartGenerator::class);
@@ -447,7 +447,7 @@ class BudgetController extends Controller
$cache->addProperty($currency->id);
$cache->addProperty('chart.budget.period');
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
return response()->json($cache->get());
}
$titleFormat = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
$preferredRange = app('navigation')->preferredRangeFormat($start, $end);
@@ -521,7 +521,7 @@ class BudgetController extends Controller
$cache->addProperty($currency->id);
$cache->addProperty('chart.budget.no-budget');
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
return response()->json($cache->get());
}
// the expenses:

View File

@@ -76,7 +76,7 @@ class CategoryController extends Controller
$cache->addProperty('chart.category.all');
$cache->addProperty($category->id);
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
return response()->json($cache->get());
}
/** @var CategoryRepositoryInterface $repository */
$repository = app(CategoryRepositoryInterface::class);
@@ -102,8 +102,8 @@ class CategoryController extends Controller
$carbon = null;
try {
$carbon = today(config('app.timezone'));
} catch (Exception $e) {
$e->getMessage();
} catch (Exception $e) { // @phpstan-ignore-line
// @ignoreException
}
return $carbon;
@@ -125,7 +125,7 @@ class CategoryController extends Controller
$cache->addProperty($end);
$cache->addProperty('chart.category.frontpage');
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
return response()->json($cache->get());
}
$frontPageGenerator = new FrontpageChartGenerator($start, $end);
@@ -156,7 +156,7 @@ class CategoryController extends Controller
$cache->addProperty($accounts->pluck('id')->toArray());
$cache->addProperty($category);
if ($cache->has()) {
return response()->json($cache->get());// @codeCoverageIgnore
return response()->json($cache->get());
}
$data = $this->reportPeriodChart($accounts, $start, $end, $category);
@@ -270,7 +270,7 @@ class CategoryController extends Controller
$cache->addProperty('chart.category.period.no-cat');
$cache->addProperty($accounts->pluck('id')->toArray());
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
return response()->json($cache->get());
}
$data = $this->reportPeriodChart($accounts, $start, $end, null);
@@ -294,7 +294,7 @@ class CategoryController extends Controller
$start = app('navigation')->startOfPeriod($date, $range);
$end = session()->get('end');
if ($end < $start) {
[$end, $start] = [$start, $end]; // @codeCoverageIgnore
[$end, $start] = [$start, $end];
}
$cache = new CacheProperties;
@@ -303,7 +303,7 @@ class CategoryController extends Controller
$cache->addProperty($category->id);
$cache->addProperty('chart.category.period-chart');
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
return response()->json($cache->get());
}
/** @var WholePeriodChartGenerator $chartGenerator */

View File

@@ -88,7 +88,7 @@ class ExpenseReportController extends Controller
$cache->addProperty($start);
$cache->addProperty($end);
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
return response()->json($cache->get());
}
$format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
@@ -184,11 +184,11 @@ class ExpenseReportController extends Controller
$newSet = [];
foreach ($chartData as $key => $entry) {
if (0 === !array_sum($entry['entries'])) {
$newSet[$key] = $chartData[$key]; // @codeCoverageIgnore
$newSet[$key] = $chartData[$key];
}
}
if (empty($newSet)) {
$newSet = $chartData; // @codeCoverageIgnore
if (0===count($newSet)) {
$newSet = $chartData;
}
$data = $this->generator->multiSet($newSet);
$cache->store($data);

View File

@@ -73,7 +73,7 @@ class PiggyBankController extends Controller
$cache->addProperty('chart.piggy-bank.history');
$cache->addProperty($piggyBank->id);
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
return response()->json($cache->get());
}
$set = $repository->getEvents($piggyBank);
$set = $set->reverse();

View File

@@ -78,7 +78,7 @@ class ReportController extends Controller
$cache->addProperty(implode(',', $accounts->pluck('id')->toArray()));
$cache->addProperty($end);
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
return response()->json($cache->get());
}
$locale = app('steam')->getLocale();
$current = clone $start;
@@ -113,7 +113,7 @@ class ReportController extends Controller
foreach ($result as $netWorthItem) {
$currencyId = $netWorthItem['currency']->id;
$label = $current->formatLocalized((string)trans('config.month_and_day', [], $locale));
if (!isset($chartData[$currencyId])) {
if (!array_key_exists($currencyId, $chartData)) {
$chartData[$currencyId] = [
'label' => 'Net worth in ' . $netWorthItem['currency']->name,
'type' => 'line',
@@ -152,7 +152,7 @@ class ReportController extends Controller
$cache->addProperty($accounts);
$cache->addProperty($end);
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
return response()->json($cache->get());
}
Log::debug('Going to do operations for accounts ', $accounts->pluck('id')->toArray());
$format = app('navigation')->preferredCarbonFormat($start, $end);

View File

@@ -66,7 +66,7 @@ class TransactionController extends Controller
$cache->addProperty($end);
$cache->addProperty('chart.transactions.budgets');
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
return response()->json($cache->get());
}
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
@@ -111,7 +111,7 @@ class TransactionController extends Controller
$cache->addProperty($objectType);
$cache->addProperty('chart.transactions.categories');
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
return response()->json($cache->get());
}
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
@@ -169,7 +169,7 @@ class TransactionController extends Controller
$cache->addProperty($objectType);
$cache->addProperty('chart.transactions.destinations');
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
return response()->json($cache->get());
}
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
@@ -226,7 +226,7 @@ class TransactionController extends Controller
$cache->addProperty($objectType);
$cache->addProperty('chart.transactions.sources');
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
return response()->json($cache->get());
}
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);