mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-22 20:16:22 +00:00
Catch null pointers
This commit is contained in:
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Repositories\Journal;
|
namespace FireflyIII\Repositories\Journal;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\Note;
|
use FireflyIII\Models\Note;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
@@ -386,6 +387,9 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
{
|
{
|
||||||
/** @var Transaction $transaction */
|
/** @var Transaction $transaction */
|
||||||
$transaction = $journal->transactions()->with('account')->where('amount', '<', 0)->first();
|
$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;
|
return $transaction->account;
|
||||||
}
|
}
|
||||||
@@ -397,6 +401,9 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
{
|
{
|
||||||
/** @var Transaction $transaction */
|
/** @var Transaction $transaction */
|
||||||
$transaction = $journal->transactions()->with('account')->where('amount', '>', 0)->first();
|
$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;
|
return $transaction->account;
|
||||||
}
|
}
|
||||||
|
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Repositories\Journal;
|
namespace FireflyIII\Repositories\Journal;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\TransactionGroup;
|
use FireflyIII\Models\TransactionGroup;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
@@ -114,7 +115,9 @@ interface JournalRepositoryInterface
|
|||||||
* Returns the source account of the journal.
|
* Returns the source account of the journal.
|
||||||
*
|
*
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
|
*
|
||||||
* @return Account
|
* @return Account
|
||||||
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function getSourceAccount(TransactionJournal $journal): Account;
|
public function getSourceAccount(TransactionJournal $journal): Account;
|
||||||
|
|
||||||
@@ -123,6 +126,7 @@ interface JournalRepositoryInterface
|
|||||||
*
|
*
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
* @return Account
|
* @return Account
|
||||||
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function getDestinationAccount(TransactionJournal $journal): Account;
|
public function getDestinationAccount(TransactionJournal $journal): Account;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user