mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-24 04:41:01 +00:00
Various code cleanup.
This commit is contained in:
@@ -125,7 +125,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);
|
||||
}
|
||||
@@ -153,7 +153,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);
|
||||
}
|
||||
@@ -223,7 +223,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
/** @var Collection $result */
|
||||
$query = $this->user->accounts();
|
||||
|
||||
if (!empty($accountIds)) {
|
||||
if (0 !== count($accountIds)) {
|
||||
$query->whereIn('accounts.id', $accountIds);
|
||||
}
|
||||
$query->orderBy('accounts.order', 'ASC');
|
||||
@@ -242,7 +242,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
{
|
||||
/** @var Collection $result */
|
||||
$query = $this->user->accounts();
|
||||
if (!empty($types)) {
|
||||
if (0 !== count($types)) {
|
||||
$query->accountTypeIn($types);
|
||||
}
|
||||
$res = array_intersect([AccountType::ASSET, AccountType::MORTGAGE, AccountType::LOAN, AccountType::DEBT], $types);
|
||||
@@ -269,7 +269,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
$query->where('name', 'account_role');
|
||||
}, 'attachments']
|
||||
);
|
||||
if (!empty($types)) {
|
||||
if (0 !== count($types)) {
|
||||
$query->accountTypeIn($types);
|
||||
}
|
||||
$query->where('active', 1);
|
||||
@@ -330,7 +330,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
$query->where('name', 'account_role');
|
||||
}]
|
||||
);
|
||||
if (!empty($types)) {
|
||||
if (0 !== count($types)) {
|
||||
$query->accountTypeIn($types);
|
||||
}
|
||||
$query->where('active', 0);
|
||||
@@ -668,7 +668,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);
|
||||
}
|
||||
@@ -706,7 +706,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);
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ class AccountTasker implements AccountTaskerInterface
|
||||
$sourceId = (int)$journal['source_account_id'];
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$key = sprintf('%s-%s', $sourceId, $currencyId);
|
||||
if (!isset($report['accounts'][$key])) {
|
||||
if (!array_key_exists($key, $report['accounts'])) {
|
||||
$currencies[$currencyId] = $currencies[$currencyId] ?? $currencyRepos->findNull($currencyId);
|
||||
$report['accounts'][$key] = [
|
||||
'id' => $sourceId,
|
||||
|
||||
@@ -59,8 +59,8 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
$path = $helper->getAttachmentLocation($attachment);
|
||||
try {
|
||||
Storage::disk('upload')->delete($path);
|
||||
} catch (Exception $e) {
|
||||
Log::error(sprintf('Could not delete file for attachment %d: %s', $attachment->id, $e->getMessage()));
|
||||
} catch (Exception $e) { // @phpstan-ignore-line
|
||||
// @ignoreException
|
||||
}
|
||||
$attachment->delete();
|
||||
|
||||
@@ -209,8 +209,8 @@ class AttachmentRepository implements AttachmentRepositoryInterface
|
||||
if (null !== $dbNote) {
|
||||
try {
|
||||
$dbNote->delete();
|
||||
} catch (Exception $e) {
|
||||
Log::debug(sprintf('Could not delete note: %s', $e->getMessage()));
|
||||
} catch (Exception $e) { // @phpstan-ignore-line
|
||||
// @ignoreException
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -648,7 +648,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
$cache->addProperty('nextDateMatch');
|
||||
$cache->addProperty($date);
|
||||
if ($cache->has()) {
|
||||
return $cache->get(); // @codeCoverageIgnore
|
||||
return $cache->get();
|
||||
}
|
||||
// find the most recent date for this bill NOT in the future. Cache this date:
|
||||
$start = clone $bill->date;
|
||||
@@ -682,7 +682,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
$cache->addProperty('nextExpectedMatch');
|
||||
$cache->addProperty($date);
|
||||
if ($cache->has()) {
|
||||
return $cache->get(); // @codeCoverageIgnore
|
||||
return $cache->get();
|
||||
}
|
||||
// find the most recent date for this bill NOT in the future. Cache this date:
|
||||
$start = clone $bill->date;
|
||||
|
||||
@@ -55,8 +55,8 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
|
||||
{
|
||||
try {
|
||||
$availableBudget->delete();
|
||||
} catch (Exception $e) {
|
||||
Log::error(sprintf('Could not delete available budget: %s', $e->getMessage()));
|
||||
} catch (Exception $e) { // @phpstan-ignore-line
|
||||
// @ignoreException
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,7 +262,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
|
||||
*/
|
||||
public function update(AvailableBudget $availableBudget, array $data): AvailableBudget
|
||||
{
|
||||
if (isset($data['amount'])) {
|
||||
if (array_key_exists('amount', $data)) {
|
||||
$availableBudget->amount = $data['amount'];
|
||||
}
|
||||
$availableBudget->save();
|
||||
|
||||
@@ -124,8 +124,8 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
{
|
||||
try {
|
||||
$budgetLimit->delete();
|
||||
} catch (Exception $e) {
|
||||
Log::info(sprintf('Could not delete budget limit: %s', $e->getMessage()));
|
||||
} catch (Exception $e) { // @phpstan-ignore-line
|
||||
// @ignoreException
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,25 +320,25 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
// find the budget:
|
||||
$budget = $this->user->budgets()->find((int)$data['budget_id']);
|
||||
if (null === $budget) {
|
||||
throw new FireflyException('200004: Budget does not exist.'); // @codeCoverageIgnore
|
||||
throw new FireflyException('200004: Budget does not exist.');
|
||||
}
|
||||
|
||||
// find limit with same date range and currency.
|
||||
$limit = $budget->budgetlimits()
|
||||
->where('budget_limits.start_date', $data['start_date']->format('Y-m-d 00:00:00'))
|
||||
->where('budget_limits.end_date', $data['end_date']->format('Y-m-d 23:59:59'))
|
||||
->where('budget_limits.start_date', $data['start_date']->format('Y-m-d'))
|
||||
->where('budget_limits.end_date', $data['end_date']->format('Y-m-d'))
|
||||
->where('budget_limits.transaction_currency_id', $currency->id)
|
||||
->get(['budget_limits.*'])->first();
|
||||
->first(['budget_limits.*']);
|
||||
if (null !== $limit) {
|
||||
throw new FireflyException('200027: Budget limit already exists.'); // @codeCoverageIgnore
|
||||
throw new FireflyException('200027: Budget limit already exists.');
|
||||
}
|
||||
Log::debug('No existing budget limit, create a new one');
|
||||
|
||||
// or create one and return it.
|
||||
$limit = new BudgetLimit;
|
||||
$limit->budget()->associate($budget);
|
||||
$limit->start_date = $data['start_date']->format('Y-m-d 00:00:00');
|
||||
$limit->end_date = $data['end_date']->format('Y-m-d 23:59:59');
|
||||
$limit->start_date = $data['start_date']->format('Y-m-d');
|
||||
$limit->end_date = $data['end_date']->format('Y-m-d');
|
||||
$limit->amount = $data['amount'];
|
||||
$limit->transaction_currency_id = $currency->id;
|
||||
$limit->save();
|
||||
@@ -397,7 +397,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
$limits = $budget->budgetlimits()
|
||||
->where('budget_limits.start_date', $start->format('Y-m-d 00:00:00'))
|
||||
->where('budget_limits.end_date', $end->format('Y-m-d 00:00:00'))
|
||||
->get(['budget_limits.*'])->count();
|
||||
->count(['budget_limits.*']);
|
||||
Log::debug(sprintf('Found %d budget limits.', $limits));
|
||||
|
||||
// there might be a budget limit for these dates:
|
||||
@@ -423,8 +423,8 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
Log::debug(sprintf('%s is zero, delete budget limit #%d', $amount, $limit->id));
|
||||
try {
|
||||
$limit->delete();
|
||||
} catch (Exception $e) {
|
||||
Log::debug(sprintf('Could not delete limit: %s', $e->getMessage()));
|
||||
} catch (Exception $e) { // @phpstan-ignore-line
|
||||
// @ignoreException
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -58,8 +58,8 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
// delete limits with amount 0:
|
||||
try {
|
||||
BudgetLimit::where('amount', 0)->delete();
|
||||
} catch (Exception $e) {
|
||||
Log::debug(sprintf('Could not delete budget limit: %s', $e->getMessage()));
|
||||
} catch (Exception $e) { // @phpstan-ignore-line
|
||||
// @ignoreException
|
||||
}
|
||||
$budgets = $this->getActiveBudgets();
|
||||
/**
|
||||
@@ -326,7 +326,7 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
} catch (QueryException $e) {
|
||||
Log::error($e->getMessage());
|
||||
Log::error($e->getTraceAsString());
|
||||
throw new FireflyException('400002: Could not store budget.');
|
||||
throw new FireflyException('400002: Could not store budget.', 0, $e);
|
||||
}
|
||||
if (!array_key_exists('auto_budget_type', $data)) {
|
||||
return $newBudget;
|
||||
|
||||
@@ -75,7 +75,7 @@ class NoBudgetRepository implements NoBudgetRepositoryInterface
|
||||
];
|
||||
$date = $journal['date']->format($carbonFormat);
|
||||
|
||||
if (!isset($data[$currencyId]['entries'][$date])) {
|
||||
if (!array_key_exists($date, $data[$currencyId]['entries'])) {
|
||||
$data[$currencyId]['entries'][$date] = '0';
|
||||
}
|
||||
$data[$currencyId]['entries'][$date] = bcadd($data[$currencyId]['entries'][$date], $journal['amount']);
|
||||
@@ -118,7 +118,7 @@ class NoBudgetRepository implements NoBudgetRepositoryInterface
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$code = $journal['currency_code'];
|
||||
if (!isset($currencies[$code])) {
|
||||
if (!array_key_exists($code, $currencies)) {
|
||||
$currencies[$code] = [
|
||||
'id' => $journal['currency_id'],
|
||||
'name' => $journal['currency_name'],
|
||||
@@ -126,7 +126,7 @@ class NoBudgetRepository implements NoBudgetRepositoryInterface
|
||||
'decimal_places' => $journal['currency_decimal_places'],
|
||||
];
|
||||
}
|
||||
$total[$code] = isset($total[$code]) ? bcadd($total[$code], $journal['amount']) : $journal['amount'];
|
||||
$total[$code] = array_key_exists($code, $total) ? bcadd($total[$code], $journal['amount']) : $journal['amount'];
|
||||
}
|
||||
foreach ($total as $code => $spent) {
|
||||
/** @var TransactionCurrency $currency */
|
||||
|
||||
@@ -237,7 +237,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
/** @var array $transaction */
|
||||
foreach ($group['transactions'] as $transaction) {
|
||||
$code = $transaction['currency_code'];
|
||||
if (!isset($currencies[$code])) {
|
||||
if (!array_key_exists($code, $currencies)) {
|
||||
$currencies[$code] = [
|
||||
'id' => $transaction['currency_id'],
|
||||
'decimal_places' => $transaction['currency_decimal_places'],
|
||||
@@ -246,7 +246,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
'symbol' => $transaction['currency_symbol'],
|
||||
];
|
||||
}
|
||||
$total[$code] = isset($total[$code]) ? bcadd($total[$code], $transaction['amount']) : $transaction['amount'];
|
||||
$total[$code] = array_key_exists($code, $total) ? bcadd($total[$code], $transaction['amount']) : $transaction['amount'];
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Repositories\Journal;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use DB;
|
||||
use Exception;
|
||||
@@ -29,7 +30,6 @@ use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
@@ -128,9 +128,9 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface
|
||||
if ($cache->has()) {
|
||||
$result = null;
|
||||
try {
|
||||
$result = new Carbon($cache->get()); // @codeCoverageIgnore
|
||||
} catch (Exception $e) {
|
||||
$e->getMessage();
|
||||
$result = new Carbon($cache->get());
|
||||
} catch (Exception $e) { // @phpstan-ignore-line
|
||||
// @ignoreException
|
||||
}
|
||||
|
||||
return $result;
|
||||
@@ -143,13 +143,12 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface
|
||||
$value = null;
|
||||
try {
|
||||
$value = new Carbon($entry->data);
|
||||
} catch (Exception $e) {
|
||||
$e->getMessage();
|
||||
|
||||
return null;
|
||||
} catch (Exception $e) { // @phpstan-ignore-line
|
||||
// @ignoreException
|
||||
}
|
||||
if (null !== $value) {
|
||||
$cache->store($value);
|
||||
}
|
||||
|
||||
$cache->store($entry->data);
|
||||
|
||||
return $value;
|
||||
}
|
||||
@@ -170,7 +169,7 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface
|
||||
$cache->addProperty($field);
|
||||
|
||||
if ($cache->has()) {
|
||||
return $cache->get(); // @codeCoverageIgnore
|
||||
return $cache->get();
|
||||
}
|
||||
|
||||
$entry = $journal->transactionJournalMeta()->where('name', $field)->first();
|
||||
@@ -188,13 +187,11 @@ class JournalCLIRepository implements JournalCLIRepositoryInterface
|
||||
}
|
||||
|
||||
// return when something else:
|
||||
$return = (string)$value;
|
||||
try {
|
||||
$return = (string)$value;
|
||||
$cache->store($return);
|
||||
} catch (Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
|
||||
return '';
|
||||
} catch (Exception $e) { // @phpstan-ignore-line
|
||||
// @ignoreException
|
||||
}
|
||||
|
||||
return $return;
|
||||
|
||||
@@ -137,7 +137,7 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
$cache->addProperty($journal->id);
|
||||
$cache->addProperty('destination-account-list');
|
||||
if ($useCache && $cache->has()) {
|
||||
return $cache->get(); // @codeCoverageIgnore
|
||||
return $cache->get();
|
||||
}
|
||||
$transactions = $journal->transactions()->where('amount', '>', 0)->orderBy('transactions.account_id')->with('account')->get();
|
||||
$list = new Collection;
|
||||
@@ -165,7 +165,7 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
$cache->addProperty($journal->id);
|
||||
$cache->addProperty('source-account-list');
|
||||
if ($useCache && $cache->has()) {
|
||||
return $cache->get(); // @codeCoverageIgnore
|
||||
return $cache->get();
|
||||
}
|
||||
$transactions = $journal->transactions()->where('amount', '<', 0)->orderBy('transactions.account_id')->with('account')->get();
|
||||
$list = new Collection;
|
||||
@@ -192,7 +192,7 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
$cache->addProperty($journal->id);
|
||||
$cache->addProperty('amount-positive');
|
||||
if ($cache->has()) {
|
||||
return $cache->get(); // @codeCoverageIgnore
|
||||
return $cache->get();
|
||||
}
|
||||
|
||||
// saves on queries:
|
||||
@@ -250,7 +250,7 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
$cache->addProperty($field);
|
||||
|
||||
if ($cache->has()) {
|
||||
return new Carbon($cache->get()); // @codeCoverageIgnore
|
||||
return new Carbon($cache->get());
|
||||
}
|
||||
$entry = TransactionJournalMeta::where('transaction_journal_id', $journalId)
|
||||
->where('name', $field)->first();
|
||||
|
||||
@@ -379,8 +379,8 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
|
||||
if (null !== $dbNote && '' === $text) {
|
||||
try {
|
||||
$dbNote->delete();
|
||||
} catch (Exception $e) {
|
||||
Log::debug(sprintf('Could not delete note: %s', $e->getMessage()));
|
||||
} catch (Exception $e) { // @phpstan-ignore-line
|
||||
// @ignoreException
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -304,7 +304,7 @@ trait ModifiesPiggyBanks
|
||||
$piggyBank = PiggyBank::create($piggyData);
|
||||
} catch (QueryException $e) {
|
||||
Log::error(sprintf('Could not store piggy bank: %s', $e->getMessage()), $piggyData);
|
||||
throw new FireflyException('400005: Could not store new piggy bank.');
|
||||
throw new FireflyException('400005: Could not store new piggy bank.',0,$e);
|
||||
}
|
||||
|
||||
// reset order then set order:
|
||||
@@ -315,7 +315,7 @@ trait ModifiesPiggyBanks
|
||||
|
||||
// repetition is auto created.
|
||||
$repetition = $this->getRepetition($piggyBank);
|
||||
if (null !== $repetition && isset($data['current_amount']) && '' !== $data['current_amount']) {
|
||||
if (null !== $repetition && array_key_exists('current_amount',$data) && '' !== $data['current_amount']) {
|
||||
$repetition->currentamount = $data['current_amount'];
|
||||
$repetition->save();
|
||||
}
|
||||
@@ -422,8 +422,8 @@ trait ModifiesPiggyBanks
|
||||
if (null !== $dbNote) {
|
||||
try {
|
||||
$dbNote->delete();
|
||||
} catch (Exception $e) {
|
||||
Log::debug(sprintf('Could not delete note: %s', $e->getMessage()));
|
||||
} catch (Exception $e) { // @phpstan-ignore-line
|
||||
// @ignoreException
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
use CalculateRangeOccurrences, CalculateXOccurrences, CalculateXOccurrencesSince, FiltersWeekends;
|
||||
|
||||
private User $user;
|
||||
|
||||
/**
|
||||
* Destroy a recurring transaction.
|
||||
*
|
||||
@@ -169,7 +170,7 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
$query->where('transaction_journals.date', '<=', $end->format('Y-m-d 00:00:00'));
|
||||
}
|
||||
|
||||
return $query->get(['transaction_journals.*'])->count();
|
||||
return $query->count(['transaction_journals.id']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -240,6 +241,7 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
if ('yearly' === $repetition->repetition_type) {
|
||||
$occurrences = $this->getYearlyInRange($mutator, $end, $skipMod, $repetition->repetition_moment);
|
||||
}
|
||||
|
||||
// filter out all the weekend days:
|
||||
return $this->filterWeekends($repetition, $occurrences);
|
||||
}
|
||||
@@ -332,7 +334,7 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
foreach ($journalMeta as $journalId) {
|
||||
$search[] = (int)$journalId;
|
||||
}
|
||||
if (empty($search)) {
|
||||
if (0 === count($search)) {
|
||||
|
||||
return new Collection;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user