Various code fixes.

This commit is contained in:
James Cole 2022-11-04 05:11:05 +01:00
parent 8d8f81c27d
commit f16b679049
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
48 changed files with 226 additions and 246 deletions

View File

@ -17,6 +17,7 @@ parameters:
- ../app/Console/Commands/Correction/FixAccountTypes.php
- ../app/Console/Commands/Upgrade/OtherCurrenciesCorrections.php
- ../app/Exceptions/GracefulNotFoundHandler.php
- ../app/Generator/Webhook/StandardMessageGenerator.php
-
message: '#Function compact\(\) should not be used#'
paths:
@ -28,6 +29,9 @@ parameters:
- ../app/Generator/Report/Standard/MultiYearReportGenerator.php
- ../app/Generator/Report/Standard/YearReportGenerator.php
- ../app/Generator/Report/Tag/MonthReportGenerator.php
- ../app/Http/Controllers/Account/*.php
- ../app/Http/Controllers/Admin/*.php
- ../app/Http/Controllers/*.php
paths:
- ../app

View File

@ -156,7 +156,7 @@ class MonthReportGenerator implements ReportGeneratorInterface
return [
'journals' => $journals,
'currency' => $currency,
'exists' => !empty($journals),
'exists' => 0 !== count($journals),
'end' => $this->end->isoFormat((string) trans('config.month_and_day_moment_js', [], $locale)),
'endBalance' => app('steam')->balance($account, $this->end),
'dayBefore' => $date->isoFormat((string) trans('config.month_and_day_moment_js', [], $locale)),

View File

@ -180,7 +180,7 @@ class MonthReportGenerator implements ReportGeneratorInterface
*/
protected function getExpenses(): array
{
if (!empty($this->expenses)) {
if (0 !== count($this->expenses)) {
Log::debug('Return previous set of expenses.');
return $this->expenses;

View File

@ -188,7 +188,7 @@ class MonthReportGenerator implements ReportGeneratorInterface
*/
protected function getExpenses(): array
{
if (!empty($this->expenses)) {
if (0 !== count($this->expenses)) {
Log::debug('Return previous set of expenses.');
return $this->expenses;
@ -213,7 +213,7 @@ class MonthReportGenerator implements ReportGeneratorInterface
*/
protected function getIncome(): array
{
if (!empty($this->income)) {
if (0 !== count($this->income)) {
return $this->income;
}

View File

@ -1,4 +1,5 @@
<?php
/**
* UserEventHandler.php
* Copyright (c) 2019 james@firefly-iii.org
@ -62,7 +63,7 @@ class UserEventHandler
/**
* This method will bestow upon a user the "owner" role if he is the first user in the system.
*
* @param RegisteredUser $event
* @param RegisteredUser $event
*
* @return bool
*/
@ -79,7 +80,7 @@ class UserEventHandler
}
/**
* @param InvitationCreated $event
* @param InvitationCreated $event
* @return void
*/
public function sendRegistrationInvite(InvitationCreated $event): void
@ -96,7 +97,7 @@ class UserEventHandler
}
/**
* @param RegisteredUser $event
* @param RegisteredUser $event
* @return bool
*/
public function createExchangeRates(RegisteredUser $event): void
@ -108,7 +109,7 @@ class UserEventHandler
/**
* Fires to see if a user is admin.
*
* @param Login $event
* @param Login $event
*
* @return bool
*/
@ -138,7 +139,7 @@ class UserEventHandler
}
/**
* @param RegisteredUser $event
* @param RegisteredUser $event
*
* @return bool
* @throws FireflyException
@ -149,6 +150,8 @@ class UserEventHandler
$groupExists = true;
$groupTitle = $user->email;
$index = 1;
/** @var UserGroup $group */
$group = null;
// create a new group.
while (true === $groupExists) {
@ -163,6 +166,7 @@ class UserEventHandler
throw new FireflyException('Email address can no longer be used for registrations.');
}
}
/** @var UserRole $role */
$role = UserRole::where('title', UserRole::OWNER)->first();
if (null === $role) {
throw new FireflyException('The user role is unexpectedly empty. Did you run all migrations?');
@ -181,7 +185,7 @@ class UserEventHandler
/**
* Set the demo user back to English.
*
* @param Login $event
* @param Login $event
*
* @throws FireflyException
*/
@ -201,7 +205,7 @@ class UserEventHandler
}
/**
* @param DetectedNewIPAddress $event
* @param DetectedNewIPAddress $event
*
* @throws FireflyException
*/
@ -232,7 +236,7 @@ class UserEventHandler
* Send email to confirm email change. Will not be made into a notification, because
* this requires some custom fields from the user and not just the "user" object.
*
* @param UserChangedEmail $event
* @param UserChangedEmail $event
*
* @throws FireflyException
*/
@ -256,7 +260,7 @@ class UserEventHandler
* Send email to be able to undo email change. Will not be made into a notification, because
* this requires some custom fields from the user and not just the "user" object.
*
* @param UserChangedEmail $event
* @param UserChangedEmail $event
*
* @throws FireflyException
*/
@ -266,7 +270,7 @@ class UserEventHandler
$oldEmail = $event->oldEmail;
$user = $event->user;
$token = app('preferences')->getForUser($user, 'email_change_undo_token', 'invalid');
$hashed = hash('sha256', sprintf('%s%s', (string) config('app.key'), $oldEmail));
$hashed = hash('sha256', sprintf('%s%s', (string)config('app.key'), $oldEmail));
$url = route('profile.undo-email-change', [$token->data, $hashed]);
try {
Mail::to($oldEmail)->send(new UndoEmailChangeMail($newEmail, $oldEmail, $url));
@ -278,7 +282,7 @@ class UserEventHandler
/**
* Send a new password to the user.
* @param RequestedNewPassword $event
* @param RequestedNewPassword $event
*/
public function sendNewPassword(RequestedNewPassword $event): void
{
@ -289,7 +293,7 @@ class UserEventHandler
* This method will send the user a registration mail, welcoming him or her to Firefly III.
* This message is only sent when the configuration of Firefly III says so.
*
* @param RegisteredUser $event
* @param RegisteredUser $event
*
*/
public function sendRegistrationMail(RegisteredUser $event): void
@ -301,7 +305,7 @@ class UserEventHandler
}
/**
* @param RegisteredUser $event
* @param RegisteredUser $event
*/
public function sendAdminRegistrationNotification(RegisteredUser $event): void
{
@ -319,7 +323,7 @@ class UserEventHandler
}
/**
* @param ActuallyLoggedIn $event
* @param ActuallyLoggedIn $event
* @throws FireflyException
*/
public function storeUserIPAddress(ActuallyLoggedIn $event): void

View File

@ -372,7 +372,7 @@ class GroupCollector implements GroupCollectorInterface
*/
public function excludeJournalIds(array $journalIds): GroupCollectorInterface
{
if (!empty($journalIds)) {
if (0 !== count($journalIds)) {
// make all integers.
$integerIDs = array_map('intval', $journalIds);
@ -894,7 +894,7 @@ class GroupCollector implements GroupCollectorInterface
*/
public function setJournalIds(array $journalIds): GroupCollectorInterface
{
if (!empty($journalIds)) {
if (0 !== count($journalIds)) {
// make all integers.
$integerIDs = array_map('intval', $journalIds);

View File

@ -61,7 +61,7 @@ class CreateController extends Controller
$this->middleware(
function ($request, $next) {
app('view')->share('mainTitleIcon', 'fa-credit-card');
app('view')->share('title', (string) trans('firefly.accounts'));
app('view')->share('title', (string)trans('firefly.accounts'));
$this->repository = app(AccountRepositoryInterface::class);
$this->attachments = app(AttachmentHelperInterface::class);
@ -74,17 +74,16 @@ class CreateController extends Controller
/**
* Create a new account.
*
* @param Request $request
* @param string|null $objectType
* @param Request $request
* @param string $objectType
*
* @return Factory|View
*/
public function create(Request $request, string $objectType = null)
public function create(Request $request, string $objectType)
{
$objectType = $objectType ?? 'asset';
$defaultCurrency = app('amount')->getDefaultCurrency();
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType));
$subTitle = (string) trans(sprintf('firefly.make_new_%s_account', $objectType));
$subTitle = (string)trans(sprintf('firefly.make_new_%s_account', $objectType));
$roles = $this->getRoles();
$liabilityTypes = $this->getLiabilityTypes();
$hasOldInput = null !== $request->old('_token');
@ -103,9 +102,9 @@ class CreateController extends Controller
// interest calculation periods:
$interestPeriods = [
'daily' => (string) trans('firefly.interest_calc_daily'),
'monthly' => (string) trans('firefly.interest_calc_monthly'),
'yearly' => (string) trans('firefly.interest_calc_yearly'),
'daily' => (string)trans('firefly.interest_calc_daily'),
'monthly' => (string)trans('firefly.interest_calc_monthly'),
'yearly' => (string)trans('firefly.interest_calc_yearly'),
];
// pre fill some data
@ -113,7 +112,7 @@ class CreateController extends Controller
'preFilled',
[
'currency_id' => $defaultCurrency->id,
'include_net_worth' => $hasOldInput ? (bool) $request->old('include_net_worth') : true,
'include_net_worth' => $hasOldInput ? (bool)$request->old('include_net_worth') : true,
]
);
@ -133,7 +132,7 @@ class CreateController extends Controller
/**
* Store the new account.
*
* @param AccountFormRequest $request
* @param AccountFormRequest $request
*
* @return RedirectResponse|Redirector
* @throws FireflyException
@ -144,7 +143,7 @@ class CreateController extends Controller
{
$data = $request->getAccountData();
$account = $this->repository->store($data);
$request->session()->flash('success', (string) trans('firefly.stored_new_account', ['name' => $account->name]));
$request->session()->flash('success', (string)trans('firefly.stored_new_account', ['name' => $account->name]));
app('preferences')->mark();
Log::channel('audit')->info('Stored new account.', $data);
@ -163,7 +162,7 @@ class CreateController extends Controller
$this->attachments->saveAttachmentsForModel($account, $files);
}
if (null !== $files && auth()->user()->hasRole('demo')) {
session()->flash('info', (string) trans('firefly.no_att_demo_user'));
session()->flash('info', (string)trans('firefly.no_att_demo_user'));
}
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
@ -172,7 +171,7 @@ class CreateController extends Controller
// redirect to previous URL.
$redirect = redirect($this->getPreviousUrl('accounts.create.url'));
if (1 === (int) $request->get('create_another')) {
if (1 === (int)$request->get('create_another')) {
// set value so create routine will not overwrite URL:
$request->session()->put('accounts.create.fromStore', true);

View File

@ -79,7 +79,6 @@ class IndexController extends Controller
*/
public function inactive(Request $request, string $objectType)
{
$objectType = $objectType ?? 'asset';
$inactivePage = true;
$subTitle = (string) trans(sprintf('firefly.%s_accounts_inactive', $objectType));
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType));
@ -137,7 +136,6 @@ class IndexController extends Controller
public function index(Request $request, string $objectType)
{
Log::debug(sprintf('Now at %s', __METHOD__));
$objectType = $objectType ?? 'asset';
$subTitle = (string) trans(sprintf('firefly.%s_accounts', $objectType));
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType));
$types = config(sprintf('firefly.accountTypesByIdentifier.%s', $objectType));

View File

@ -90,7 +90,7 @@ class ReconcileController extends Controller
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
public function reconcile(Account $account, Carbon $start = null, Carbon $end = null)
public function reconcile(Account $account, Carbon $start = null, Carbon $end = null) // @phpstan-ignore-line
{
if (!$this->isEditableAccount($account)) {
return $this->redirectAccountToAccount($account);

View File

@ -88,7 +88,7 @@ class ShowController extends Controller
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
public function show(Request $request, Account $account, Carbon $start = null, Carbon $end = null)
public function show(Request $request, Account $account, Carbon $start = null, Carbon $end = null) // @phpstan-ignore-line
{
$objectType = config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type));

View File

@ -81,8 +81,6 @@ class LoginController extends Controller
*
* @param Request $request
*
* @return JsonResponse|RedirectResponse
*
* @throws ValidationException
*/
public function login(Request $request)

View File

@ -126,7 +126,7 @@ class ResetPasswordController extends Controller
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
public function showResetForm(Request $request, $token = null)
public function showResetForm(Request $request, $token = null) // @phpstan-ignore-line
{
$loginProvider = config('firefly.login_provider');
if ('eloquent' !== $loginProvider) {

View File

@ -96,7 +96,7 @@ class IndexController extends Controller
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
public function index(Request $request, Carbon $start = null, Carbon $end = null)
public function index(Request $request, Carbon $start = null, Carbon $end = null) // @phpstan-ignore-line
{
Log::debug('Start of IndexController::index()');
@ -122,7 +122,7 @@ class IndexController extends Controller
$sums = $this->getSums($budgets);
// get budgeted for default currency:
if (empty($availableBudgets)) {
if (0 === count($availableBudgets)) {
$budgeted = $this->blRepository->budgeted($start, $end, $defaultCurrency, );
$spentArr = $this->opsRepository->sumExpenses($start, $end, null, null, $defaultCurrency);
$spent = $spentArr[$defaultCurrency->id]['sum'] ?? '0';

View File

@ -84,7 +84,7 @@ class ShowController extends Controller
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
public function noBudget(Request $request, Carbon $start = null, Carbon $end = null)
public function noBudget(Request $request, Carbon $start = null, Carbon $end = null)// @phpstan-ignore-line
{
/** @var Carbon $start */
$start = $start ?? session('start');

View File

@ -80,7 +80,7 @@ class NoCategoryController extends Controller
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
public function show(Request $request, Carbon $start = null, Carbon $end = null)
public function show(Request $request, Carbon $start = null, Carbon $end = null)// @phpstan-ignore-line
{
Log::debug('Start of noCategory()');
/** @var Carbon $start */

View File

@ -82,7 +82,7 @@ class ShowController extends Controller
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
public function show(Request $request, Category $category, Carbon $start = null, Carbon $end = null)
public function show(Request $request, Category $category, Carbon $start = null, Carbon $end = null) // @phpstan-ignore-line
{
/** @var Carbon $start */
$start = $start ?? session('start', Carbon::now()->startOfMonth());

View File

@ -1,4 +1,5 @@
<?php
/**
* AccountController.php
* Copyright (c) 2019 james@firefly-iii.org
@ -114,14 +115,14 @@ class AccountController extends Controller
// loop the end balances. This is an array for each account ($expenses)
foreach ($endBalances as $accountId => $expenses) {
$accountId = (int) $accountId;
$accountId = (int)$accountId;
// loop each expense entry (each entry can be a different currency).
foreach ($expenses as $currencyId => $endAmount) {
$currencyId = (int) $currencyId;
$currencyId = (int)$currencyId;
// see if there is an accompanying start amount.
// grab the difference and find the currency.
$startAmount = (string) ($startBalances[$accountId][$currencyId] ?? '0');
$startAmount = (string)($startBalances[$accountId][$currencyId] ?? '0');
$diff = bcsub((string)$endAmount, $startAmount);
$currencies[$currencyId] = $currencies[$currencyId] ?? $this->currencyRepository->find($currencyId);
if (0 !== bccomp($diff, '0')) {
@ -129,7 +130,7 @@ class AccountController extends Controller
$tempData[] = [
'name' => $accountNames[$accountId],
'difference' => $diff,
'diff_float' => (float) $diff,
'diff_float' => (float)$diff,
'currency_id' => $currencyId,
];
}
@ -142,13 +143,13 @@ class AccountController extends Controller
// loop all found currencies and build the data array for the chart.
/**
* @var int $currencyId
* @var int $currencyId
* @var TransactionCurrency $currency
*/
foreach ($currencies as $currencyId => $currency) {
$dataSet
= [
'label' => (string) trans('firefly.spent'),
'label' => (string)trans('firefly.spent'),
'type' => 'bar',
'currency_symbol' => $currency->symbol,
'currency_code' => $currency->code,
@ -173,8 +174,8 @@ class AccountController extends Controller
/**
* Expenses per budget for all time, as shown on account overview.
*
* @param AccountRepositoryInterface $repository
* @param Account $account
* @param AccountRepositoryInterface $repository
* @param Account $account
*
* @return JsonResponse
* @throws JsonException
@ -190,9 +191,9 @@ class AccountController extends Controller
/**
* Expenses per budget, as shown on account overview.
*
* @param Account $account
* @param Carbon $start
* @param Carbon $end
* @param Account $account
* @param Carbon $start
* @param Carbon $end
*
* @return JsonResponse
*/
@ -215,7 +216,7 @@ class AccountController extends Controller
$budgetIds = [];
/** @var array $journal */
foreach ($journals as $journal) {
$budgetId = (int) $journal['budget_id'];
$budgetId = (int)$journal['budget_id'];
$key = sprintf('%d-%d', $budgetId, $journal['currency_id']);
$budgetIds[] = $budgetId;
if (!array_key_exists($key, $result)) {
@ -235,7 +236,7 @@ class AccountController extends Controller
foreach ($result as $row) {
$budgetId = $row['budget_id'];
$name = $names[$budgetId];
$label = (string) trans('firefly.name_in_currency', ['name' => $name, 'currency' => $row['currency_name']]);
$label = (string)trans('firefly.name_in_currency', ['name' => $name, 'currency' => $row['currency_name']]);
$chartData[$label] = ['amount' => $row['total'], 'currency_symbol' => $row['currency_symbol'], 'currency_code' => $row['currency_code']];
}
@ -248,8 +249,8 @@ class AccountController extends Controller
/**
* Expenses grouped by category for account.
*
* @param AccountRepositoryInterface $repository
* @param Account $account
* @param AccountRepositoryInterface $repository
* @param Account $account
*
* @return JsonResponse
* @throws JsonException
@ -265,9 +266,9 @@ class AccountController extends Controller
/**
* Expenses per category for one single account.
*
* @param Account $account
* @param Carbon $start
* @param Carbon $end
* @param Account $account
* @param Carbon $start
* @param Carbon $end
*
* @return JsonResponse
*/
@ -295,7 +296,7 @@ class AccountController extends Controller
if (!array_key_exists($key, $result)) {
$result[$key] = [
'total' => '0',
'category_id' => (int) $journal['category_id'],
'category_id' => (int)$journal['category_id'],
'currency_name' => $journal['currency_name'],
'currency_symbol' => $journal['currency_symbol'],
'currency_code' => $journal['currency_code'],
@ -308,7 +309,7 @@ class AccountController extends Controller
foreach ($result as $row) {
$categoryId = $row['category_id'];
$name = $names[$categoryId] ?? '(unknown)';
$label = (string) trans('firefly.name_in_currency', ['name' => $name, 'currency' => $row['currency_name']]);
$label = (string)trans('firefly.name_in_currency', ['name' => $name, 'currency' => $row['currency_name']]);
$chartData[$label] = ['amount' => $row['total'], 'currency_symbol' => $row['currency_symbol'], 'currency_code' => $row['currency_code']];
}
@ -321,7 +322,7 @@ class AccountController extends Controller
/**
* Shows the balances for all the user's frontpage accounts.
*
* @param AccountRepositoryInterface $repository
* @param AccountRepositoryInterface $repository
*
* @return JsonResponse
* @throws FireflyException
@ -337,7 +338,7 @@ class AccountController extends Controller
Log::debug('Default set is ', $defaultSet);
$frontPage = app('preferences')->get('frontPageAccounts', $defaultSet);
Log::debug('Frontpage preference set is ', $frontPage->data);
if (empty($frontPage->data)) {
if (0 === count($frontPage->data)) {
app('preferences')->set('frontPageAccounts', $defaultSet);
Log::debug('frontpage set is empty!');
}
@ -349,8 +350,8 @@ class AccountController extends Controller
/**
* Shows the income grouped by category for an account, in all time.
*
* @param AccountRepositoryInterface $repository
* @param Account $account
* @param AccountRepositoryInterface $repository
* @param Account $account
*
* @return JsonResponse
* @throws JsonException
@ -366,9 +367,9 @@ class AccountController extends Controller
/**
* Shows all income per account for each category.
*
* @param Account $account
* @param Carbon $start
* @param Carbon $end
* @param Account $account
* @param Carbon $start
* @param Carbon $end
*
* @return JsonResponse
*/
@ -410,7 +411,7 @@ class AccountController extends Controller
foreach ($result as $row) {
$categoryId = $row['category_id'];
$name = $names[$categoryId] ?? '(unknown)';
$label = (string) trans('firefly.name_in_currency', ['name' => $name, 'currency' => $row['currency_name']]);
$label = (string)trans('firefly.name_in_currency', ['name' => $name, 'currency' => $row['currency_name']]);
$chartData[$label] = ['amount' => $row['total'], 'currency_symbol' => $row['currency_symbol'], 'currency_code' => $row['currency_code']];
}
$data = $this->generator->multiCurrencyPieChart($chartData);
@ -422,10 +423,10 @@ class AccountController extends Controller
/**
* Shows overview of account during a single period.
*
* @param Account $account
* @param Carbon $start
* @param Account $account
* @param Carbon $start
*
* @param Carbon $end
* @param Carbon $end
*
* @return JsonResponse
* @throws FireflyException
@ -461,10 +462,10 @@ class AccountController extends Controller
}
/**
* @param Carbon $start
* @param Carbon $end
* @param Account $account
* @param TransactionCurrency $currency
* @param Carbon $start
* @param Carbon $end
* @param Account $account
* @param TransactionCurrency $currency
*
* @return array
* @throws FireflyException
@ -478,38 +479,31 @@ class AccountController extends Controller
'label' => sprintf('%s (%s)', $account->name, $currency->symbol),
'currency_symbol' => $currency->symbol,
'currency_code' => $currency->code,
'entries' => [],
];
$entries = [];
$current = clone $start;
switch ($step) {
default:
break;
case '1D':
// per day the entire period, balance for every day.
$format = (string) trans('config.month_and_day_js', [], $locale);
$range = app('steam')->balanceInRange($account, $start, $end, $currency);
$previous = array_values($range)[0];
while ($end >= $current) {
$theDate = $current->format('Y-m-d');
$balance = $range[$theDate] ?? $previous;
$label = $current->isoFormat($format);
$entries[$label] = (float) $balance;
$previous = $balance;
$current->addDay();
}
break;
case '1W':
case '1M':
case '1Y':
while ($end >= $current) {
$balance = (float) app('steam')->balance($account, $current, $currency);
$label = app('navigation')->periodShow($current, $step);
$entries[$label] = $balance;
$current = app('navigation')->addPeriod($current, $step, 0);
}
break;
if ('1D' === $step) {
// per day the entire period, balance for every day.
$format = (string)trans('config.month_and_day_js', [], $locale);
$range = app('steam')->balanceInRange($account, $start, $end, $currency);
$previous = array_values($range)[0];
while ($end >= $current) {
$theDate = $current->format('Y-m-d');
$balance = $range[$theDate] ?? $previous;
$label = $current->isoFormat($format);
$entries[$label] = (float)$balance;
$previous = $balance;
$current->addDay();
}
}
if ('1W' === $step || '1M' === $step || '1Y' === $step) {
while ($end >= $current) {
$balance = (float)app('steam')->balance($account, $current, $currency);
$label = app('navigation')->periodShow($current, $step);
$entries[$label] = $balance;
$current = app('navigation')->addPeriod($current, $step, 0);
}
}
$result['entries'] = $entries;
@ -521,10 +515,10 @@ class AccountController extends Controller
*
* TODO this chart is not multi currency aware.
*
* @param Collection $accounts
* @param Collection $accounts
*
* @param Carbon $start
* @param Carbon $end
* @param Carbon $start
* @param Carbon $end
* @return JsonResponse
* @throws FireflyException
* @throws JsonException
@ -572,22 +566,22 @@ class AccountController extends Controller
// loop the end balances. This is an array for each account ($expenses)
foreach ($endBalances as $accountId => $expenses) {
$accountId = (int) $accountId;
$accountId = (int)$accountId;
// loop each expense entry (each entry can be a different currency).
foreach ($expenses as $currencyId => $endAmount) {
$currencyId = (int) $currencyId;
$currencyId = (int)$currencyId;
// see if there is an accompanying start amount.
// grab the difference and find the currency.
$startAmount = (string)($startBalances[$accountId][$currencyId] ?? '0');
$diff = bcsub((string) $endAmount, $startAmount);
$diff = bcsub((string)$endAmount, $startAmount);
$currencies[$currencyId] = $currencies[$currencyId] ?? $this->currencyRepository->find($currencyId);
if (0 !== bccomp($diff, '0')) {
// store the values in a temporary array.
$tempData[] = [
'name' => $accountNames[$accountId],
'difference' => $diff,
'diff_float' => (float) $diff,
'diff_float' => (float)$diff,
'currency_id' => $currencyId,
];
}
@ -600,13 +594,13 @@ class AccountController extends Controller
// loop all found currencies and build the data array for the chart.
/**
* @var int $currencyId
* @var int $currencyId
* @var TransactionCurrency $currency
*/
foreach ($currencies as $currencyId => $currency) {
$dataSet
= [
'label' => (string) trans('firefly.earned'),
'label' => (string)trans('firefly.earned'),
'type' => 'bar',
'currency_symbol' => $currency->symbol,
'currency_code' => $currency->code,

View File

@ -205,7 +205,7 @@ class BudgetController extends Controller
*
* @return JsonResponse
*/
public function expenseAsset(Budget $budget, ?BudgetLimit $budgetLimit = null): JsonResponse
public function expenseAsset(Budget $budget, ?BudgetLimit $budgetLimit = null): JsonResponse // @phpstan-ignore-line
{
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
@ -273,7 +273,7 @@ class BudgetController extends Controller
*
* @return JsonResponse
*/
public function expenseCategory(Budget $budget, ?BudgetLimit $budgetLimit = null): JsonResponse
public function expenseCategory(Budget $budget, ?BudgetLimit $budgetLimit = null): JsonResponse // @phpstan-ignore-line
{
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
@ -337,7 +337,7 @@ class BudgetController extends Controller
*
* @return JsonResponse
*/
public function expenseExpense(Budget $budget, ?BudgetLimit $budgetLimit = null): JsonResponse
public function expenseExpense(Budget $budget, ?BudgetLimit $budgetLimit = null): JsonResponse // @phpstan-ignore-line
{
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);

View File

@ -1,4 +1,5 @@
<?php
/**
* CategoryController.php
* Copyright (c) 2019 james@firefly-iii.org
@ -23,7 +24,6 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Chart;
use Carbon\Carbon;
use Exception;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Http\Controllers\Controller;
@ -39,7 +39,6 @@ use FireflyIII\Support\Http\Controllers\ChartGeneration;
use FireflyIII\Support\Http\Controllers\DateCalculation;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Collection;
use JsonException;
/**
* Class CategoryController.
@ -69,7 +68,7 @@ class CategoryController extends Controller
* Show an overview for a category for all time, per month/week/year.
* TODO test method, for category refactor.
*
* @param Category $category
* @param Category $category
*
* @return JsonResponse
* @throws FireflyException
@ -106,14 +105,7 @@ class CategoryController extends Controller
*/
private function getDate(): Carbon
{
$carbon = null;
try {
$carbon = today(config('app.timezone'));
} catch (Exception $e) {
// @ignoreException
}
return $carbon;
return today(config('app.timezone'));
}
/**
@ -147,10 +139,10 @@ class CategoryController extends Controller
* Chart report.
* TODO test method for category refactor.
*
* @param Category $category
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
* @param Category $category
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return JsonResponse
*/
@ -175,10 +167,10 @@ class CategoryController extends Controller
/**
* Generate report chart for either with or without category.
*
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
* @param Category|null $category
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
* @param Category|null $category
*
* @return array
*/
@ -199,7 +191,7 @@ class CategoryController extends Controller
if (null !== $category) {
/** @var OperationsRepositoryInterface $opsRepository */
$opsRepository = app(OperationsRepositoryInterface::class);
$categoryId = (int) $category->id;
$categoryId = (int)$category->id;
// this gives us all currencies
$collection = new Collection([$category]);
$expenses = $opsRepository->listExpenses($start, $end, null, $collection);
@ -217,7 +209,7 @@ class CategoryController extends Controller
$inKey = sprintf('%d-in', $currencyId);
$chartData[$outKey]
= [
'label' => sprintf('%s (%s)', (string) trans('firefly.spent'), $currencyInfo['currency_name']),
'label' => sprintf('%s (%s)', (string)trans('firefly.spent'), $currencyInfo['currency_name']),
'entries' => [],
'type' => 'bar',
'backgroundColor' => 'rgba(219, 68, 55, 0.5)', // red
@ -225,7 +217,7 @@ class CategoryController extends Controller
$chartData[$inKey]
= [
'label' => sprintf('%s (%s)', (string) trans('firefly.earned'), $currencyInfo['currency_name']),
'label' => sprintf('%s (%s)', (string)trans('firefly.earned'), $currencyInfo['currency_name']),
'entries' => [],
'type' => 'bar',
'backgroundColor' => 'rgba(0, 141, 76, 0.5)', // green
@ -262,9 +254,9 @@ class CategoryController extends Controller
* Chart for period for transactions without a category.
* TODO test me.
*
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return JsonResponse
*/
@ -289,8 +281,8 @@ class CategoryController extends Controller
* Chart for a specific period.
* TODO test me, for category refactor.
*
* @param Category $category
* @param Carbon $date
* @param Category $category
* @param Carbon $date
*
* @return JsonResponse
* @throws FireflyException

View File

@ -318,7 +318,7 @@ class DoubleReportController extends Controller
$journalId = $journal['transaction_journal_id'];
// no tags? also deserves a sport
if (empty($journal['tags'])) {
if (0 === count($journal['tags'])) {
$includedJournals[] = $journalId;
// do something
$tagName = trans('firefly.no_tags');
@ -378,7 +378,7 @@ class DoubleReportController extends Controller
$journalId = $journal['transaction_journal_id'];
// no tags? also deserves a sport
if (empty($journal['tags'])) {
if (0 === count($journal['tags'])) {
$includedJournals[] = $journalId;
// do something
$tagName = trans('firefly.no_tags');

View File

@ -189,7 +189,7 @@ class ExpenseReportController extends Controller
$newSet[$key] = $entry;
}
}
if (empty($newSet)) {
if (0 === count($newSet)) {
$newSet = $chartData;
}
$data = $this->generator->multiSet($newSet);

View File

@ -115,20 +115,17 @@ class TransactionController extends Controller
$collector = app(GroupCollectorInterface::class);
$collector->setRange($start, $end);
$collector->withCategoryInformation();
switch ($objectType) {
default:
throw new FireflyException(sprintf('Cant handle "%s"', $objectType));
case 'withdrawal':
$collector->setTypes([TransactionType::WITHDRAWAL]);
break;
case 'deposit':
$collector->setTypes([TransactionType::DEPOSIT]);
break;
case 'transfers':
case 'transfer':
$collector->setTypes([TransactionType::TRANSFER]);
break;
if ('withdrawal' === $objectType) {
$collector->setTypes([TransactionType::WITHDRAWAL]);
}
if ('deposit' === $objectType) {
$collector->setTypes([TransactionType::DEPOSIT]);
}
if ('transfer' === $objectType || 'transfers' === $objectType) {
$collector->setTypes([TransactionType::TRANSFER]);
}
$result = $collector->getExtractedJournals();
$data = [];
@ -172,20 +169,17 @@ class TransactionController extends Controller
$collector = app(GroupCollectorInterface::class);
$collector->setRange($start, $end);
$collector->withAccountInformation();
switch ($objectType) {
default:
throw new FireflyException(sprintf('Cant handle "%s"', $objectType));
case 'withdrawal':
$collector->setTypes([TransactionType::WITHDRAWAL]);
break;
case 'deposit':
$collector->setTypes([TransactionType::DEPOSIT]);
break;
case 'transfers':
case 'transfer':
$collector->setTypes([TransactionType::TRANSFER]);
break;
if ('withdrawal' === $objectType) {
$collector->setTypes([TransactionType::WITHDRAWAL]);
}
if ('deposit' === $objectType) {
$collector->setTypes([TransactionType::DEPOSIT]);
}
if ('transfer' === $objectType || 'transfers' === $objectType) {
$collector->setTypes([TransactionType::TRANSFER]);
}
$result = $collector->getExtractedJournals();
$data = [];
@ -229,20 +223,17 @@ class TransactionController extends Controller
$collector = app(GroupCollectorInterface::class);
$collector->setRange($start, $end);
$collector->withAccountInformation();
switch ($objectType) {
default:
throw new FireflyException(sprintf('Cant handle "%s"', $objectType));
case 'withdrawal':
$collector->setTypes([TransactionType::WITHDRAWAL]);
break;
case 'deposit':
$collector->setTypes([TransactionType::DEPOSIT]);
break;
case 'transfers':
case 'transfer':
$collector->setTypes([TransactionType::TRANSFER]);
break;
if ('withdrawal' === $objectType) {
$collector->setTypes([TransactionType::WITHDRAWAL]);
}
if ('deposit' === $objectType) {
$collector->setTypes([TransactionType::DEPOSIT]);
}
if ('transfer' === $objectType || 'transfers' === $objectType) {
$collector->setTypes([TransactionType::TRANSFER]);
}
$result = $collector->getExtractedJournals();
$data = [];

View File

@ -98,7 +98,7 @@ class DebugController extends Controller
Log::debug('Call twig:clean...');
try {
Artisan::call('twig:clean');
} catch (Exception $e) {
} catch (Exception $e) { // @phpstan-ignore-line
// @ignoreException
}
@ -188,7 +188,7 @@ class DebugController extends Controller
if (null !== $logFile) {
try {
$logContent = file_get_contents($logFile);
} catch (Exception $e) {
} catch (Exception $e) { // @phpstan-ignore-line
// @ignoreException
}
}

View File

@ -190,7 +190,7 @@ class BoxController extends Controller
$incomes[$currencyId] = app('amount')->formatAnything($currency, $incomes[$currencyId] ?? '0', false);
$expenses[$currencyId] = app('amount')->formatAnything($currency, $expenses[$currencyId] ?? '0', false);
}
if (empty($sums)) {
if (0 === count($sums)) {
$currency = app('amount')->getDefaultCurrency();
$sums[$currency->id] = app('amount')->formatAnything($currency, '0', false);
$incomes[$currency->id] = app('amount')->formatAnything($currency, '0', false);

View File

@ -68,7 +68,7 @@ class FrontpageController extends Controller
}
}
$html = '';
if (!empty($info)) {
if (0 !== count($info)) {
try {
$html = view('json.piggy-banks', compact('info'))->render();
} catch (Throwable $e) {

View File

@ -43,13 +43,13 @@ class IntroController extends Controller
*
* @return JsonResponse
*/
public function getIntroSteps(string $route, string $specificPage = null): JsonResponse
public function getIntroSteps(string $route, string $specificPage = null): JsonResponse // @phpstan-ignore-line
{
Log::debug(sprintf('getIntroSteps for route "%s" and page "%s"', $route, $specificPage));
$specificPage = $specificPage ?? '';
$steps = $this->getBasicSteps($route);
$specificSteps = $this->getSpecificSteps($route, $specificPage);
if (empty($specificSteps)) {
if (0 === count($specificSteps)) {
Log::debug(sprintf('No specific steps for route "%s" and page "%s"', $route, $specificPage));
return response()->json($steps);
@ -104,7 +104,7 @@ class IntroController extends Controller
* @return JsonResponse
* @throws FireflyException
*/
public function postEnable(string $route, string $specialPage = null): JsonResponse
public function postEnable(string $route, string $specialPage = null): JsonResponse // @phpstan-ignore-line
{
$specialPage = $specialPage ?? '';
$route = str_replace('.', '_', $route);
@ -128,7 +128,7 @@ class IntroController extends Controller
* @return JsonResponse
* @throws FireflyException
*/
public function postFinished(string $route, string $specialPage = null): JsonResponse
public function postFinished(string $route, string $specialPage = null): JsonResponse // @phpstan-ignore-line
{
$specialPage = $specialPage ?? '';
$key = 'shown_demo_' . $route;

View File

@ -85,7 +85,7 @@ class ReconcileController extends Controller
* @throws FireflyException
* @throws JsonException
*/
public function overview(Request $request, Account $account = null, Carbon $start = null, Carbon $end = null): JsonResponse
public function overview(Request $request, Account $account = null, Carbon $start = null, Carbon $end = null): JsonResponse // @phpstan-ignore-line
{
$startBalance = $request->get('startBalance');
$endBalance = $request->get('endBalance');
@ -226,7 +226,7 @@ class ReconcileController extends Controller
* @throws FireflyException
* @throws JsonException
*/
public function transactions(Account $account, Carbon $start = null, Carbon $end = null)
public function transactions(Account $account, Carbon $start = null, Carbon $end = null) // @phpstan-ignore-line
{
if (null === $start || null === $end) {
throw new FireflyException('Invalid dates submitted.');

View File

@ -127,7 +127,7 @@ class PreferencesController extends Controller
$locales = ['equal' => (string) trans('firefly.equal_to_language')] + $locales;
// an important fallback is that the frontPageAccount array gets refilled automatically
// when it turns up empty.
if (empty($frontPageAccounts->data)) {
if (0 === count($frontPageAccounts->data)) {
$frontPageAccounts = $accountIds;
}

View File

@ -728,7 +728,7 @@ class CategoryController extends Controller
} catch (Throwable $e) {
Log::debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());
throw new FireflyException($result, 0, $e);
throw new FireflyException($e->getMessage(), 0, $e);
}
return $result;
@ -778,7 +778,7 @@ class CategoryController extends Controller
} catch (Throwable $e) {
Log::debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());
throw new FireflyException($result, 0, $e);
throw new FireflyException($e->getMessage(), 0, $e);
}
return $result;

View File

@ -115,7 +115,7 @@ class DoubleController extends Controller
} catch (Throwable $e) {
Log::debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());
throw new FireflyException($result, 0, $e);
throw new FireflyException($e->getMessage(), 0, $e);
}
return $result;
@ -167,7 +167,7 @@ class DoubleController extends Controller
} catch (Throwable $e) {
Log::debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());
throw new FireflyException($result, 0, $e);
throw new FireflyException($e->getMessage(), 0, $e);
}
return $result;
@ -461,7 +461,7 @@ class DoubleController extends Controller
} catch (Throwable $e) {
Log::debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());
throw new FireflyException($result, 0, $e);
throw new FireflyException($e->getMessage(), 0, $e);
}
return $result;
@ -511,7 +511,7 @@ class DoubleController extends Controller
} catch (Throwable $e) {
Log::debug(sprintf('Could not render reports.partials.budget-period: %s', $e->getMessage()));
$result = sprintf('Could not render view: %s', $e->getMessage());
throw new FireflyException($result, 0, $e);
throw new FireflyException($e->getMessage(), 0, $e);
}
return $result;

View File

@ -145,7 +145,7 @@ class SelectController extends Controller
$textTriggers = $this->getValidTriggerList($request);
// warn if nothing.
if (empty($textTriggers)) {
if (0 === count($textTriggers)) {
return response()->json(['html' => '', 'warning' => (string) trans('firefly.warning_no_valid_triggers')]);
}
@ -169,7 +169,7 @@ class SelectController extends Controller
// Warn the user if only a subset of transactions is returned
$warning = '';
if (empty($collection)) {
if (0 === count($collection)) {
$warning = (string) trans('firefly.warning_no_matching_transactions');
}
@ -200,7 +200,7 @@ class SelectController extends Controller
{
$triggers = $rule->ruleTriggers;
if (empty($triggers)) {
if (0 === count($triggers)) {
return response()->json(['html' => '', 'warning' => (string) trans('firefly.warning_no_valid_triggers')]);
}
// create new rule engine:
@ -212,7 +212,7 @@ class SelectController extends Controller
$collection = $collection->slice(0, 20);
$warning = '';
if (empty($collection)) {
if (0 === count($collection)) {
$warning = (string) trans('firefly.warning_no_matching_transactions');
}

View File

@ -87,7 +87,7 @@ class Authenticate
*/
protected function authenticate($request, array $guards)
{
if (empty($guards)) {
if (0 === count($guards)) {
try {
// go for default guard:
if ($this->auth->check()) {

View File

@ -296,7 +296,7 @@ class TransactionJournal extends Model
if (!self::isJoined($query, 'transaction_types')) {
$query->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id');
}
if (!empty($types)) {
if (0 !== count($types)) {
$query->whereIn('transaction_types.type', $types);
}
}

View File

@ -142,7 +142,7 @@ class AccountRepository implements AccountRepositoryInterface
}
);
if (!empty($types)) {
if (0 !== count($types)) {
$dbQuery->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$dbQuery->whereIn('account_types.type', $types);
}
@ -160,7 +160,7 @@ class AccountRepository implements AccountRepositoryInterface
{
$query = $this->user->accounts()->where('iban', '!=', '')->whereNotNull('iban');
if (!empty($types)) {
if (0 !== count($types)) {
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$query->whereIn('account_types.type', $types);
}
@ -178,7 +178,7 @@ class AccountRepository implements AccountRepositoryInterface
{
$query = $this->user->accounts();
if (!empty($types)) {
if (0 !== count($types)) {
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$query->whereIn('account_types.type', $types);
}
@ -218,7 +218,7 @@ class AccountRepository implements AccountRepositoryInterface
{
$query = $this->user->accounts();
if (!empty($accountIds)) {
if (0 !== count($accountIds)) {
$query->whereIn('accounts.id', $accountIds);
}
$query->orderBy('accounts.order', 'ASC');
@ -240,7 +240,7 @@ class AccountRepository implements AccountRepositoryInterface
$query->where('name', 'account_role');
}, 'attachments']
);
if (!empty($types)) {
if (0 !== count($types)) {
$query->accountTypeIn($types);
}
$query->where('active', true);
@ -316,7 +316,7 @@ class AccountRepository implements AccountRepositoryInterface
$query->where('name', 'account_role');
}]
);
if (!empty($types)) {
if (0 !== count($types)) {
$query->accountTypeIn($types);
}
$query->where('active', 0);
@ -585,19 +585,19 @@ class AccountRepository implements AccountRepositoryInterface
{
$res = array_intersect([AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT], $types);
$query = $this->user->accounts();
if (!empty($types)) {
if (0 !== count($types)) {
$query->accountTypeIn($types);
}
// add sort parameters. At this point they're filtered to allowed fields to sort by:
if (!empty($sort)) {
if (0 !== count($sort)) {
foreach ($sort as $param) {
$query->orderBy($param[0], $param[1]);
}
}
if (empty($sort)) {
if (!empty($res)) {
if (0 === count($sort)) {
if (0 !== count($res)) {
$query->orderBy('accounts.order', 'ASC');
}
$query->orderBy('accounts.active', 'DESC');
@ -698,7 +698,7 @@ class AccountRepository implements AccountRepositoryInterface
$dbQuery->where('name', 'LIKE', $search);
}
}
if (!empty($types)) {
if (0 !== count($types)) {
$dbQuery->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$dbQuery->whereIn('account_types.type', $types);
}
@ -736,7 +736,7 @@ class AccountRepository implements AccountRepositoryInterface
);
}
}
if (!empty($types)) {
if (0 !== count($types)) {
$dbQuery->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
$dbQuery->whereIn('account_types.type', $types);
}

View File

@ -332,7 +332,7 @@ class RecurringRepository implements RecurringRepositoryInterface
foreach ($journalMeta as $journalId) {
$search[] = (int) $journalId;
}
if (empty($search)) {
if (0 === count($search)) {
return new Collection();
}

View File

@ -68,7 +68,7 @@ class CreditRecalculateService
// work based on account.
$this->processAccount();
}
if (empty($this->work)) {
if (0 === count($this->work)) {
Log::debug('No work accounts, do not do CreditRecalculationService');
return;
@ -84,7 +84,7 @@ class CreditRecalculateService
{
/** @var TransactionJournal $journal */
foreach ($this->group->transactionJournals as $journal) {
if (empty($this->work)) {
if (0 === count($this->work)) {
try {
$this->findByJournal($journal);
} catch (FireflyException $e) {

View File

@ -339,7 +339,7 @@ trait RecurringTransactionTrait
*/
protected function updateTags(RecurrenceTransaction $transaction, array $tags): void
{
if (!empty($tags)) {
if (0 !== count($tags)) {
/** @var RecurrenceMeta|null $entry */
$entry = $transaction->recurrenceTransactionMeta()->where('name', 'tags')->first();
if (null === $entry) {
@ -348,7 +348,7 @@ trait RecurringTransactionTrait
$entry->value = json_encode($tags);
$entry->save();
}
if (empty($tags)) {
if (0 === count($tags)) {
// delete if present
$transaction->recurrenceTransactionMeta()->where('name', 'tags')->delete();
}

View File

@ -60,7 +60,7 @@ class GroupUpdateService
}
if (empty($transactions)) {
if (0 === count($transactions)) {
Log::debug('No transactions submitted, do nothing.');
return $transactionGroup;
@ -119,7 +119,7 @@ class GroupUpdateService
private function updateTransactionJournal(TransactionGroup $transactionGroup, TransactionJournal $journal, array $data): void
{
Log::debug(sprintf('Now in %s', __METHOD__));
if (empty($data)) {
if (0 === count($data)) {
return;
}
if (1 === count($data) && array_key_exists('transaction_journal_id', $data)) {

View File

@ -150,7 +150,7 @@ class RecurrenceUpdateService
private function updateRepetitions(Recurrence $recurrence, array $repetitions): void
{
$originalCount = $recurrence->recurrenceRepetitions()->count();
if (empty($repetitions)) {
if (0 === count($repetitions)) {
// wont drop repetition, rather avoid.
return;
}
@ -228,7 +228,7 @@ class RecurrenceUpdateService
private function updateTransactions(Recurrence $recurrence, array $transactions): void
{
$originalCount = $recurrence->recurrenceTransactions()->count();
if (empty($transactions)) {
if (0 === count($transactions)) {
// wont drop transactions, rather avoid.
return;
}

View File

@ -54,7 +54,7 @@ class BudgetList implements BinderInterface
$list = array_unique(array_map('\intval', explode(',', $value)));
if (empty($list)) {
if (0 === count($list)) {
app('log')->warning('Budget list count is zero, return 404.');
throw new NotFoundHttpException();
}

View File

@ -50,7 +50,7 @@ class CategoryList implements BinderInterface
}
$list = array_unique(array_map('\intval', explode(',', $value)));
if (empty($list)) {
if (0 === count($list)) {
throw new NotFoundHttpException();
}

View File

@ -52,7 +52,7 @@ class JournalList implements BinderInterface
$collector->withCategoryInformation()->withBudgetInformation()->withTagInformation()->withAccountInformation();
$collector->setJournalIds($list);
$result = $collector->getExtractedJournals();
if (empty($result)) {
if (0 === count($result)) {
throw new NotFoundHttpException();
}
@ -69,7 +69,7 @@ class JournalList implements BinderInterface
protected static function parseList(string $value): array
{
$list = array_unique(array_map('\intval', explode(',', $value)));
if (empty($list)) {
if (0 === count($list)) {
throw new NotFoundHttpException();
}

View File

@ -52,7 +52,7 @@ class TagList implements BinderInterface
$list = array_unique(array_map('\strtolower', explode(',', $value)));
Log::debug('List of tags is', $list);
if (empty($list)) {
if (0 === count($list)) {
Log::error('Tag list is empty.');
throw new NotFoundHttpException();
}

View File

@ -767,7 +767,7 @@ class ExportDataGenerator
*/
private function mergeTags(array $tags): string
{
if (empty($tags)) {
if (0 === count($tags)) {
return '';
}
$smol = [];

View File

@ -1993,7 +1993,7 @@ class OperatorQuerySearch implements SearchInterface
*/
public function searchTransactions(): LengthAwarePaginator
{
if (empty($this->getWords()) && empty($this->getOperators())) {
if (0 === count($this->getWords()) && 0 === count($this->getOperators())) {
return new LengthAwarePaginator([], 0, 5, 1);
}

View File

@ -92,7 +92,7 @@ class ActionFactory
*/
protected static function getActionTypes(): array
{
if (empty(self::$actionTypes)) {
if (0 === count(self::$actionTypes)) {
self::$actionTypes = Domain::getRuleActions();
}

View File

@ -126,7 +126,7 @@ trait RecurrenceValidation
$data = $validator->getData();
$repetitions = $data['repetitions'] ?? [];
// need at least one transaction
if (!is_countable($repetitions) || empty($repetitions)) {
if (!is_countable($repetitions) || 0 === count($repetitions)) {
$validator->errors()->add('repetitions', (string) trans('validation.at_least_one_repetition'));
}
}
@ -144,7 +144,7 @@ trait RecurrenceValidation
return;
}
// need at least one transaction
if (empty($repetitions)) {
if (0 === count($repetitions)) {
$validator->errors()->add('repetitions', (string) trans('validation.at_least_one_repetition'));
}
}

View File

@ -312,7 +312,7 @@ trait TransactionValidation
$transactions = $this->getTransactionsArray($validator);
// need at least one transaction
if (empty($transactions)) {
if (0 === count($transactions)) {
$validator->errors()->add('transactions', (string) trans('validation.at_least_one_transaction'));
}
}
@ -327,7 +327,7 @@ trait TransactionValidation
Log::debug('Now in validateOneTransaction()');
$transactions = $this->getTransactionsArray($validator);
// need at least one transaction
if (empty($transactions)) {
if (0 === count($transactions)) {
$validator->errors()->add('transactions.0.description', (string) trans('validation.at_least_one_transaction'));
Log::debug('Added error: at_least_one_transaction.');