Update find methods to return null

This commit is contained in:
James Cole
2018-02-16 15:19:19 +01:00
parent 28b00f6507
commit 33db99ffd3
16 changed files with 142 additions and 34 deletions

View File

@@ -44,12 +44,13 @@ use Validator;
*/
class AccountRepository implements AccountRepositoryInterface
{
/** @var User */
private $user;
use FindAccountsTrait;
/** @var array */
private $validAssetFields = ['accountRole', 'accountNumber', 'currency_id', 'BIC'];
use FindAccountsTrait;
/** @var array */
private $validCCFields = ['accountRole', 'ccMonthlyPaymentDate', 'ccType', 'accountNumber', 'currency_id', 'BIC'];
/** @var array */
@@ -91,6 +92,16 @@ class AccountRepository implements AccountRepositoryInterface
return true;
}
/**
* @param int $accountId
*
* @return Account|null
*/
public function findNull(int $accountId): ?Account
{
return $this->user->accounts()->find($accountId);
}
/**
* Return account type by string.
*
@@ -336,7 +347,7 @@ class AccountRepository implements AccountRepositoryInterface
// account may exist already:
$existingAccount = $this->findByName($data['name'], [$type]);
if (null !== $existingAccount->id) {
if (null !== $existingAccount) {
Log::warning(sprintf('There already is an account named "%s" of type "%s".', $data['name'], $type));
return $existingAccount;