mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Fix possible null pointer.
This commit is contained in:
@@ -24,6 +24,8 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Factory;
|
||||
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class TransactionCurrencyFactory
|
||||
@@ -33,21 +35,26 @@ class TransactionCurrencyFactory
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return TransactionCurrency
|
||||
* @return TransactionCurrency|null
|
||||
*/
|
||||
public function create(array $data): TransactionCurrency
|
||||
public function create(array $data): ?TransactionCurrency
|
||||
{
|
||||
/** @var TransactionCurrency $currency */
|
||||
$currency = TransactionCurrency::create(
|
||||
[
|
||||
'name' => $data['name'],
|
||||
'code' => $data['code'],
|
||||
'symbol' => $data['symbol'],
|
||||
'decimal_places' => $data['decimal_places'],
|
||||
]
|
||||
);
|
||||
$result = null;
|
||||
try {
|
||||
/** @var TransactionCurrency $currency */
|
||||
$result = TransactionCurrency::create(
|
||||
[
|
||||
'name' => $data['name'],
|
||||
'code' => $data['code'],
|
||||
'symbol' => $data['symbol'],
|
||||
'decimal_places' => $data['decimal_places'],
|
||||
]
|
||||
);
|
||||
} catch (QueryException $e) {
|
||||
Log::error(sprintf('Could not create new currency: %s', $e->getMessage()));
|
||||
}
|
||||
|
||||
return $currency;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -43,7 +43,7 @@ class TransactionJournalMetaFactory
|
||||
$value = $data['data'];
|
||||
/** @var TransactionJournalMeta $entry */
|
||||
$entry = $data['journal']->transactionJournalMeta()->where('name', $data['name'])->first();
|
||||
if (is_null($value) && !is_null($entry)) {
|
||||
if (null === $value && null !== $entry) {
|
||||
try {
|
||||
$entry->delete();
|
||||
} catch (Exception $e) { // @codeCoverageIgnore
|
||||
@@ -56,9 +56,9 @@ class TransactionJournalMetaFactory
|
||||
if ($data['data'] instanceof Carbon) {
|
||||
$value = $data['data']->toW3cString();
|
||||
}
|
||||
if (strlen(strval($value)) === 0) {
|
||||
if ((string)$value === '') {
|
||||
// don't store blank strings.
|
||||
if (!is_null($entry)) {
|
||||
if (null !== $entry) {
|
||||
try {
|
||||
$entry->delete();
|
||||
} catch (Exception $e) { // @codeCoverageIgnore
|
||||
@@ -69,7 +69,6 @@ class TransactionJournalMetaFactory
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
if (null === $entry) {
|
||||
$entry = new TransactionJournalMeta();
|
||||
$entry->transactionJournal()->associate($data['journal']);
|
||||
|
Reference in New Issue
Block a user