From 52df2edc8fc7bc3802469953227c9db878a3795d Mon Sep 17 00:00:00 2001 From: James Cole Date: Mon, 6 Jul 2015 18:48:17 +0200 Subject: [PATCH] Fixed the last issues. Now onto code complexity. --- app/Repositories/Account/AccountRepository.php | 8 ++++++-- app/Repositories/Journal/JournalRepository.php | 10 ++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index 2631f655e5..447bb4adbf 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -389,7 +389,9 @@ class AccountRepository implements AccountRepositoryInterface public function store(array $data) { $newAccount = $this->storeAccount($data); - $this->storeMetadata($newAccount, $data); + if (!is_null($newAccount)) { + $this->storeMetadata($newAccount, $data); + } // continue with the opposing account: @@ -457,7 +459,9 @@ class AccountRepository implements AccountRepositoryInterface 'virtualBalance' => 0, ]; $opposing = $this->storeAccount($opposingData); - $this->storeInitialBalance($account, $opposing, $data); + if (!is_null($opposing)) { + $this->storeInitialBalance($account, $opposing, $data); + } } } else { diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.php index 11cce176e9..4bf1e742c4 100644 --- a/app/Repositories/Journal/JournalRepository.php +++ b/app/Repositories/Journal/JournalRepository.php @@ -143,7 +143,9 @@ class JournalRepository implements JournalRepositoryInterface foreach ($array as $name) { if (strlen(trim($name)) > 0) { $tag = Tag::firstOrCreateEncrypted(['tag' => $name, 'user_id' => $journal->user_id]); - $tagRepository->connect($journal, $tag); + if (!is_null($tag)) { + $tagRepository->connect($journal, $tag); + } } } } @@ -186,19 +188,19 @@ class JournalRepository implements JournalRepositoryInterface } // store accounts (depends on type) - list($from, $to) = $this->storeAccounts($transactionType, $data); + list($fromAccount, $toAccount) = $this->storeAccounts($transactionType, $data); // store accompanying transactions. Transaction::create( // first transaction. [ - 'account_id' => $from->id, + 'account_id' => $fromAccount->id, 'transaction_journal_id' => $journal->id, 'amount' => $data['amount'] * -1 ] ); Transaction::create( // second transaction. [ - 'account_id' => $to->id, + 'account_id' => $toAccount->id, 'transaction_journal_id' => $journal->id, 'amount' => $data['amount'] ]