mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-26 13:36:15 +00:00
Fix various code.
This commit is contained in:
@@ -125,7 +125,7 @@ class AccountTransformer extends AbstractTransformer
|
||||
'currency_code' => $account->meta['currency']?->code,
|
||||
'currency_symbol' => $account->meta['currency']?->symbol,
|
||||
'currency_decimal_places' => $account->meta['currency']?->decimal_places,
|
||||
'native_currency_id' => null === $native ? null : (string) $native->id,
|
||||
'native_currency_id' => $native instanceof TransactionCurrency ? (string) $native->id : null,
|
||||
'native_currency_code' => $native?->code,
|
||||
'native_currency_symbol' => $native?->symbol,
|
||||
'native_currency_decimal_places' => $native?->decimal_places,
|
||||
@@ -166,7 +166,7 @@ class AccountTransformer extends AbstractTransformer
|
||||
{
|
||||
$accountRole = $account->meta['account_role'] ?? null;
|
||||
if ('asset' !== $accountType || '' === (string) $accountRole) {
|
||||
$accountRole = null;
|
||||
return null;
|
||||
}
|
||||
|
||||
return $accountRole;
|
||||
@@ -177,12 +177,11 @@ class AccountTransformer extends AbstractTransformer
|
||||
*/
|
||||
private function getDate(): Carbon
|
||||
{
|
||||
$date = today(config('app.timezone'));
|
||||
if (null !== $this->parameters->get('date')) {
|
||||
$date = $this->parameters->get('date');
|
||||
return $this->parameters->get('date');
|
||||
}
|
||||
|
||||
return $date;
|
||||
return today(config('app.timezone'));
|
||||
}
|
||||
|
||||
private function getCCInfo(Account $account, ?string $accountRole, string $accountType): array
|
||||
@@ -197,7 +196,7 @@ class AccountTransformer extends AbstractTransformer
|
||||
// try classic date:
|
||||
if (10 === strlen($monthlyPaymentDate)) {
|
||||
$object = Carbon::createFromFormat('!Y-m-d', $monthlyPaymentDate, config('app.timezone'));
|
||||
if (null === $object) {
|
||||
if (!$object instanceof Carbon) {
|
||||
$object = today(config('app.timezone'));
|
||||
}
|
||||
$monthlyPaymentDate = $object->toAtomString();
|
||||
@@ -223,7 +222,7 @@ class AccountTransformer extends AbstractTransformer
|
||||
}
|
||||
if (null !== $openingBalanceDate) {
|
||||
$object = Carbon::createFromFormat('Y-m-d H:i:s', $openingBalanceDate, config('app.timezone'));
|
||||
if (null === $object) {
|
||||
if (!$object instanceof Carbon) {
|
||||
$object = today(config('app.timezone'));
|
||||
}
|
||||
$openingBalanceDate = $object->toAtomString();
|
||||
|
||||
@@ -74,7 +74,7 @@ class AvailableBudgetTransformer extends AbstractTransformer
|
||||
'currency_code' => $currency->code,
|
||||
'currency_symbol' => $currency->symbol,
|
||||
'currency_decimal_places' => $currency->decimal_places,
|
||||
'native_currency_id' => null === $default ? null : (string) $default->id,
|
||||
'native_currency_id' => $default instanceof TransactionCurrency ? (string) $default->id : null,
|
||||
'native_currency_code' => $default?->code,
|
||||
'native_currency_symbol' => $default?->symbol,
|
||||
'native_currency_decimal_places' => $default?->decimal_places,
|
||||
|
||||
@@ -91,7 +91,7 @@ class BillTransformer extends AbstractTransformer
|
||||
$payDatesFormatted = [];
|
||||
foreach ($paidData as $object) {
|
||||
$date = Carbon::createFromFormat('!Y-m-d', $object['date'], config('app.timezone'));
|
||||
if (null === $date) {
|
||||
if (!$date instanceof Carbon) {
|
||||
$date = today(config('app.timezone'));
|
||||
}
|
||||
$object['date'] = $date->toAtomString();
|
||||
@@ -100,7 +100,7 @@ class BillTransformer extends AbstractTransformer
|
||||
|
||||
foreach ($payDates as $string) {
|
||||
$date = Carbon::createFromFormat('!Y-m-d', $string, config('app.timezone'));
|
||||
if (null === $date) {
|
||||
if (!$date instanceof Carbon) {
|
||||
$date = today(config('app.timezone'));
|
||||
}
|
||||
$payDatesFormatted[] = $date->toAtomString();
|
||||
@@ -113,7 +113,7 @@ class BillTransformer extends AbstractTransformer
|
||||
|
||||
if (null !== $firstPayDate) {
|
||||
$nemDate = Carbon::createFromFormat('!Y-m-d', $firstPayDate, config('app.timezone'));
|
||||
if (null === $nemDate) {
|
||||
if (!$nemDate instanceof Carbon) {
|
||||
$nemDate = today(config('app.timezone'));
|
||||
}
|
||||
$nem = $nemDate->toAtomString();
|
||||
@@ -138,7 +138,7 @@ class BillTransformer extends AbstractTransformer
|
||||
$current = $payDatesFormatted[0] ?? null;
|
||||
if (null !== $current && !$nemDate->isToday()) {
|
||||
$temp2 = Carbon::createFromFormat('Y-m-d\TH:i:sP', $current);
|
||||
if (null === $temp2) {
|
||||
if (!$temp2 instanceof Carbon) {
|
||||
$temp2 = today(config('app.timezone'));
|
||||
}
|
||||
$nemDiff = trans('firefly.bill_expected_date', ['date' => $temp2->diffForHumans(today(config('app.timezone')), CarbonInterface::DIFF_RELATIVE_TO_NOW)]);
|
||||
|
||||
@@ -111,7 +111,7 @@ class BudgetLimitTransformer extends AbstractTransformer
|
||||
'currency_name' => $currencyName,
|
||||
'currency_decimal_places' => $currencyDecimalPlaces,
|
||||
'currency_symbol' => $currencySymbol,
|
||||
'native_currency_id' => null === $default ? null : (string) $default->id,
|
||||
'native_currency_id' => $default instanceof TransactionCurrency ? (string) $default->id : null,
|
||||
'native_currency_code' => $default?->code,
|
||||
'native_currency_symbol' => $default?->symbol,
|
||||
'native_currency_decimal_places' => $default?->decimal_places,
|
||||
|
||||
@@ -113,7 +113,7 @@ class BudgetTransformer extends AbstractTransformer
|
||||
'currency_decimal_places' => $autoBudget?->transactionCurrency->decimal_places,
|
||||
'currency_symbol' => $autoBudget?->transactionCurrency->symbol,
|
||||
|
||||
'native_currency_id' => null === $default ? null : (string) $default->id,
|
||||
'native_currency_id' => $default instanceof TransactionCurrency ? (string) $default->id : null,
|
||||
'native_currency_code' => $default?->code,
|
||||
'native_currency_symbol' => $default?->symbol,
|
||||
'native_currency_decimal_places' => $default?->decimal_places,
|
||||
|
||||
@@ -80,7 +80,7 @@ class CategoryTransformer extends AbstractTransformer
|
||||
'updated_at' => $category->updated_at->toAtomString(),
|
||||
'name' => $category->name,
|
||||
'notes' => $notes,
|
||||
'native_currency_id' => null === $default ? null : (string) $default->id,
|
||||
'native_currency_id' => $default instanceof TransactionCurrency ? (string) $default->id : null,
|
||||
'native_currency_code' => $default?->code,
|
||||
'native_currency_symbol' => $default?->symbol,
|
||||
'native_currency_decimal_places' => $default?->decimal_places,
|
||||
|
||||
@@ -37,6 +37,8 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
||||
|
||||
use function Safe\json_decode;
|
||||
|
||||
/**
|
||||
* Class RecurringTransactionTransformer
|
||||
*/
|
||||
@@ -264,7 +266,7 @@ class RecurrenceTransformer extends AbstractTransformer
|
||||
break;
|
||||
|
||||
case 'tags':
|
||||
$array['tags'] = \Safe\json_decode($transactionMeta->value);
|
||||
$array['tags'] = json_decode((string) $transactionMeta->value);
|
||||
|
||||
break;
|
||||
|
||||
|
||||
@@ -306,7 +306,7 @@ class TransactionGroupTransformer extends AbstractTransformer
|
||||
$latitude = null;
|
||||
$zoomLevel = null;
|
||||
$location = $this->getLocation($journal);
|
||||
if (null !== $location) {
|
||||
if ($location instanceof Location) {
|
||||
$longitude = $location->longitude;
|
||||
$latitude = $location->latitude;
|
||||
$zoomLevel = $location->zoom_level;
|
||||
@@ -428,12 +428,11 @@ class TransactionGroupTransformer extends AbstractTransformer
|
||||
|
||||
private function getForeignAmount(?string $foreignAmount): ?string
|
||||
{
|
||||
$result = null;
|
||||
if (null !== $foreignAmount && '' !== $foreignAmount && 0 !== bccomp('0', $foreignAmount)) {
|
||||
$result = app('steam')->positive($foreignAmount);
|
||||
return app('steam')->positive($foreignAmount);
|
||||
}
|
||||
|
||||
return $result;
|
||||
return null;
|
||||
}
|
||||
|
||||
private function getDates(NullArrayObject $dates): array
|
||||
@@ -465,7 +464,7 @@ class TransactionGroupTransformer extends AbstractTransformer
|
||||
'symbol' => null,
|
||||
'decimal_places' => null,
|
||||
];
|
||||
if (null === $currency) {
|
||||
if (!$currency instanceof TransactionCurrency) {
|
||||
return $array;
|
||||
}
|
||||
$array['id'] = $currency->id;
|
||||
@@ -482,7 +481,7 @@ class TransactionGroupTransformer extends AbstractTransformer
|
||||
'id' => null,
|
||||
'name' => null,
|
||||
];
|
||||
if (null === $budget) {
|
||||
if (!$budget instanceof Budget) {
|
||||
return $array;
|
||||
}
|
||||
$array['id'] = $budget->id;
|
||||
@@ -497,7 +496,7 @@ class TransactionGroupTransformer extends AbstractTransformer
|
||||
'id' => null,
|
||||
'name' => null,
|
||||
];
|
||||
if (null === $category) {
|
||||
if (!$category instanceof Category) {
|
||||
return $array;
|
||||
}
|
||||
$array['id'] = $category->id;
|
||||
@@ -512,7 +511,7 @@ class TransactionGroupTransformer extends AbstractTransformer
|
||||
'id' => null,
|
||||
'name' => null,
|
||||
];
|
||||
if (null === $bill) {
|
||||
if (!$bill instanceof Bill) {
|
||||
return $array;
|
||||
}
|
||||
$array['id'] = (string) $bill->id;
|
||||
|
||||
@@ -127,12 +127,11 @@ class AccountTransformer extends AbstractTransformer
|
||||
|
||||
private function getDate(): Carbon
|
||||
{
|
||||
$date = today(config('app.timezone'));
|
||||
if (null !== $this->parameters->get('date')) {
|
||||
$date = $this->parameters->get('date');
|
||||
return $this->parameters->get('date');
|
||||
}
|
||||
|
||||
return $date;
|
||||
return today(config('app.timezone'));
|
||||
}
|
||||
|
||||
private function getDefaultCurrency(): void
|
||||
|
||||
@@ -269,7 +269,7 @@ class BillTransformer extends AbstractTransformer
|
||||
}
|
||||
if ($nextMatch->isSameDay($lastPaidDate)) {
|
||||
// Add another period because it's the same day as the last paid date.
|
||||
$nextMatch = app('navigation')->addPeriod($nextMatch, $bill->repeat_freq, $bill->skip);
|
||||
return app('navigation')->addPeriod($nextMatch, $bill->repeat_freq, $bill->skip);
|
||||
}
|
||||
|
||||
return $nextMatch;
|
||||
|
||||
@@ -248,12 +248,12 @@ class PiggyBankTransformer extends AbstractTransformer
|
||||
private function getSuggestedMonthlyAmount(string $currentAmount, string $targetAmount, ?Carbon $startDate, ?Carbon $targetDate): string
|
||||
{
|
||||
$savePerMonth = '0';
|
||||
if (null === $targetDate) {
|
||||
if (!$targetDate instanceof Carbon) {
|
||||
return '0';
|
||||
}
|
||||
if (bccomp($currentAmount, $targetAmount) < 1) {
|
||||
$now = today(config('app.timezone'));
|
||||
$startDate = null !== $startDate && $startDate->gte($now) ? $startDate : $now;
|
||||
$startDate = $startDate instanceof Carbon && $startDate->gte($now) ? $startDate : $now;
|
||||
$diffInMonths = (int) $startDate->diffInMonths($targetDate);
|
||||
$remainingAmount = bcsub($targetAmount, $currentAmount);
|
||||
|
||||
|
||||
@@ -465,7 +465,7 @@ class TransactionGroupTransformer extends AbstractTransformer
|
||||
// app('log')->debug(sprintf('Now in date("%s")', $string));
|
||||
if (10 === strlen($string)) {
|
||||
$res = Carbon::createFromFormat('Y-m-d', $string, config('app.timezone'));
|
||||
if (null === $res) {
|
||||
if (!$res instanceof Carbon) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -476,7 +476,7 @@ class TransactionGroupTransformer extends AbstractTransformer
|
||||
}
|
||||
if (19 === strlen($string) && str_contains($string, 'T')) {
|
||||
$res = Carbon::createFromFormat('Y-m-d\TH:i:s', substr($string, 0, 19), config('app.timezone'));
|
||||
if (null === $res) {
|
||||
if (!$res instanceof Carbon) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -485,7 +485,7 @@ class TransactionGroupTransformer extends AbstractTransformer
|
||||
|
||||
// 2022-01-01 01:01:01
|
||||
$res = Carbon::createFromFormat('Y-m-d H:i:s', substr($string, 0, 19), config('app.timezone'));
|
||||
if (null === $res) {
|
||||
if (!$res instanceof Carbon) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,8 @@ namespace FireflyIII\Transformers;
|
||||
use FireflyIII\Models\WebhookMessage;
|
||||
use JsonException;
|
||||
|
||||
use function Safe\json_encode;
|
||||
|
||||
/**
|
||||
* Class WebhookMessageTransformer
|
||||
*/
|
||||
@@ -40,7 +42,7 @@ class WebhookMessageTransformer extends AbstractTransformer
|
||||
$json = '{}';
|
||||
|
||||
try {
|
||||
$json = \Safe\json_encode($message->message, JSON_THROW_ON_ERROR);
|
||||
$json = json_encode($message->message, JSON_THROW_ON_ERROR);
|
||||
} catch (JsonException $e) {
|
||||
app('log')->error(sprintf('Could not encode webhook message #%d: %s', $message->id, $e->getMessage()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user