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

@@ -38,8 +38,8 @@ class AccountController extends Controller
public function moveTransactions(MoveTransactionsRequest $request): JsonResponse
{
$accountIds = $request->getAll();
$original = $this->repository->findNull($accountIds['original_account']);
$destination = $this->repository->findNull($accountIds['destination_account']);
$original = $this->repository->find($accountIds['original_account']);
$destination = $this->repository->find($accountIds['destination_account']);
/** @var AccountDestroyService $service */
$service = app(AccountDestroyService::class);

View File

@@ -38,7 +38,7 @@ use Illuminate\Http\JsonResponse;
*
* Shows income information grouped or limited by date.
* Ie. all income grouped by account + currency.
* See reference nr. 75
* See reference nr. 75
*/
class AccountController extends Controller
{
@@ -74,8 +74,9 @@ class AccountController extends Controller
}
/**
* See reference nr. 76
* See reference nr. 77
* See reference nr. 76
* See reference nr. 77
*
* @param GenericRequest $request
*
* @return JsonResponse
@@ -103,7 +104,7 @@ class AccountController extends Controller
}
/**
* See reference nr. 78
* See reference nr. 78
*
* @param GenericRequest $request
*

View File

@@ -78,8 +78,8 @@ class StoreController extends Controller
{
$manager = $this->getManager();
$data = $request->getAll();
$inward = $this->journalRepository->findNull($data['inward_id'] ?? 0);
$outward = $this->journalRepository->findNull($data['outward_id'] ?? 0);
$inward = $this->journalRepository->find($data['inward_id'] ?? 0);
$outward = $this->journalRepository->find($data['outward_id'] ?? 0);
if (null === $inward || null === $outward) {
throw new FireflyException('200024: Source or destination does not exist.');
}

View File

@@ -175,7 +175,7 @@ class BasicController extends Controller
// format amounts:
$keys = array_keys($sums);
foreach ($keys as $currencyId) {
$currency = $this->currencyRepos->findNull($currencyId);
$currency = $this->currencyRepos->find($currencyId);
if (null === $currency) {
continue;
}
@@ -239,7 +239,7 @@ class BasicController extends Controller
$return = [];
foreach ($paidAmount as $currencyId => $amount) {
$amount = bcmul($amount, '-1');
$currency = $this->currencyRepos->findNull((int)$currencyId);
$currency = $this->currencyRepos->find((int)$currencyId);
if (null === $currency) {
continue;
}
@@ -259,7 +259,7 @@ class BasicController extends Controller
foreach ($unpaidAmount as $currencyId => $amount) {
$amount = bcmul($amount, '-1');
$currency = $this->currencyRepos->findNull((int)$currencyId);
$currency = $this->currencyRepos->find((int)$currencyId);
if (null === $currency) {
continue;
}

View File

@@ -55,8 +55,8 @@ class MoveTransactionsRequest extends FormRequest
if (array_key_exists('original_account', $data) && array_key_exists('destination_account', $data)) {
$repository = app(AccountRepositoryInterface::class);
$repository->setUser(auth()->user());
$original = $repository->findNull((int)$data['original_account']);
$destination = $repository->findNull((int)$data['destination_account']);
$original = $repository->find((int)$data['original_account']);
$destination = $repository->find((int)$data['destination_account']);
if ($original->accountType->type !== $destination->accountType->type) {
$validator->errors()->add('title', (string)trans('validation.same_account_type'));

View File

@@ -53,7 +53,7 @@ class ExportRequest extends FormRequest
foreach ($parts as $part) {
$accountId = (int)$part;
if (0 !== $accountId) {
$account = $repository->findNull($accountId);
$account = $repository->find($accountId);
if (null !== $account && AccountType::ASSET === $account->accountType->type) {
$accounts->push($account);
}

View File

@@ -95,7 +95,7 @@ class GenericRequest extends FormRequest
if (is_array($array)) {
foreach ($array as $accountId) {
$accountId = (int)$accountId;
$account = $repository->findNull($accountId);
$account = $repository->find($accountId);
if (null !== $account) {
$this->accounts->push($account);
}
@@ -159,7 +159,7 @@ class GenericRequest extends FormRequest
if (is_array($array)) {
foreach ($array as $budgetId) {
$budgetId = (int)$budgetId;
$budget = $repository->findNull($budgetId);
$budget = $repository->find($budgetId);
if (null !== $budgetId) {
$this->budgets->push($budget);
}
@@ -191,7 +191,7 @@ class GenericRequest extends FormRequest
if (is_array($array)) {
foreach ($array as $categoryId) {
$categoryId = (int)$categoryId;
$category = $repository->findNull($categoryId);
$category = $repository->find($categoryId);
if (null !== $categoryId) {
$this->categories->push($category);
}
@@ -281,7 +281,7 @@ class GenericRequest extends FormRequest
if (is_array($array)) {
foreach ($array as $tagId) {
$tagId = (int)$tagId;
$tag = $repository->findNull($tagId);
$tag = $repository->find($tagId);
if (null !== $tagId) {
$this->tags->push($tag);
}

View File

@@ -104,8 +104,8 @@ class StoreRequest extends FormRequest
$data = $validator->getData();
$inwardId = (int)($data['inward_id'] ?? 0);
$outwardId = (int)($data['outward_id'] ?? 0);
$inward = $journalRepos->findNull($inwardId);
$outward = $journalRepos->findNull($outwardId);
$inward = $journalRepos->find($inwardId);
$outward = $journalRepos->find($outwardId);
if (null === $inward) {
$validator->errors()->add('inward_id', 'Invalid inward ID.');

View File

@@ -104,8 +104,8 @@ class UpdateRequest extends FormRequest
$inwardId = $data['inward_id'] ?? $existing->source_id;
$outwardId = $data['outward_id'] ?? $existing->destination_id;
$inward = $journalRepos->findNull((int)$inwardId);
$outward = $journalRepos->findNull((int)$outwardId);
$inward = $journalRepos->find((int)$inwardId);
$outward = $journalRepos->find((int)$outwardId);
if (null === $inward) {
$inward = $existing->source;
}