Fix various code.

This commit is contained in:
James Cole
2025-05-27 17:06:15 +02:00
parent d8f512ca3a
commit 2cb14f6b72
123 changed files with 581 additions and 500 deletions

View File

@@ -47,6 +47,8 @@ use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Storage;
use Override;
use function Safe\json_encode;
/**
* Class AccountRepository.
*/
@@ -109,7 +111,7 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
->where('accounts.active', true)
->where(
static function (EloquentBuilder $q1) use ($number): void {
$json = \Safe\json_encode($number);
$json = json_encode($number);
$q1->where('account_meta.name', '=', 'account_number');
$q1->where('account_meta.data', '=', $json);
}

View File

@@ -150,51 +150,51 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
// depends on transaction type:
if (TransactionTypeEnum::WITHDRAWAL->value === $type) {
if (null !== $accounts) {
if ($accounts instanceof Collection) {
$collector->setSourceAccounts($accounts);
}
if (null !== $opposing) {
if ($opposing instanceof Collection) {
$collector->setDestinationAccounts($opposing);
}
}
if (TransactionTypeEnum::DEPOSIT->value === $type) {
if (null !== $accounts) {
if ($accounts instanceof Collection) {
$collector->setDestinationAccounts($accounts);
}
if (null !== $opposing) {
if ($opposing instanceof Collection) {
$collector->setSourceAccounts($opposing);
}
}
// supports only accounts, not opposing.
if (TransactionTypeEnum::TRANSFER->value === $type && null !== $accounts) {
if (TransactionTypeEnum::TRANSFER->value === $type && $accounts instanceof Collection) {
$collector->setAccounts($accounts);
}
if (null !== $currency) {
if ($currency instanceof TransactionCurrency) {
$collector->setCurrency($currency);
}
$journals = $collector->getExtractedJournals();
// same but for foreign currencies:
if (null !== $currency) {
if ($currency instanceof TransactionCurrency) {
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user)->setRange($start, $end)->setTypes([$type])->withAccountInformation()
->setForeignCurrency($currency)
;
if (TransactionTypeEnum::WITHDRAWAL->value === $type) {
if (null !== $accounts) {
if ($accounts instanceof Collection) {
$collector->setSourceAccounts($accounts);
}
if (null !== $opposing) {
if ($opposing instanceof Collection) {
$collector->setDestinationAccounts($opposing);
}
}
if (TransactionTypeEnum::DEPOSIT->value === $type) {
if (null !== $accounts) {
if ($accounts instanceof Collection) {
$collector->setDestinationAccounts($accounts);
}
if (null !== $opposing) {
if ($opposing instanceof Collection) {
$collector->setSourceAccounts($opposing);
}
}

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Bill;
use FireflyIII\Models\ObjectGroup;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\BillFactory;
@@ -119,7 +120,7 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
{
if (null !== $billId) {
$searchResult = $this->find($billId);
if (null !== $searchResult) {
if ($searchResult instanceof Bill) {
app('log')->debug(sprintf('Found bill based on #%d, will return it.', $billId));
return $searchResult;
@@ -127,7 +128,7 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
}
if (null !== $billName) {
$searchResult = $this->findByName($billName);
if (null !== $searchResult) {
if ($searchResult instanceof Bill) {
app('log')->debug(sprintf('Found bill based on "%s", will return it.', $billName));
return $searchResult;
@@ -503,7 +504,7 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
public function setObjectGroup(Bill $bill, string $objectGroupTitle): Bill
{
$objectGroup = $this->findOrCreateObjectGroup($objectGroupTitle);
if (null !== $objectGroup) {
if ($objectGroup instanceof ObjectGroup) {
$bill->objectGroups()->sync([$objectGroup->id]);
}

View File

@@ -65,7 +65,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface, U
public function get(?Carbon $start = null, ?Carbon $end = null): Collection
{
$query = $this->user->availableBudgets()->with(['transactionCurrency']);
if (null !== $start && null !== $end) {
if ($start instanceof Carbon && $end instanceof Carbon) {
$query->where(
static function (Builder $q1) use ($start, $end): void {
$q1->where('start_date', '=', $start->format('Y-m-d'));
@@ -123,7 +123,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface, U
->where('end_date', $end->format('Y-m-d'))->first()
;
if (null !== $availableBudget) {
$amount = $availableBudget->amount;
return $availableBudget->amount;
}
return $amount;
@@ -172,10 +172,10 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface, U
{
$query = $this->user->availableBudgets();
if (null !== $start) {
if ($start instanceof Carbon) {
$query->where('start_date', '>=', $start->format('Y-m-d'));
}
if (null !== $end) {
if ($end instanceof Carbon) {
$query->where('end_date', '<=', $end->format('Y-m-d'));
}

View File

@@ -88,7 +88,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface, UserGroup
->where('budgets.active', true)
->where('budgets.user_id', $this->user->id)
;
if (null !== $budgets && $budgets->count() > 0) {
if ($budgets instanceof Collection && $budgets->count() > 0) {
$query->whereIn('budget_limits.budget_id', $budgets->pluck('id')->toArray());
}
@@ -135,7 +135,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface, UserGroup
public function getAllBudgetLimits(?Carbon $start = null, ?Carbon $end = null): Collection
{
// both are NULL:
if (null === $start && null === $end) {
if (!$start instanceof Carbon && !$end instanceof Carbon) {
return BudgetLimit::leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
->with(['budget'])
->where('budgets.user_id', $this->user->id)
@@ -144,17 +144,17 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface, UserGroup
;
}
// one of the two is NULL.
if (null === $start xor null === $end) {
if (!$start instanceof Carbon xor !$end instanceof Carbon) {
$query = BudgetLimit::leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
->with(['budget'])
->whereNull('budgets.deleted_at')
->where('budgets.user_id', $this->user->id)
;
if (null !== $end) {
if ($end instanceof Carbon) {
// end date must be before $end.
$query->where('end_date', '<=', $end->format('Y-m-d 00:00:00'));
}
if (null !== $start) {
if ($start instanceof Carbon) {
// start date must be after $start.
$query->where('start_date', '>=', $start->format('Y-m-d 00:00:00'));
}
@@ -201,17 +201,17 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface, UserGroup
public function getBudgetLimits(Budget $budget, ?Carbon $start = null, ?Carbon $end = null): Collection
{
if (null === $end && null === $start) {
if (!$end instanceof Carbon && !$start instanceof Carbon) {
return $budget->budgetlimits()->with(['transactionCurrency'])->orderBy('budget_limits.start_date', 'DESC')->get(['budget_limits.*']);
}
if (null === $end xor null === $start) {
if (!$end instanceof Carbon xor !$start instanceof Carbon) {
$query = $budget->budgetlimits()->with(['transactionCurrency'])->orderBy('budget_limits.start_date', 'DESC');
// one of the two is null
if (null !== $end) {
if ($end instanceof Carbon) {
// end date must be before $end.
$query->where('end_date', '<=', $end->format('Y-m-d 00:00:00'));
}
if (null !== $start) {
if ($start instanceof Carbon) {
// start date must be after $start.
$query->where('start_date', '>=', $start->format('Y-m-d 00:00:00'));
}

View File

@@ -303,16 +303,16 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
// first things first: delete when no longer required:
$autoBudgetType = array_key_exists('auto_budget_type', $data) ? $data['auto_budget_type'] : null;
if (0 === $autoBudgetType && null !== $autoBudget) {
if (0 === $autoBudgetType && $autoBudget instanceof AutoBudget) {
// delete!
$autoBudget->delete();
return $budget;
}
if (0 === $autoBudgetType && null === $autoBudget) {
if (0 === $autoBudgetType && !$autoBudget instanceof AutoBudget) {
return $budget;
}
if (null === $autoBudgetType && null === $autoBudget) {
if (null === $autoBudgetType && !$autoBudget instanceof AutoBudget) {
return $budget;
}
$this->updateAutoBudget($budget, $data);
@@ -393,7 +393,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
// grab default currency:
$currency = app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup);
if (null === $autoBudget) {
if (!$autoBudget instanceof AutoBudget) {
// at this point it's a blind assumption auto_budget_type is 1 or 2.
$autoBudget = new AutoBudget();
$autoBudget->auto_budget_type = $data['auto_budget_type'];
@@ -488,14 +488,14 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
app('log')->debug('Now in findBudget()');
app('log')->debug(sprintf('Searching for budget with ID #%d...', $budgetId));
$result = $this->find((int) $budgetId);
if (null === $result && null !== $budgetName && '' !== $budgetName) {
if (!$result instanceof Budget && null !== $budgetName && '' !== $budgetName) {
app('log')->debug(sprintf('Searching for budget with name %s...', $budgetName));
$result = $this->findByName($budgetName);
}
if (null !== $result) {
if ($result instanceof Budget) {
app('log')->debug(sprintf('Found budget #%d: %s', $result->id, $result->name));
}
app('log')->debug(sprintf('Found result is null? %s', var_export(null === $result, true)));
app('log')->debug(sprintf('Found result is null? %s', var_export(!$result instanceof Budget, true)));
return $result;
}

View File

@@ -85,10 +85,10 @@ class NoBudgetRepository implements NoBudgetRepositoryInterface, UserGroupInterf
$collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionTypeEnum::WITHDRAWAL->value]);
if (null !== $accounts && $accounts->count() > 0) {
if ($accounts instanceof Collection && $accounts->count() > 0) {
$collector->setAccounts($accounts);
}
if (null !== $currency) {
if ($currency instanceof TransactionCurrency) {
$collector->setCurrency($currency);
}
$collector->withoutBudget();

View File

@@ -126,13 +126,13 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionTypeEnum::WITHDRAWAL->value]);
if (null !== $accounts && $accounts->count() > 0) {
if ($accounts instanceof Collection && $accounts->count() > 0) {
$collector->setAccounts($accounts);
}
if (null !== $budgets && $budgets->count() > 0) {
if ($budgets instanceof Collection && $budgets->count() > 0) {
$collector->setBudgets($budgets);
}
if (null === $budgets || 0 === $budgets->count()) {
if (!$budgets instanceof Collection || 0 === $budgets->count()) {
$collector->setBudgets($this->getBudgets());
}
$collector->withBudgetInformation()->withAccountInformation()->withCategoryInformation();
@@ -229,13 +229,13 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
->setTypes([TransactionTypeEnum::WITHDRAWAL->value])
;
if (null !== $accounts) {
if ($accounts instanceof Collection) {
$collector->setAccounts($accounts);
}
if (null === $budgets) {
if (!$budgets instanceof Collection) {
$budgets = $this->getBudgets();
}
if (null !== $currency) {
if ($currency instanceof TransactionCurrency) {
Log::debug(sprintf('Limit to normal currency %s', $currency->code));
$collector->setNormalCurrency($currency);
}
@@ -245,7 +245,7 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
$journals = $collector->getExtractedJournals();
// same but for transactions in the foreign currency:
if (null !== $currency) {
if ($currency instanceof TransactionCurrency) {
Log::debug('STOP looking for transactions in the foreign currency.');
}
$summarizer = new TransactionSummarizer($this->user);

View File

@@ -111,18 +111,18 @@ class CategoryRepository implements CategoryRepositoryInterface, UserGroupInterf
app('log')->debug('Now in findCategory()');
app('log')->debug(sprintf('Searching for category with ID #%d...', $categoryId));
$result = $this->find((int) $categoryId);
if (null === $result) {
if (!$result instanceof Category) {
app('log')->debug(sprintf('Searching for category with name %s...', $categoryName));
$result = $this->findByName((string) $categoryName);
if (null === $result && '' !== (string) $categoryName) {
if (!$result instanceof Category && '' !== (string) $categoryName) {
// create it!
$result = $this->store(['name' => $categoryName]);
}
}
if (null !== $result) {
if ($result instanceof Category) {
app('log')->debug(sprintf('Found category #%d: %s', $result->id, $result->name));
}
app('log')->debug(sprintf('Found category result is null? %s', var_export(null === $result, true)));
app('log')->debug(sprintf('Found category result is null? %s', var_export(!$result instanceof Category, true)));
return $result;
}
@@ -191,13 +191,13 @@ class CategoryRepository implements CategoryRepositoryInterface, UserGroupInterf
$firstJournalDate = $this->getFirstJournalDate($category);
$firstTransactionDate = $this->getFirstTransactionDate($category);
if (null === $firstTransactionDate && null === $firstJournalDate) {
if (!$firstTransactionDate instanceof Carbon && !$firstJournalDate instanceof Carbon) {
return null;
}
if (null === $firstTransactionDate) {
if (!$firstTransactionDate instanceof Carbon) {
return $firstJournalDate;
}
if (null === $firstJournalDate) {
if (!$firstJournalDate instanceof Carbon) {
return $firstTransactionDate;
}
@@ -279,13 +279,13 @@ class CategoryRepository implements CategoryRepositoryInterface, UserGroupInterf
$lastJournalDate = $this->getLastJournalDate($category, $accounts);
$lastTransactionDate = $this->getLastTransactionDate($category, $accounts);
if (null === $lastTransactionDate && null === $lastJournalDate) {
if (!$lastTransactionDate instanceof Carbon && !$lastJournalDate instanceof Carbon) {
return null;
}
if (null === $lastTransactionDate) {
if (!$lastTransactionDate instanceof Carbon) {
return $lastJournalDate;
}
if (null === $lastJournalDate) {
if (!$lastJournalDate instanceof Carbon) {
return $lastTransactionDate;
}

View File

@@ -49,7 +49,7 @@ class NoCategoryRepository implements NoCategoryRepositoryInterface, UserGroupIn
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionTypeEnum::WITHDRAWAL->value])->withoutCategory();
if (null !== $accounts && $accounts->count() > 0) {
if ($accounts instanceof Collection && $accounts->count() > 0) {
$collector->setAccounts($accounts);
}
$journals = $collector->getExtractedJournals();
@@ -95,7 +95,7 @@ class NoCategoryRepository implements NoCategoryRepositoryInterface, UserGroupIn
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionTypeEnum::DEPOSIT->value])->withoutCategory();
if (null !== $accounts && $accounts->count() > 0) {
if ($accounts instanceof Collection && $accounts->count() > 0) {
$collector->setAccounts($accounts);
}
$journals = $collector->getExtractedJournals();
@@ -140,7 +140,7 @@ class NoCategoryRepository implements NoCategoryRepositoryInterface, UserGroupIn
$collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionTypeEnum::WITHDRAWAL->value])->withoutCategory();
if (null !== $accounts && $accounts->count() > 0) {
if ($accounts instanceof Collection && $accounts->count() > 0) {
$collector->setAccounts($accounts);
}
$journals = $collector->getExtractedJournals();
@@ -158,7 +158,7 @@ class NoCategoryRepository implements NoCategoryRepositoryInterface, UserGroupIn
$collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionTypeEnum::DEPOSIT->value])->withoutCategory();
if (null !== $accounts && $accounts->count() > 0) {
if ($accounts instanceof Collection && $accounts->count() > 0) {
$collector->setAccounts($accounts);
}
$journals = $collector->getExtractedJournals();
@@ -186,7 +186,7 @@ class NoCategoryRepository implements NoCategoryRepositoryInterface, UserGroupIn
$collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionTypeEnum::TRANSFER->value])->withoutCategory();
if (null !== $accounts && $accounts->count() > 0) {
if ($accounts instanceof Collection && $accounts->count() > 0) {
$collector->setAccounts($accounts);
}
$journals = $collector->getExtractedJournals();

View File

@@ -53,14 +53,14 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionTypeEnum::WITHDRAWAL->value]);
if (null !== $accounts && $accounts->count() > 0) {
if ($accounts instanceof Collection && $accounts->count() > 0) {
$collector->setAccounts($accounts);
$collector->excludeDestinationAccounts($accounts); // to exclude withdrawals to liabilities.
}
if (null !== $categories && $categories->count() > 0) {
if ($categories instanceof Collection && $categories->count() > 0) {
$collector->setCategories($categories);
}
if (null === $categories || 0 === $categories->count()) {
if (!$categories instanceof Collection || 0 === $categories->count()) {
$collector->setCategories($this->getCategories());
}
$collector->withCategoryInformation()->withAccountInformation()->withBudgetInformation();
@@ -131,14 +131,14 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionTypeEnum::DEPOSIT->value]);
if (null !== $accounts && $accounts->count() > 0) {
if ($accounts instanceof Collection && $accounts->count() > 0) {
$collector->setAccounts($accounts);
$collector->excludeSourceAccounts($accounts); // to prevent income from liabilities.
}
if (null !== $categories && $categories->count() > 0) {
if ($categories instanceof Collection && $categories->count() > 0) {
$collector->setCategories($categories);
}
if (null === $categories || 0 === $categories->count()) {
if (!$categories instanceof Collection || 0 === $categories->count()) {
$collector->setCategories($this->getCategories());
}
$collector->withCategoryInformation()->withAccountInformation();
@@ -197,10 +197,10 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionTypeEnum::TRANSFER->value])
->setDestinationAccounts($accounts)->excludeSourceAccounts($accounts)
;
if (null !== $categories && $categories->count() > 0) {
if ($categories instanceof Collection && $categories->count() > 0) {
$collector->setCategories($categories);
}
if (null === $categories || 0 === $categories->count()) {
if (!$categories instanceof Collection || 0 === $categories->count()) {
$collector->setCategories($this->getCategories());
}
$collector->withCategoryInformation()->withAccountInformation()->withBudgetInformation();
@@ -260,10 +260,10 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionTypeEnum::TRANSFER->value])
->setSourceAccounts($accounts)->excludeDestinationAccounts($accounts)
;
if (null !== $categories && $categories->count() > 0) {
if ($categories instanceof Collection && $categories->count() > 0) {
$collector->setCategories($categories);
}
if (null === $categories || 0 === $categories->count()) {
if (!$categories instanceof Collection || 0 === $categories->count()) {
$collector->setCategories($this->getCategories());
}
$collector->withCategoryInformation()->withAccountInformation()->withBudgetInformation();
@@ -325,10 +325,10 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
$collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionTypeEnum::WITHDRAWAL->value]);
if (null !== $accounts && $accounts->count() > 0) {
if ($accounts instanceof Collection && $accounts->count() > 0) {
$collector->setAccounts($accounts);
}
if (null === $categories || 0 === $categories->count()) {
if (!$categories instanceof Collection || 0 === $categories->count()) {
$categories = $this->getCategories();
}
$collector->setCategories($categories);
@@ -350,10 +350,10 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
->setTypes([TransactionTypeEnum::DEPOSIT->value])
;
if (null !== $accounts && $accounts->count() > 0) {
if ($accounts instanceof Collection && $accounts->count() > 0) {
$collector->setAccounts($accounts);
}
if (null === $categories || 0 === $categories->count()) {
if (!$categories instanceof Collection || 0 === $categories->count()) {
$categories = $this->getCategories();
}
$collector->setCategories($categories);
@@ -419,10 +419,10 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
->setTypes([TransactionTypeEnum::TRANSFER->value])
;
if (null !== $accounts && $accounts->count() > 0) {
if ($accounts instanceof Collection && $accounts->count() > 0) {
$collector->setAccounts($accounts);
}
if (null === $categories || 0 === $categories->count()) {
if (!$categories instanceof Collection || 0 === $categories->count()) {
$categories = $this->getCategories();
}
$collector->setCategories($categories);

View File

@@ -44,6 +44,8 @@ use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use Override;
use function Safe\json_encode;
/**
* Class CurrencyRepository.
*/
@@ -82,7 +84,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf
}
// is being used in accounts:
$meta = AccountMeta::where('name', 'currency_id')->where('data', \Safe\json_encode((string) $currency->id))->count();
$meta = AccountMeta::where('name', 'currency_id')->where('data', json_encode((string) $currency->id))->count();
if ($meta > 0) {
Log::info(sprintf('Used in %d accounts as currency_id, return true. ', $meta));
@@ -90,7 +92,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf
}
// second search using integer check.
$meta = AccountMeta::where('name', 'currency_id')->where('data', \Safe\json_encode((int) $currency->id))->count();
$meta = AccountMeta::where('name', 'currency_id')->where('data', json_encode((int) $currency->id))->count();
if ($meta > 0) {
Log::info(sprintf('Used in %d accounts as currency_id, return true. ', $meta));
@@ -118,7 +120,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf
// is being used in accounts (as integer)
$meta = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id')
->whereNull('accounts.deleted_at')
->where('account_meta.name', 'currency_id')->where('account_meta.data', \Safe\json_encode($currency->id))->count()
->where('account_meta.name', 'currency_id')->where('account_meta.data', json_encode($currency->id))->count()
;
if ($meta > 0) {
Log::info(sprintf('Used in %d accounts as currency_id, return true. ', $meta));
@@ -237,7 +239,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf
{
$result = $this->findCurrencyNull($currencyId, $currencyCode);
if (null === $result) {
if (!$result instanceof TransactionCurrency) {
Log::debug('Grabbing default currency for this user...');
/** @var null|TransactionCurrency $result */
@@ -260,7 +262,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf
{
Log::debug(sprintf('Now in findCurrencyNull(%s, "%s")', var_export($currencyId, true), $currencyCode));
$result = $this->find((int) $currencyId);
if (null !== $result) {
if ($result instanceof TransactionCurrency) {
Log::debug(sprintf('Found currency by ID: %s', $result->code));
return $result;
@@ -269,7 +271,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf
Log::debug(sprintf('Searching for currency with code "%s"...', $currencyCode));
$result = $this->findByCode((string) $currencyCode);
}
if (null !== $result && false === $result->enabled) {
if ($result instanceof TransactionCurrency && false === $result->enabled) {
Log::debug(sprintf('Also enabled currency %s', $result->code));
$this->enable($result);
}

View File

@@ -105,7 +105,7 @@ class ExchangeRateRepository implements ExchangeRateRepositoryInterface, UserGro
public function updateExchangeRate(CurrencyExchangeRate $object, string $rate, ?Carbon $date = null): CurrencyExchangeRate
{
$object->rate = $rate;
if (null !== $date) {
if ($date instanceof Carbon) {
$object->date = $date;
}
$object->save();

View File

@@ -77,13 +77,12 @@ class JournalRepository implements JournalRepositoryInterface, UserGroupInterfac
public function firstNull(): ?TransactionJournal
{
/** @var null|TransactionJournal $entry */
$entry = $this->user->transactionJournals()->orderBy('date', 'ASC')->first(['transaction_journals.*']);
$result = null;
$entry = $this->user->transactionJournals()->orderBy('date', 'ASC')->first(['transaction_journals.*']);
if (null !== $entry) {
$result = $entry;
return $entry;
}
return $result;
return null;
}
public function getDestinationAccount(TransactionJournal $journal): Account
@@ -120,13 +119,12 @@ class JournalRepository implements JournalRepositoryInterface, UserGroupInterfac
public function getLast(): ?TransactionJournal
{
/** @var null|TransactionJournal $entry */
$entry = $this->user->transactionJournals()->orderBy('date', 'DESC')->first(['transaction_journals.*']);
$result = null;
$entry = $this->user->transactionJournals()->orderBy('date', 'DESC')->first(['transaction_journals.*']);
if (null !== $entry) {
$result = $entry;
return $entry;
}
return $result;
return null;
}
public function getLinkNoteText(TransactionJournalLink $link): string

View File

@@ -47,7 +47,7 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface, UserGroupInterf
public function destroy(LinkType $linkType, ?LinkType $moveTo = null): bool
{
if (null !== $moveTo) {
if ($moveTo instanceof LinkType) {
TransactionJournalLink::where('link_type_id', $linkType->id)->update(['link_type_id' => $moveTo->id]);
}
$linkType->delete();
@@ -125,7 +125,7 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface, UserGroupInterf
->whereNull('dest_journals.deleted_at')
;
if (null !== $linkType) {
if ($linkType instanceof LinkType) {
$query->where('journal_links.link_type_id', $linkType->id);
}
@@ -177,17 +177,17 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface, UserGroupInterf
{
$linkType = $this->find((int) ($information['link_type_id'] ?? 0));
if (null === $linkType) {
if (!$linkType instanceof LinkType) {
$linkType = $this->findByName($information['link_type_name']);
}
if (null === $linkType) {
if (!$linkType instanceof LinkType) {
return null;
}
// might exist already:
$existing = $this->findSpecificLink($linkType, $inward, $outward);
if (null !== $existing) {
if ($existing instanceof TransactionJournalLink) {
return $existing;
}

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\PiggyBank;
use FireflyIII\User;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\PiggyBankFactory;
@@ -69,7 +70,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface, UserGroupInte
if (null !== $piggyBankId) {
$searchResult = $this->find($piggyBankId);
if (null !== $searchResult) {
if ($searchResult instanceof PiggyBank) {
app('log')->debug(sprintf('Found piggy based on #%d, will return it.', $piggyBankId));
return $searchResult;
@@ -77,7 +78,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface, UserGroupInte
}
if (null !== $piggyBankName) {
$searchResult = $this->findByName($piggyBankName);
if (null !== $searchResult) {
if ($searchResult instanceof PiggyBank) {
app('log')->debug(sprintf('Found piggy based on "%s", will return it.', $piggyBankName));
return $searchResult;
@@ -133,7 +134,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface, UserGroupInte
{
$sum = '0';
foreach ($piggyBank->accounts as $current) {
if (null !== $account && $account->id !== $current->id) {
if ($account instanceof Account && $account->id !== $current->id) {
continue;
}
$amount = (string) $current->pivot->native_current_amount;
@@ -267,7 +268,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface, UserGroupInte
{
$sum = '0';
foreach ($piggyBank->accounts as $current) {
if (null !== $account && $account->id !== $current->id) {
if ($account instanceof Account && $account->id !== $current->id) {
continue;
}
$amount = (string) $current->pivot->current_amount;
@@ -311,10 +312,10 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface, UserGroupInte
$query = PiggyBank::leftJoin('account_piggy_bank', 'account_piggy_bank.piggy_bank_id', '=', 'piggy_banks.id')
->leftJoin('accounts', 'accounts.id', '=', 'account_piggy_bank.account_id')
;
if (null === $this->user) {
if (!$this->user instanceof User) {
$query->where('accounts.user_group_id', $this->userGroup->id);
}
if (null !== $this->user) {
if ($this->user instanceof User) {
$query->where('accounts.user_id', $this->user->id);
}

View File

@@ -50,6 +50,9 @@ use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use function Safe\json_encode;
use function Safe\json_decode;
/**
* Class RecurringRepository
*/
@@ -68,16 +71,16 @@ class RecurringRepository implements RecurringRepositoryInterface, UserGroupInte
$set
= TransactionJournalMeta::where(static function (Builder $q1) use ($recurrence): void {
$q1->where('name', 'recurrence_id');
$q1->where('data', \Safe\json_encode((string) $recurrence->id));
$q1->where('data', json_encode((string) $recurrence->id));
})->get(['journal_meta.transaction_journal_id']);
// there are X journals made for this recurrence. Any of them meant for today?
foreach ($set as $journalMeta) {
$count = TransactionJournalMeta::where(static function (Builder $q2) use ($date): void {
$string = (string) $date;
app('log')->debug(sprintf('Search for date: %s', \Safe\json_encode($string)));
app('log')->debug(sprintf('Search for date: %s', json_encode($string)));
$q2->where('name', 'recurrence_date');
$q2->where('data', \Safe\json_encode($string));
$q2->where('data', json_encode($string));
})
->where('transaction_journal_id', $journalMeta->transaction_journal_id)
->count()
@@ -212,10 +215,10 @@ class RecurringRepository implements RecurringRepositoryInterface, UserGroupInte
->where('journal_meta.name', 'recurrence_id')
->where('journal_meta.data', '"'.$recurrence->id.'"')
;
if (null !== $start) {
if ($start instanceof Carbon) {
$query->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00'));
}
if (null !== $end) {
if ($end instanceof Carbon) {
$query->where('transaction_journals.date', '<=', $end->format('Y-m-d 00:00:00'));
}
$count = $query->count('transaction_journals.id');
@@ -232,7 +235,7 @@ class RecurringRepository implements RecurringRepositoryInterface, UserGroupInte
return TransactionJournalMeta::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id')
->where('transaction_journals.user_id', $this->user->id)
->where('journal_meta.name', '=', 'recurrence_id')
->where('journal_meta.data', '=', \Safe\json_encode((string) $recurrence->id))
->where('journal_meta.data', '=', json_encode((string) $recurrence->id))
->get(['journal_meta.transaction_journal_id'])->pluck('transaction_journal_id')->toArray()
;
}
@@ -272,7 +275,7 @@ class RecurringRepository implements RecurringRepositoryInterface, UserGroupInte
/** @var RecurrenceMeta $meta */
foreach ($transaction->recurrenceTransactionMeta as $meta) {
if ('tags' === $meta->name && '' !== $meta->value) {
$tags = \Safe\json_decode($meta->value, true, 512, JSON_THROW_ON_ERROR);
$tags = json_decode((string) $meta->value, true, 512, JSON_THROW_ON_ERROR);
}
}
@@ -285,7 +288,7 @@ class RecurringRepository implements RecurringRepositoryInterface, UserGroupInte
->whereNull('transaction_journals.deleted_at')
->where('transaction_journals.user_id', $this->user->id)
->where('name', 'recurrence_id')
->where('data', \Safe\json_encode((string) $recurrence->id))
->where('data', json_encode((string) $recurrence->id))
->get()->pluck('transaction_journal_id')->toArray()
;
$search = [];
@@ -311,7 +314,7 @@ class RecurringRepository implements RecurringRepositoryInterface, UserGroupInte
->whereNull('transaction_journals.deleted_at')
->where('transaction_journals.user_id', $this->user->id)
->where('name', 'recurrence_id')
->where('data', \Safe\json_encode((string) $recurrence->id))
->where('data', json_encode((string) $recurrence->id))
->get()->pluck('transaction_journal_id')->toArray()
;
$search = [];
@@ -406,7 +409,7 @@ class RecurringRepository implements RecurringRepositoryInterface, UserGroupInte
private function filterMaxDate(?Carbon $max, array $occurrences): array
{
$filtered = [];
if (null === $max) {
if (!$max instanceof Carbon) {
foreach ($occurrences as $date) {
if ($date->gt(today())) {
$filtered[] = $date;
@@ -476,7 +479,7 @@ class RecurringRepository implements RecurringRepositoryInterface, UserGroupInte
if ('yearly' === $repetition->repetition_type) {
$today = today(config('app.timezone'))->endOfYear();
$repDate = Carbon::createFromFormat('Y-m-d', $repetition->repetition_moment);
if (null === $repDate) {
if (!$repDate instanceof Carbon) {
$repDate = clone $today;
}
$diffInYears = (int) $today->diffInYears($repDate, true);

View File

@@ -79,7 +79,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface, UserGroupInte
{
/** @var Rule $rule */
foreach ($ruleGroup->rules as $rule) {
if (null === $moveTo) {
if (!$moveTo instanceof RuleGroup) {
$rule->delete();
continue;
@@ -92,7 +92,7 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface, UserGroupInte
$ruleGroup->delete();
$this->resetOrder();
if (null !== $moveTo) {
if ($moveTo instanceof RuleGroup) {
$this->resetRuleOrder($moveTo);
}

View File

@@ -50,14 +50,14 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
$collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionTypeEnum::WITHDRAWAL->value]);
$tagIds = [];
if (null !== $accounts && $accounts->count() > 0) {
if ($accounts instanceof Collection && $accounts->count() > 0) {
$collector->setAccounts($accounts);
}
if (null !== $tags && $tags->count() > 0) {
if ($tags instanceof Collection && $tags->count() > 0) {
$collector->setTags($tags);
$tagIds = $tags->pluck('id')->toArray();
}
if (null === $tags || 0 === $tags->count()) {
if (!$tags instanceof Collection || 0 === $tags->count()) {
$collector->setTags($this->getTags());
$tagIds = $this->getTags()->pluck('id')->toArray();
}
@@ -133,14 +133,14 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
$collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionTypeEnum::DEPOSIT->value]);
$tagIds = [];
if (null !== $accounts && $accounts->count() > 0) {
if ($accounts instanceof Collection && $accounts->count() > 0) {
$collector->setAccounts($accounts);
}
if (null !== $tags && $tags->count() > 0) {
if ($tags instanceof Collection && $tags->count() > 0) {
$collector->setTags($tags);
$tagIds = $tags->pluck('id')->toArray();
}
if (null === $tags || 0 === $tags->count()) {
if (!$tags instanceof Collection || 0 === $tags->count()) {
$collector->setTags($this->getTags());
$tagIds = $this->getTags()->pluck('id')->toArray();
}

View File

@@ -231,7 +231,7 @@ class TagRepository implements TagRepositoryInterface, UserGroupInterface
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
if (null !== $start && null !== $end) {
if ($start instanceof Carbon && $end instanceof Carbon) {
$collector->setRange($start, $end);
}
@@ -354,7 +354,7 @@ class TagRepository implements TagRepositoryInterface, UserGroupInterface
// otherwise, update or create.
if (!(null === $data['latitude'] && null === $data['longitude'] && null === $data['zoom_level'])) {
$location = $this->getLocation($tag);
if (null === $location) {
if (!$location instanceof Location) {
$location = new Location();
$location->locatable()->associate($tag);
}

View File

@@ -50,6 +50,8 @@ use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use Exception;
use function Safe\json_decode;
/**
* Class TransactionGroupRepository
*/
@@ -245,15 +247,14 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
$currency = $transaction->transactionCurrency;
$type = $journal->transactionType->type;
$amount = app('steam')->positive($transaction->amount);
$return = '';
if (TransactionTypeEnum::WITHDRAWAL->value === $type) {
$return = app('amount')->formatAnything($currency, app('steam')->negative($amount));
return app('amount')->formatAnything($currency, app('steam')->negative($amount));
}
if (TransactionTypeEnum::WITHDRAWAL->value !== $type) {
$return = app('amount')->formatAnything($currency, $amount);
return app('amount')->formatAnything($currency, $amount);
}
return $return;
return '';
}
private function getFormattedForeignAmount(TransactionJournal $journal): string
@@ -269,15 +270,14 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
$currency = $transaction->foreignCurrency;
$type = $journal->transactionType->type;
$amount = app('steam')->positive($transaction->foreign_amount);
$return = '';
if (TransactionTypeEnum::WITHDRAWAL->value === $type) {
$return = app('amount')->formatAnything($currency, app('steam')->negative($amount));
return app('amount')->formatAnything($currency, app('steam')->negative($amount));
}
if (TransactionTypeEnum::WITHDRAWAL->value !== $type) {
$return = app('amount')->formatAnything($currency, $amount);
return app('amount')->formatAnything($currency, $amount);
}
return $return;
return '';
}
public function getLocation(int $journalId): ?Location
@@ -305,7 +305,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
$return = [];
foreach ($query as $row) {
$return[$row->name] = new Carbon(\Safe\json_decode($row->data, true, 512, JSON_THROW_ON_ERROR));
$return[$row->name] = new Carbon(json_decode((string) $row->data, true, 512, JSON_THROW_ON_ERROR));
}
return new NullArrayObject($return);
@@ -325,7 +325,7 @@ class TransactionGroupRepository implements TransactionGroupRepositoryInterface,
$return = [];
foreach ($query as $row) {
$return[$row->name] = \Safe\json_decode($row->data);
$return[$row->name] = json_decode((string) $row->data);
}
return new NullArrayObject($return);

View File

@@ -36,14 +36,14 @@ class TransactionTypeRepository implements TransactionTypeRepositoryInterface
public function findTransactionType(?TransactionType $type, ?string $typeString): TransactionType
{
app('log')->debug('Now looking for a transaction type.');
if (null !== $type) {
if ($type instanceof TransactionType) {
app('log')->debug(sprintf('Found $type in parameters, its %s. Will return it.', $type->type));
return $type;
}
$typeString ??= TransactionTypeEnum::WITHDRAWAL->value;
$search = $this->findByType($typeString);
if (null === $search) {
if (!$search instanceof TransactionType) {
$search = $this->findByType(TransactionTypeEnum::WITHDRAWAL->value);
}
app('log')->debug(sprintf('Tried to search for "%s", came up with "%s". Will return it.', $typeString, $search->type));

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\User;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\GroupMembership;
@@ -56,7 +57,7 @@ class UserRepository implements UserRepositoryInterface
// save old email as pref
app('preferences')->setForUser($user, 'previous_email_latest', $oldEmail);
app('preferences')->setForUser($user, 'previous_email_'.date('Y-m-d-H-i-s'), $oldEmail);
app('preferences')->setForUser($user, 'previous_email_'.Carbon::now()->format('Y-m-d-H-i-s'), $oldEmail);
// set undo and confirm token:
app('preferences')->setForUser($user, 'email_change_undo_token', bin2hex(random_bytes(16)));
@@ -230,7 +231,7 @@ class UserRepository implements UserRepositoryInterface
public function hasRole(null|Authenticatable|User $user, string $role): bool
{
if (null === $user) {
if (!$user instanceof Authenticatable) {
return false;
}
if ($user instanceof User) {
@@ -391,7 +392,7 @@ class UserRepository implements UserRepositoryInterface
// save old email as pref
app('preferences')->setForUser($user, 'admin_previous_email_latest', $oldEmail);
app('preferences')->setForUser($user, 'admin_previous_email_'.date('Y-m-d-H-i-s'), $oldEmail);
app('preferences')->setForUser($user, 'admin_previous_email_'.Carbon::now()->format('Y-m-d-H-i-s'), $oldEmail);
$user->email = $newEmail;
$user->save();
@@ -405,7 +406,7 @@ class UserRepository implements UserRepositoryInterface
public function removeRole(User $user, string $role): void
{
$roleObj = $this->getRole($role);
if (null === $roleObj) {
if (!$roleObj instanceof Role) {
return;
}
$user->roles()->detach($roleObj->id);

View File

@@ -134,7 +134,7 @@ class UserGroupRepository implements UserGroupRepositoryInterface, UserGroupInte
$existingGroup = null;
while ($exists && $loop < 10) {
$existingGroup = $this->findByName($groupName);
if (null === $existingGroup) {
if (!$existingGroup instanceof UserGroup) {
$exists = false;
/** @var null|UserGroup $existingGroup */

View File

@@ -40,6 +40,8 @@ use Illuminate\Support\Facades\DB;
use Override;
use stdClass;
use function Safe\json_encode;
/**
* Class AccountRepository
*
@@ -68,7 +70,7 @@ class AccountRepository implements AccountRepositoryInterface
->where('accounts.active', true)
->where(
static function (EloquentBuilder $q1) use ($number): void {
$json = \Safe\json_encode($number);
$json = json_encode($number);
$q1->where('account_meta.name', '=', 'account_number');
$q1->where('account_meta.data', '=', $json);
}
@@ -167,7 +169,7 @@ class AccountRepository implements AccountRepositoryInterface
{
$account = $this->user->accounts()->find($accountId);
if (null === $account) {
$account = $this->userGroup->accounts()->find($accountId);
return $this->userGroup->accounts()->find($accountId);
}
/** @var null|Account */

View File

@@ -49,13 +49,13 @@ class OperationsRepository implements OperationsRepositoryInterface
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setUserGroup($this->userGroup)->setRange($start, $end)->setTypes([TransactionTypeEnum::WITHDRAWAL->value]);
if (null !== $accounts && $accounts->count() > 0) {
if ($accounts instanceof Collection && $accounts->count() > 0) {
$collector->setAccounts($accounts);
}
if (null !== $budgets && $budgets->count() > 0) {
if ($budgets instanceof Collection && $budgets->count() > 0) {
$collector->setBudgets($budgets);
}
if (null === $budgets || (0 === $budgets->count())) {
if (!$budgets instanceof Collection || (0 === $budgets->count())) {
$collector->setBudgets($this->getBudgets());
}
$collector->withBudgetInformation()->withAccountInformation()->withCategoryInformation();

View File

@@ -41,6 +41,8 @@ use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use function Safe\json_encode;
/**
* Class CurrencyRepository
*
@@ -81,7 +83,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
}
// is being used in accounts:
$meta = AccountMeta::where('name', 'currency_id')->where('data', \Safe\json_encode((string) $currency->id))->count();
$meta = AccountMeta::where('name', 'currency_id')->where('data', json_encode((string) $currency->id))->count();
if ($meta > 0) {
Log::info(sprintf('Used in %d accounts as currency_id, return true. ', $meta));
@@ -89,7 +91,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
}
// second search using integer check.
$meta = AccountMeta::where('name', 'currency_id')->where('data', \Safe\json_encode((int) $currency->id))->count();
$meta = AccountMeta::where('name', 'currency_id')->where('data', json_encode((int) $currency->id))->count();
if ($meta > 0) {
Log::info(sprintf('Used in %d accounts as currency_id, return true. ', $meta));
@@ -117,7 +119,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
// is being used in accounts (as integer)
$meta = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id')
->whereNull('accounts.deleted_at')
->where('account_meta.name', 'currency_id')->where('account_meta.data', \Safe\json_encode($currency->id))->count()
->where('account_meta.name', 'currency_id')->where('account_meta.data', json_encode($currency->id))->count()
;
if ($meta > 0) {
Log::info(sprintf('Used in %d accounts as currency_id, return true. ', $meta));
@@ -239,7 +241,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
{
$result = $this->findCurrencyNull($currencyId, $currencyCode);
if (null === $result) {
if (!$result instanceof TransactionCurrency) {
Log::debug('Grabbing default currency for this user...');
/** @var null|TransactionCurrency $result */
@@ -262,11 +264,11 @@ class CurrencyRepository implements CurrencyRepositoryInterface
{
Log::debug(sprintf('Now in findCurrencyNull("%s", "%s")', $currencyId, $currencyCode));
$result = $this->find((int) $currencyId);
if (null === $result) {
if (!$result instanceof TransactionCurrency) {
Log::debug(sprintf('Searching for currency with code "%s"...', $currencyCode));
$result = $this->findByCode((string) $currencyCode);
}
if (null !== $result && false === $result->enabled) {
if ($result instanceof TransactionCurrency && false === $result->enabled) {
Log::debug(sprintf('Also enabled currency %s', $result->code));
$this->enable($result);
}

View File

@@ -109,7 +109,7 @@ class ExchangeRateRepository implements ExchangeRateRepositoryInterface
public function updateExchangeRate(CurrencyExchangeRate $object, string $rate, ?Carbon $date = null): CurrencyExchangeRate
{
$object->rate = $rate;
if (null !== $date) {
if ($date instanceof Carbon) {
$object->date = $date;
}
$object->save();