From b4edd3dcc4b5e022481a77978b25ca3e5c2c8825 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 8 Nov 2024 21:02:36 +0100 Subject: [PATCH] Catch potential nullpointers --- app/Repositories/PiggyBank/ModifiesPiggyBanks.php | 4 ++-- app/Support/Models/AccountBalanceCalculator.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Repositories/PiggyBank/ModifiesPiggyBanks.php b/app/Repositories/PiggyBank/ModifiesPiggyBanks.php index 7fa1c4c42d..df3e98c10e 100644 --- a/app/Repositories/PiggyBank/ModifiesPiggyBanks.php +++ b/app/Repositories/PiggyBank/ModifiesPiggyBanks.php @@ -377,11 +377,11 @@ trait ModifiesPiggyBanks } if (array_key_exists('targetdate', $data) && '' !== $data['targetdate']) { $piggyBank->targetdate = $data['targetdate']; - $piggyBank->targetdate_tz = $data['targetdate']->format('e'); + $piggyBank->targetdate_tz = $data['targetdate']?->format('e'); } if (array_key_exists('startdate', $data)) { $piggyBank->startdate = $data['startdate']; - $piggyBank->startdate_tz = $data['targetdate']->format('e'); + $piggyBank->startdate_tz = $data['targetdate']?->format('e'); } $piggyBank->save(); diff --git a/app/Support/Models/AccountBalanceCalculator.php b/app/Support/Models/AccountBalanceCalculator.php index cd0e0860c7..94908ed2b3 100644 --- a/app/Support/Models/AccountBalanceCalculator.php +++ b/app/Support/Models/AccountBalanceCalculator.php @@ -236,12 +236,12 @@ class AccountBalanceCalculator 'balance' => '0', 'transaction_currency_id' => $currencyId, 'date' => $balance[1], - 'date_tz' => $balance[1]->format('e'), + 'date_tz' => $balance[1]?->format('e'), ] ); $object->balance = $balance[0]; $object->date = $balance[1]; - $object->date_tz = $balance[1]->format('e'); + $object->date_tz = $balance[1]?->format('e'); $object->save(); } }