mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Catch null pointers
This commit is contained in:
parent
ec335ae88c
commit
2ba6ffccbc
@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Repositories\Journal;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\Note;
|
||||
use FireflyIII\Models\Transaction;
|
||||
@ -386,6 +387,9 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
{
|
||||
/** @var Transaction $transaction */
|
||||
$transaction = $journal->transactions()->with('account')->where('amount', '<', 0)->first();
|
||||
if (null === $transaction) {
|
||||
throw new FireflyException(sprintf('Your administration is broken. Transaction journal #%d has no source transaction.', $journal->id));
|
||||
}
|
||||
|
||||
return $transaction->account;
|
||||
}
|
||||
@ -397,6 +401,9 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
{
|
||||
/** @var Transaction $transaction */
|
||||
$transaction = $journal->transactions()->with('account')->where('amount', '>', 0)->first();
|
||||
if (null === $transaction) {
|
||||
throw new FireflyException(sprintf('Your administration is broken. Transaction journal #%d has no destination transaction.', $journal->id));
|
||||
}
|
||||
|
||||
return $transaction->account;
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Repositories\Journal;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\TransactionGroup;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
@ -114,7 +115,9 @@ interface JournalRepositoryInterface
|
||||
* Returns the source account of the journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return Account
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function getSourceAccount(TransactionJournal $journal): Account;
|
||||
|
||||
@ -123,6 +126,7 @@ interface JournalRepositoryInterface
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @return Account
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function getDestinationAccount(TransactionJournal $journal): Account;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user