mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-03 11:25:18 +00:00
Various issues fixed (SonarQube)
This commit is contained in:
@@ -82,10 +82,9 @@ class TransactionStoreRequest extends FormRequest
|
||||
{
|
||||
$return = [];
|
||||
/**
|
||||
* @var int $index
|
||||
* @var array $transaction
|
||||
*/
|
||||
foreach ($this->get('transactions') as $index => $transaction) {
|
||||
foreach ($this->get('transactions') as $transaction) {
|
||||
$object = new NullArrayObject($transaction);
|
||||
$return[] = [
|
||||
'type' => $this->stringFromValue($object['type']),
|
||||
|
@@ -63,7 +63,6 @@ class TransactionJournalFactory
|
||||
private array $fields;
|
||||
private PiggyBankEventFactory $piggyEventFactory;
|
||||
private PiggyBankRepositoryInterface $piggyRepository;
|
||||
private TransactionFactory $transactionFactory;
|
||||
private TransactionTypeRepositoryInterface $typeRepository;
|
||||
private User $user;
|
||||
|
||||
|
@@ -155,7 +155,7 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
||||
return [
|
||||
'journals' => $journals,
|
||||
'currency' => $currency,
|
||||
'exists' => count($journals) > 0,
|
||||
'exists' => !empty($journals),
|
||||
'end' => $this->end->formatLocalized((string) trans('config.month_and_day', [], $locale)),
|
||||
'endBalance' => app('steam')->balance($account, $this->end),
|
||||
'dayBefore' => $date->formatLocalized((string) trans('config.month_and_day', [], $locale)),
|
||||
|
@@ -224,7 +224,7 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
}
|
||||
Log::debug('Done processing uploads.');
|
||||
}
|
||||
if (!is_array($files) || (is_array($files) && 0 === count($files))) {
|
||||
if (!is_array($files) || empty($files)) {
|
||||
Log::debug('Array of files is not an array. Probably nothing uploaded. Will not store attachments.');
|
||||
}
|
||||
|
||||
|
@@ -267,7 +267,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
*/
|
||||
public function setJournalIds(array $journalIds): GroupCollectorInterface
|
||||
{
|
||||
if (count($journalIds) > 0) {
|
||||
if (!empty($journalIds)) {
|
||||
$this->query->whereIn('transaction_journals.id', $journalIds);
|
||||
}
|
||||
|
||||
|
@@ -116,7 +116,7 @@ class LoginController extends Controller
|
||||
$this->incrementLoginAttempts($request);
|
||||
Log::channel('audit')->info(sprintf('Login failed. Attempt for user "%s" failed.', $request->get('email')));
|
||||
|
||||
return $this->sendFailedLoginResponse($request);
|
||||
$this->sendFailedLoginResponse($request);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -264,10 +264,9 @@ class IndexController extends Controller
|
||||
return [];
|
||||
}
|
||||
/**
|
||||
* @var int $objectGroupId
|
||||
* @var array $array
|
||||
*/
|
||||
foreach ($sums as $objectGroupId => $array) {
|
||||
foreach ($sums as $array) {
|
||||
/**
|
||||
* @var int $currencyId
|
||||
* @var array $entry
|
||||
|
@@ -50,16 +50,11 @@ class BudgetController extends Controller
|
||||
{
|
||||
use DateCalculation, AugumentData;
|
||||
|
||||
/** @var GeneratorInterface Chart generation methods. */
|
||||
protected $generator;
|
||||
/** @var OperationsRepositoryInterface */
|
||||
protected $opsRepository;
|
||||
/** @var BudgetRepositoryInterface The budget repository */
|
||||
protected $repository;
|
||||
/** @var BudgetLimitRepositoryInterface */
|
||||
private $blRepository;
|
||||
/** @var NoBudgetRepositoryInterface */
|
||||
private $nbRepository;
|
||||
protected GeneratorInterface $generator;
|
||||
protected OperationsRepositoryInterface $opsRepository;
|
||||
protected BudgetRepositoryInterface $repository;
|
||||
private BudgetLimitRepositoryInterface $blRepository;
|
||||
private NoBudgetRepositoryInterface $nbRepository;
|
||||
|
||||
/**
|
||||
* BudgetController constructor.
|
||||
@@ -185,12 +180,12 @@ class BudgetController extends Controller
|
||||
while ($start <= $end) {
|
||||
$spent = $this->opsRepository->spentInPeriod($budgetCollection, new Collection, $start, $start);
|
||||
$amount = bcadd($amount, $spent);
|
||||
$format = $start->formatLocalized((string) trans('config.month_and_day', [], $locale));
|
||||
$format = $start->formatLocalized((string)trans('config.month_and_day', [], $locale));
|
||||
$entries[$format] = $amount;
|
||||
|
||||
$start->addDay();
|
||||
}
|
||||
$data = $this->generator->singleSet((string) trans('firefly.left'), $entries);
|
||||
$data = $this->generator->singleSet((string)trans('firefly.left'), $entries);
|
||||
// add currency symbol from budget limit:
|
||||
$data['datasets'][0]['currency_symbol'] = $budgetLimit->transactionCurrency->symbol;
|
||||
$data['datasets'][0]['currency_code'] = $budgetLimit->transactionCurrency->code;
|
||||
@@ -239,7 +234,7 @@ class BudgetController extends Controller
|
||||
|
||||
// group by asset account ID:
|
||||
foreach ($journals as $journal) {
|
||||
$key = sprintf('%d-%d', (int) $journal['source_account_id'], $journal['currency_id']);
|
||||
$key = sprintf('%d-%d', (int)$journal['source_account_id'], $journal['currency_id']);
|
||||
$result[$key] = $result[$key] ?? [
|
||||
'amount' => '0',
|
||||
'currency_symbol' => $journal['currency_symbol'],
|
||||
@@ -252,7 +247,7 @@ class BudgetController extends Controller
|
||||
$names = $this->getAccountNames(array_keys($result));
|
||||
foreach ($result as $combinedId => $info) {
|
||||
$parts = explode('-', $combinedId);
|
||||
$assetId = (int) $parts[0];
|
||||
$assetId = (int)$parts[0];
|
||||
$title = sprintf('%s (%s)', $names[$assetId] ?? '(empty)', $info['currency_name']);
|
||||
$chartData[$title]
|
||||
= [
|
||||
@@ -319,7 +314,7 @@ class BudgetController extends Controller
|
||||
$names = $this->getCategoryNames(array_keys($result));
|
||||
foreach ($result as $combinedId => $info) {
|
||||
$parts = explode('-', $combinedId);
|
||||
$categoryId = (int) $parts[0];
|
||||
$categoryId = (int)$parts[0];
|
||||
$title = sprintf('%s (%s)', $names[$categoryId] ?? '(empty)', $info['currency_name']);
|
||||
$chartData[$title] = [
|
||||
'amount' => $info['amount'],
|
||||
@@ -385,7 +380,7 @@ class BudgetController extends Controller
|
||||
$names = $this->getAccountNames(array_keys($result));
|
||||
foreach ($result as $combinedId => $info) {
|
||||
$parts = explode('-', $combinedId);
|
||||
$opposingId = (int) $parts[0];
|
||||
$opposingId = (int)$parts[0];
|
||||
$name = $names[$opposingId] ?? 'no name';
|
||||
$title = sprintf('%s (%s)', $name, $info['currency_name']);
|
||||
$chartData[$title] = [
|
||||
@@ -422,12 +417,12 @@ class BudgetController extends Controller
|
||||
return response()->json($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$generator = app(FrontpageChartGenerator::class);
|
||||
$generator->setUser(auth()->user());
|
||||
$generator->setStart($start);
|
||||
$generator->setEnd($end);
|
||||
$chartGenerator = app(FrontpageChartGenerator::class);
|
||||
$chartGenerator->setUser(auth()->user());
|
||||
$chartGenerator->setStart($start);
|
||||
$chartGenerator->setEnd($end);
|
||||
|
||||
$chartData = $generator->generate();
|
||||
$chartData = $chartGenerator->generate();
|
||||
$data = $this->generator->multiSet($chartData);
|
||||
$cache->store($data);
|
||||
|
||||
@@ -463,14 +458,14 @@ class BudgetController extends Controller
|
||||
$preferredRange = app('navigation')->preferredRangeFormat($start, $end);
|
||||
$chartData = [
|
||||
[
|
||||
'label' => (string) trans('firefly.box_spent_in_currency', ['currency' => $currency->name]),
|
||||
'label' => (string)trans('firefly.box_spent_in_currency', ['currency' => $currency->name]),
|
||||
'type' => 'bar',
|
||||
'entries' => [],
|
||||
'currency_symbol' => $currency->symbol,
|
||||
'currency_code' => $currency->code,
|
||||
],
|
||||
[
|
||||
'label' => (string) trans('firefly.box_budgeted_in_currency', ['currency' => $currency->name]),
|
||||
'label' => (string)trans('firefly.box_budgeted_in_currency', ['currency' => $currency->name]),
|
||||
'type' => 'bar',
|
||||
'currency_symbol' => $currency->symbol,
|
||||
'currency_code' => $currency->code,
|
||||
@@ -549,7 +544,7 @@ class BudgetController extends Controller
|
||||
$currentStart = app('navigation')->addPeriod($currentStart, $preferredRange, 0);
|
||||
}
|
||||
|
||||
$data = $this->generator->singleSet((string) trans('firefly.spent'), $chartData);
|
||||
$data = $this->generator->singleSet((string)trans('firefly.spent'), $chartData);
|
||||
$cache->store($data);
|
||||
|
||||
return response()->json($data);
|
||||
|
@@ -187,7 +187,7 @@ class ExpenseReportController extends Controller
|
||||
$newSet[$key] = $chartData[$key]; // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
if (0 === count($newSet)) {
|
||||
if (empty($newSet)) {
|
||||
$newSet = $chartData; // @codeCoverageIgnore
|
||||
}
|
||||
$data = $this->generator->multiSet($newSet);
|
||||
|
@@ -193,7 +193,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 (0 === count($sums)) {
|
||||
if (empty($sums)) {
|
||||
$currency = app('amount')->getDefaultCurrency();
|
||||
$sums[$currency->id] = app('amount')->formatAnything($currency, '0', false);
|
||||
$incomes[$currency->id] = app('amount')->formatAnything($currency, '0', false);
|
||||
@@ -257,7 +257,7 @@ class BoxController extends Controller
|
||||
|
||||
|
||||
$return = [];
|
||||
foreach ($netWorthSet as $index => $data) {
|
||||
foreach ($netWorthSet as $data) {
|
||||
/** @var TransactionCurrency $currency */
|
||||
$currency = $data['currency'];
|
||||
$return[$currency->id] = app('amount')->formatAnything($currency, $data['balance'], false);
|
||||
|
@@ -64,7 +64,7 @@ class FrontpageController extends Controller
|
||||
}
|
||||
}
|
||||
$html = '';
|
||||
if (count($info) > 0) {
|
||||
if (!empty($info)) {
|
||||
try {
|
||||
$html = view('json.piggy-banks', compact('info'))->render();
|
||||
// @codeCoverageIgnoreStart
|
||||
|
@@ -67,8 +67,6 @@ class EditController extends Controller
|
||||
{
|
||||
$subTitle = (string) trans('firefly.edit_object_group', ['title' => $objectGroup->title]);
|
||||
$subTitleIcon = 'fa-pencil';
|
||||
$targetDate = null;
|
||||
$startDate = null;
|
||||
|
||||
if (true !== session('object-groups.edit.fromUpdate')) {
|
||||
$this->rememberPreviousUri('object-groups.edit.uri');
|
||||
|
@@ -165,7 +165,6 @@ class BudgetController extends Controller
|
||||
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $budgets);
|
||||
$result = [];
|
||||
foreach ($spent as $currency) {
|
||||
$currencyId = $currency['currency_id'];
|
||||
foreach ($currency['budgets'] as $budget) {
|
||||
foreach ($budget['transaction_journals'] as $journal) {
|
||||
$destinationId = $journal['destination_account_id'];
|
||||
@@ -328,7 +327,6 @@ class BudgetController extends Controller
|
||||
foreach ($expenses as $currency) {
|
||||
foreach ($currency['budgets'] as $budget) {
|
||||
$count = 0;
|
||||
$total = '0';
|
||||
foreach ($budget['transaction_journals'] as $journal) {
|
||||
$count++;
|
||||
$key = sprintf('%d-%d', $budget['id'], $currency['currency_id']);
|
||||
@@ -377,7 +375,6 @@ class BudgetController extends Controller
|
||||
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $budgets);
|
||||
$result = [];
|
||||
foreach ($spent as $currency) {
|
||||
$currencyId = $currency['currency_id'];
|
||||
foreach ($currency['budgets'] as $budget) {
|
||||
foreach ($budget['transaction_journals'] as $journal) {
|
||||
$result[] = [
|
||||
|
@@ -40,10 +40,7 @@ use Throwable;
|
||||
*/
|
||||
class TagController extends Controller
|
||||
{
|
||||
|
||||
|
||||
/** @var OperationsRepositoryInterface */
|
||||
private $opsRepository;
|
||||
private OperationsRepositoryInterface $opsRepository;
|
||||
|
||||
/**
|
||||
* ExpenseReportController constructor.
|
||||
@@ -282,7 +279,6 @@ class TagController extends Controller
|
||||
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $tags);
|
||||
$result = [];
|
||||
foreach ($spent as $currency) {
|
||||
$currencyId = $currency['currency_id'];
|
||||
foreach ($currency['tags'] as $tag) {
|
||||
foreach ($tag['transaction_journals'] as $journal) {
|
||||
$destinationId = $journal['destination_account_id'];
|
||||
@@ -335,7 +331,6 @@ class TagController extends Controller
|
||||
$spent = $this->opsRepository->listIncome($start, $end, $accounts, $tags);
|
||||
$result = [];
|
||||
foreach ($spent as $currency) {
|
||||
$currencyId = $currency['currency_id'];
|
||||
foreach ($currency['tags'] as $tag) {
|
||||
foreach ($tag['transaction_journals'] as $journal) {
|
||||
$sourceId = $journal['source_account_id'];
|
||||
@@ -496,7 +491,6 @@ class TagController extends Controller
|
||||
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $tags);
|
||||
$result = [];
|
||||
foreach ($spent as $currency) {
|
||||
$currencyId = $currency['currency_id'];
|
||||
foreach ($currency['tags'] as $tag) {
|
||||
foreach ($tag['transaction_journals'] as $journal) {
|
||||
$result[] = [
|
||||
@@ -546,7 +540,6 @@ class TagController extends Controller
|
||||
$spent = $this->opsRepository->listIncome($start, $end, $accounts, $tags);
|
||||
$result = [];
|
||||
foreach ($spent as $currency) {
|
||||
$currencyId = $currency['currency_id'];
|
||||
foreach ($currency['tags'] as $tag) {
|
||||
foreach ($tag['transaction_journals'] as $journal) {
|
||||
$result[] = [
|
||||
|
@@ -242,17 +242,15 @@ class ConvertController extends Controller
|
||||
private function getAssetAccounts(): array
|
||||
{
|
||||
// make repositories
|
||||
/** @var AccountRepositoryInterface $accountRepository */
|
||||
$accountRepository = app(AccountRepositoryInterface::class);
|
||||
$accountList = $accountRepository->getActiveAccountsByType([AccountType::ASSET]);
|
||||
$accountList = $this->accountRepository->getActiveAccountsByType([AccountType::ASSET]);
|
||||
$defaultCurrency = app('amount')->getDefaultCurrency();
|
||||
$grouped = [];
|
||||
// group accounts:
|
||||
/** @var Account $account */
|
||||
foreach ($accountList as $account) {
|
||||
$balance = app('steam')->balance($account, today());
|
||||
$currency = $accountRepository->getAccountCurrency($account) ?? $defaultCurrency;
|
||||
$role = (string)$accountRepository->getMetaValue($account, 'account_role');
|
||||
$currency = $this->accountRepository->getAccountCurrency($account) ?? $defaultCurrency;
|
||||
$role = (string)$this->accountRepository->getMetaValue($account, 'account_role');
|
||||
if ('' === $role) {
|
||||
$role = 'no_account_type'; // @codeCoverageIgnore
|
||||
}
|
||||
@@ -271,16 +269,14 @@ class ConvertController extends Controller
|
||||
private function getLiabilities(): array
|
||||
{
|
||||
// make repositories
|
||||
/** @var AccountRepositoryInterface $accountRepository */
|
||||
$accountRepository = app(AccountRepositoryInterface::class);
|
||||
$accountList = $accountRepository->getActiveAccountsByType([AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);
|
||||
$accountList = $this->accountRepository->getActiveAccountsByType([AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);
|
||||
$defaultCurrency = app('amount')->getDefaultCurrency();
|
||||
$grouped = [];
|
||||
// group accounts:
|
||||
/** @var Account $account */
|
||||
foreach ($accountList as $account) {
|
||||
$balance = app('steam')->balance($account, today());
|
||||
$currency = $accountRepository->getAccountCurrency($account) ?? $defaultCurrency;
|
||||
$currency = $this->accountRepository->getAccountCurrency($account) ?? $defaultCurrency;
|
||||
$role = 'l_' . $account->accountType->type;
|
||||
$key = (string)trans('firefly.opt_group_' . $role);
|
||||
$grouped[$key][$account->id] = $account->name . ' (' . app('amount')->formatAnything($currency, $balance, false) . ')';
|
||||
@@ -295,16 +291,14 @@ class ConvertController extends Controller
|
||||
private function getValidDepositSources(): array
|
||||
{
|
||||
// make repositories
|
||||
/** @var AccountRepositoryInterface $accountRepository */
|
||||
$accountRepository = app(AccountRepositoryInterface::class);
|
||||
$liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN];
|
||||
$accountList = $accountRepository
|
||||
$accountList = $this->accountRepository
|
||||
->getActiveAccountsByType([AccountType::REVENUE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);
|
||||
$grouped = [];
|
||||
// group accounts:
|
||||
/** @var Account $account */
|
||||
foreach ($accountList as $account) {
|
||||
$role = (string)$accountRepository->getMetaValue($account, 'account_role');
|
||||
$role = (string)$this->accountRepository->getMetaValue($account, 'account_role');
|
||||
$name = $account->name;
|
||||
if ('' === $role) {
|
||||
$role = 'no_account_type'; // @codeCoverageIgnore
|
||||
@@ -337,17 +331,15 @@ class ConvertController extends Controller
|
||||
private function getValidWithdrawalDests(): array
|
||||
{
|
||||
// make repositories
|
||||
/** @var AccountRepositoryInterface $accountRepository */
|
||||
$accountRepository = app(AccountRepositoryInterface::class);
|
||||
$liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN];
|
||||
$accountList = $accountRepository->getActiveAccountsByType(
|
||||
$accountList = $this->accountRepository->getActiveAccountsByType(
|
||||
[AccountType::EXPENSE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]
|
||||
);
|
||||
$grouped = [];
|
||||
// group accounts:
|
||||
/** @var Account $account */
|
||||
foreach ($accountList as $account) {
|
||||
$role = (string)$accountRepository->getMetaValue($account, 'account_role');
|
||||
$role = (string)$this->accountRepository->getMetaValue($account, 'account_role');
|
||||
$name = $account->name;
|
||||
if ('' === $role) {
|
||||
$role = 'no_account_type'; // @codeCoverageIgnore
|
||||
|
@@ -171,7 +171,7 @@ class ShowController extends Controller
|
||||
{
|
||||
$accounts = [];
|
||||
|
||||
foreach ($group['transactions'] as $index => $transaction) {
|
||||
foreach ($group['transactions'] as $transaction) {
|
||||
$accounts['source'][] = [
|
||||
'type' => $transaction['source_type'],
|
||||
'id' => $transaction['source_id'],
|
||||
|
@@ -354,17 +354,7 @@ class CreateRecurringTransactions implements ShouldQueue
|
||||
$includeWeekend = clone $this->date;
|
||||
$includeWeekend->addDays(2);
|
||||
$occurrences = $this->repository->getOccurrencesInRange($repetition, $recurrence->first_date, $includeWeekend);
|
||||
/*
|
||||
Log::debug(
|
||||
sprintf(
|
||||
'Calculated %d occurrences between %s and %s',
|
||||
count($occurrences),
|
||||
$recurrence->first_date->format('Y-m-d'),
|
||||
$includeWeekend->format('Y-m-d')
|
||||
),
|
||||
$this->debugArray($occurrences)
|
||||
);
|
||||
*/
|
||||
|
||||
unset($includeWeekend);
|
||||
|
||||
$result = $this->handleOccurrences($recurrence, $repetition, $occurrences);
|
||||
|
@@ -70,12 +70,6 @@ class ReportNewJournalsMail extends Mailable
|
||||
*/
|
||||
public function build(): self
|
||||
{
|
||||
$subject = 1 === $this->groups->count()
|
||||
? 'Firefly III has created a new transaction'
|
||||
: sprintf(
|
||||
'Firefly III has created new %d transactions',
|
||||
$this->groups->count()
|
||||
);
|
||||
$this->transform();
|
||||
|
||||
return $this->view('emails.report-new-journals-html')->text('emails.report-new-journals-text')
|
||||
|
@@ -355,7 +355,7 @@ class TransactionJournal extends Model
|
||||
if (!self::isJoined($query, 'transaction_types')) {
|
||||
$query->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id');
|
||||
}
|
||||
if (count($types) > 0) {
|
||||
if (!empty($types)) {
|
||||
$query->whereIn('transaction_types.type', $types);
|
||||
}
|
||||
}
|
||||
|
@@ -128,7 +128,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
->where('account_meta.name', 'account_number')
|
||||
->where('account_meta.data', json_encode($number));
|
||||
|
||||
if (count($types) > 0) {
|
||||
if (!empty($types)) {
|
||||
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
|
||||
$query->whereIn('account_types.type', $types);
|
||||
}
|
||||
@@ -152,7 +152,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
{
|
||||
$query = $this->user->accounts()->where('iban', '!=', '')->whereNotNull('iban');
|
||||
|
||||
if (count($types) > 0) {
|
||||
if (!empty($types)) {
|
||||
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
|
||||
$query->whereIn('account_types.type', $types);
|
||||
}
|
||||
@@ -180,7 +180,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
{
|
||||
$query = $this->user->accounts();
|
||||
|
||||
if (count($types) > 0) {
|
||||
if (!empty($types)) {
|
||||
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
|
||||
$query->whereIn('account_types.type', $types);
|
||||
}
|
||||
@@ -260,7 +260,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
/** @var Collection $result */
|
||||
$query = $this->user->accounts();
|
||||
|
||||
if (count($accountIds) > 0) {
|
||||
if (!empty($accountIds)) {
|
||||
$query->whereIn('accounts.id', $accountIds);
|
||||
}
|
||||
$query->orderBy('accounts.order', 'ASC');
|
||||
@@ -279,7 +279,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
{
|
||||
/** @var Collection $result */
|
||||
$query = $this->user->accounts();
|
||||
if (count($types) > 0) {
|
||||
if (!empty($types)) {
|
||||
$query->accountTypeIn($types);
|
||||
}
|
||||
$query->orderBy('accounts.order', 'ASC');
|
||||
@@ -303,7 +303,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
$query->where('name', 'account_role');
|
||||
}, 'attachments']
|
||||
);
|
||||
if (count($types) > 0) {
|
||||
if (!empty($types)) {
|
||||
$query->accountTypeIn($types);
|
||||
}
|
||||
$query->where('active', 1);
|
||||
@@ -572,7 +572,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
}
|
||||
|
||||
}
|
||||
if (count($types) > 0) {
|
||||
if (!empty($types)) {
|
||||
$dbQuery->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
|
||||
$dbQuery->whereIn('account_types.type', $types);
|
||||
}
|
||||
@@ -630,7 +630,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
$query->where('name', 'account_role');
|
||||
}]
|
||||
);
|
||||
if (count($types) > 0) {
|
||||
if (!empty($types)) {
|
||||
$query->accountTypeIn($types);
|
||||
}
|
||||
$query->where('active', 0);
|
||||
@@ -728,7 +728,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
});
|
||||
}
|
||||
}
|
||||
if (count($types) > 0) {
|
||||
if (!empty($types)) {
|
||||
$dbQuery->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
|
||||
$dbQuery->whereIn('account_types.type', $types);
|
||||
}
|
||||
|
@@ -157,7 +157,6 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
*/
|
||||
public function firstUseDate(Budget $budget): ?Carbon
|
||||
{
|
||||
$oldest = null;
|
||||
$journal = $budget->transactionJournals()->orderBy('date', 'ASC')->first();
|
||||
if (null !== $journal) {
|
||||
return $journal->date;
|
||||
|
@@ -215,7 +215,6 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
*/
|
||||
public function getLinkNoteText(TransactionJournalLink $link): string
|
||||
{
|
||||
$notes = null;
|
||||
/** @var Note $note */
|
||||
$note = $link->notes()->first();
|
||||
if (null !== $note) {
|
||||
|
@@ -60,7 +60,6 @@ trait CreatesObjectGroups
|
||||
*/
|
||||
protected function findOrCreateObjectGroup(string $title): ?ObjectGroup
|
||||
{
|
||||
$group = null;
|
||||
$maxOrder = $this->getObjectGroupMaxOrder();
|
||||
if (!$this->hasObjectGroup($title)) {
|
||||
return ObjectGroup::create(
|
||||
|
@@ -327,7 +327,7 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
foreach ($journalMeta as $journalId) {
|
||||
$search[] = (int)$journalId;
|
||||
}
|
||||
if (0 === count($search)) {
|
||||
if (empty($search)) {
|
||||
|
||||
return new Collection;
|
||||
}
|
||||
|
@@ -476,7 +476,6 @@ class TagRepository implements TagRepositoryInterface
|
||||
*/
|
||||
public function update(Tag $tag, array $data): Tag
|
||||
{
|
||||
$oldTag = $data['tag'];
|
||||
$tag->tag = $data['tag'];
|
||||
$tag->date = $data['date'];
|
||||
$tag->description = $data['description'];
|
||||
|
@@ -275,7 +275,7 @@ trait RecurringTransactionTrait
|
||||
*/
|
||||
protected function updateTags(RecurrenceTransaction $transaction, array $tags): void
|
||||
{
|
||||
if (count($tags) > 0) {
|
||||
if (!empty($tags)) {
|
||||
/** @var RecurrenceMeta $entry */
|
||||
$entry = $transaction->recurrenceTransactionMeta()->where('name', 'tags')->first();
|
||||
if (null === $entry) {
|
||||
@@ -284,7 +284,7 @@ trait RecurringTransactionTrait
|
||||
$entry->value = json_encode($tags);
|
||||
$entry->save();
|
||||
}
|
||||
if (0 === count($tags)) {
|
||||
if (empty($tags)) {
|
||||
// delete if present
|
||||
$transaction->recurrenceTransactionMeta()->where('name', 'tags')->delete();
|
||||
}
|
||||
|
@@ -76,10 +76,6 @@ class JournalUpdateService
|
||||
private $transactionGroup;
|
||||
/** @var TransactionJournal The journal to update. */
|
||||
private $transactionJournal;
|
||||
/** @var Account If new account info is submitted, this array will hold the valid destination. */
|
||||
private $validDestination;
|
||||
/** @var Account If new account info is submitted, this array will hold the valid source. */
|
||||
private $validSource;
|
||||
|
||||
/**
|
||||
* JournalUpdateService constructor.
|
||||
|
@@ -41,8 +41,7 @@ class RecurrenceUpdateService
|
||||
{
|
||||
use TransactionTypeTrait, RecurringTransactionTrait;
|
||||
|
||||
/** @var User */
|
||||
private $user;
|
||||
private User $user;
|
||||
|
||||
/**
|
||||
* Updates a recurrence.
|
||||
@@ -99,7 +98,7 @@ class RecurrenceUpdateService
|
||||
$this->createRepetitions($recurrence, $data['repetitions'] ?? []);
|
||||
}
|
||||
|
||||
// update all transactions (and associated meta-data);
|
||||
// update all transactions (and associated meta-data)
|
||||
if (null !== $data['transactions']) {
|
||||
$this->deleteTransactions($recurrence);
|
||||
$this->createTransactions($recurrence, $data['transactions'] ?? []);
|
||||
|
@@ -57,8 +57,6 @@ class WholePeriodChartGenerator
|
||||
public function generate(Category $category, Carbon $start, Carbon $end): array
|
||||
{
|
||||
$collection = new Collection([$category]);
|
||||
/** @var CategoryRepositoryInterface $repository */
|
||||
$repository = app(CategoryRepositoryInterface::class);
|
||||
|
||||
/** @var OperationsRepositoryInterface $opsRepository */
|
||||
$opsRepository = app(OperationsRepositoryInterface::class);
|
||||
|
@@ -717,7 +717,7 @@ class ExportDataGenerator
|
||||
*/
|
||||
private function mergeTags(array $tags): string
|
||||
{
|
||||
if (0 === count($tags)) {
|
||||
if (empty($tags)) {
|
||||
return '';
|
||||
}
|
||||
$smol = [];
|
||||
|
@@ -129,7 +129,7 @@ trait RequestInformation
|
||||
$triggers = [];
|
||||
$data = $request->get('triggers');
|
||||
if (is_array($data)) {
|
||||
foreach ($data as $index => $triggerInfo) {
|
||||
foreach ($data as $triggerInfo) {
|
||||
$triggers[] = [
|
||||
'type' => $triggerInfo['type'] ?? '',
|
||||
'value' => $triggerInfo['value'] ?? '',
|
||||
|
@@ -154,9 +154,9 @@ class BudgetReportGenerator
|
||||
*/
|
||||
private function generalBudgetReport(): void
|
||||
{
|
||||
$budgets = $this->repository->getBudgets();
|
||||
$budgetList = $this->repository->getBudgets();
|
||||
/** @var Budget $budget */
|
||||
foreach ($budgets as $budget) {
|
||||
foreach ($budgetList as $budget) {
|
||||
$this->processBudget($budget);
|
||||
}
|
||||
}
|
||||
@@ -192,14 +192,14 @@ class BudgetReportGenerator
|
||||
*/
|
||||
private function processLimit(Budget $budget, BudgetLimit $limit): void
|
||||
{
|
||||
$budgetId = (int)$budget->id;
|
||||
$limitId = (int)$limit->id;
|
||||
$currency = $limit->transactionCurrency ?? $this->currency;
|
||||
$currencyId = (int)$currency->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';
|
||||
$budgetId = (int)$budget->id;
|
||||
$limitId = (int)$limit->id;
|
||||
$limitCurrency = $limit->transactionCurrency ?? $this->currency;
|
||||
$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,
|
||||
@@ -212,10 +212,10 @@ class BudgetReportGenerator
|
||||
'left' => $left,
|
||||
'overspent' => $overspent,
|
||||
'currency_id' => $currencyId,
|
||||
'currency_code' => $currency->code,
|
||||
'currency_name' => $currency->name,
|
||||
'currency_symbol' => $currency->symbol,
|
||||
'currency_decimal_places' => $currency->decimal_places,
|
||||
'currency_code' => $limitCurrency->code,
|
||||
'currency_name' => $limitCurrency->name,
|
||||
'currency_symbol' => $limitCurrency->symbol,
|
||||
'currency_decimal_places' => $limitCurrency->decimal_places,
|
||||
];
|
||||
|
||||
// make sum information:
|
||||
@@ -226,10 +226,10 @@ class BudgetReportGenerator
|
||||
'left' => '0',
|
||||
'overspent' => '0',
|
||||
'currency_id' => $currencyId,
|
||||
'currency_code' => $currency->code,
|
||||
'currency_name' => $currency->name,
|
||||
'currency_symbol' => $currency->symbol,
|
||||
'currency_decimal_places' => $currency->decimal_places,
|
||||
'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);
|
||||
|
Reference in New Issue
Block a user