Refactor findNull to find

This commit is contained in:
James Cole
2021-06-30 06:17:38 +02:00
parent b7ae5eda35
commit 70da5917c9
68 changed files with 120 additions and 273 deletions

View File

@@ -130,17 +130,7 @@ class AccountRepository implements AccountRepositoryInterface
$query->whereIn('account_types.type', $types);
}
// See reference nr. 9
$accounts = $query->get(['accounts.*']);
/** @var Account $account */
foreach ($accounts as $account) {
if ($account->iban === $iban) {
return $account;
}
}
return null;
return $query->where('iban', $iban)->first(['accounts.*']);
}
/**
@@ -161,7 +151,7 @@ class AccountRepository implements AccountRepositoryInterface
$accounts = $query->get(['accounts.*']);
// See reference nr. 10
// See reference nr. 10
/** @var Account $account */
foreach ($accounts as $account) {
@@ -181,7 +171,7 @@ class AccountRepository implements AccountRepositoryInterface
*
* @return Account|null
*/
public function findNull(int $accountId): ?Account
public function find(int $accountId): ?Account
{
return $this->user->accounts()->find($accountId);
}

View File

@@ -95,7 +95,7 @@ interface AccountRepositoryInterface
*
* @return Account|null
*/
public function findNull(int $accountId): ?Account;
public function find(int $accountId): ?Account;
/**
* @param Account $account

View File

@@ -207,7 +207,7 @@ class AccountTasker implements AccountTaskerInterface
$sourceId = (int)$journal['destination_account_id'];
$currencyId = (int)$journal['currency_id'];
$key = sprintf('%s-%s', $sourceId, $currencyId);
$currencies[$currencyId] = $currencies[$currencyId] ?? $currencyRepos->findNull($currencyId);
$currencies[$currencyId] = $currencies[$currencyId] ?? $currencyRepos->find($currencyId);
$report['accounts'][$key] = $report['accounts'][$key] ?? [
'id' => $sourceId,
'name' => $journal['destination_account_name'],
@@ -269,7 +269,7 @@ class AccountTasker implements AccountTaskerInterface
$currencyId = (int)$journal['currency_id'];
$key = sprintf('%s-%s', $sourceId, $currencyId);
if (!array_key_exists($key, $report['accounts'])) {
$currencies[$currencyId] = $currencies[$currencyId] ?? $currencyRepos->findNull($currencyId);
$currencies[$currencyId] = $currencies[$currencyId] ?? $currencyRepos->find($currencyId);
$report['accounts'][$key] = [
'id' => $sourceId,
'name' => $journal['source_account_name'],