More PHP8.4 updates

This commit is contained in:
James Cole
2025-05-04 13:47:00 +02:00
parent e42107c03c
commit 51e86448c7
195 changed files with 524 additions and 715 deletions

View File

@@ -96,7 +96,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface, UserGroup
/** @var BudgetLimit $budgetLimit */
foreach ($set as $budgetLimit) {
$result = bcadd($budgetLimit->amount, $result);
$result = bcadd((string) $budgetLimit->amount, $result);
}
return $result;
@@ -127,9 +127,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface, UserGroup
public function getAllBudgetLimitsByCurrency(TransactionCurrency $currency, ?Carbon $start = null, ?Carbon $end = null): Collection
{
return $this->getAllBudgetLimits($start, $end)->filter(
static function (BudgetLimit $budgetLimit) use ($currency) {
return $budgetLimit->transaction_currency_id === $currency->id;
}
static fn(BudgetLimit $budgetLimit) => $budgetLimit->transaction_currency_id === $currency->id
);
}

View File

@@ -121,7 +121,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
];
// same period
if ($limit->start_date->isSameDay($start) && $limit->end_date->isSameDay($end)) {
$return[$currencyCode]['sum'] = bcadd($return[$currencyCode]['sum'], $limit->amount);
$return[$currencyCode]['sum'] = bcadd($return[$currencyCode]['sum'], (string) $limit->amount);
$return[$currencyCode]['native_sum'] = bcmul($rate, $return[$currencyCode]['sum']);
app('log')->debug(sprintf('Add full amount [1]: %s', $limit->amount));
@@ -129,7 +129,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
}
// limit is inside of date range
if ($start->lte($limit->start_date) && $end->gte($limit->end_date)) {
$return[$currencyCode]['sum'] = bcadd($return[$currencyCode]['sum'], $limit->amount);
$return[$currencyCode]['sum'] = bcadd($return[$currencyCode]['sum'], (string) $limit->amount);
$return[$currencyCode]['native_sum'] = bcmul($rate, $return[$currencyCode]['sum']);
app('log')->debug(sprintf('Add full amount [2]: %s', $limit->amount));
@@ -137,13 +137,13 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
}
$total = $limit->start_date->diffInDays($limit->end_date, true) + 1; // include the day itself.
$days = $this->daysInOverlap($limit, $start, $end);
$amount = bcmul(bcdiv($limit->amount, (string) $total), (string) $days);
$amount = bcmul(bcdiv((string) $limit->amount, (string) $total), (string) $days);
$return[$currencyCode]['sum'] = bcadd($return[$currencyCode]['sum'], $amount);
$return[$currencyCode]['native_sum'] = bcmul($rate, $return[$currencyCode]['sum']);
app('log')->debug(
sprintf(
'Amount per day: %s (%s over %d days). Total amount for %d days: %s',
bcdiv($limit->amount, (string) $total),
bcdiv((string) $limit->amount, (string) $total),
$limit->amount,
$total,
$days,
@@ -225,26 +225,26 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
];
// same period
if ($limit->start_date->isSameDay($start) && $limit->end_date->isSameDay($end)) {
$return[$currency->id]['sum'] = bcadd($return[$currency->id]['sum'], $limit->amount);
$return[$currency->id]['sum'] = bcadd($return[$currency->id]['sum'], (string) $limit->amount);
app('log')->debug(sprintf('Add full amount [1]: %s', $limit->amount));
continue;
}
// limit is inside of date range
if ($start->lte($limit->start_date) && $end->gte($limit->end_date)) {
$return[$currency->id]['sum'] = bcadd($return[$currency->id]['sum'], $limit->amount);
$return[$currency->id]['sum'] = bcadd($return[$currency->id]['sum'], (string) $limit->amount);
app('log')->debug(sprintf('Add full amount [2]: %s', $limit->amount));
continue;
}
$total = $limit->start_date->diffInDays($limit->end_date) + 1; // include the day itself.
$days = $this->daysInOverlap($limit, $start, $end);
$amount = bcmul(bcdiv($limit->amount, (string) $total), (string) $days);
$amount = bcmul(bcdiv((string) $limit->amount, (string) $total), (string) $days);
$return[$currency->id]['sum'] = bcadd($return[$currency->id]['sum'], $amount);
app('log')->debug(
sprintf(
'Amount per day: %s (%s over %d days). Total amount for %d days: %s',
bcdiv($limit->amount, (string) $total),
bcdiv((string) $limit->amount, (string) $total),
$limit->amount,
$total,
$days,
@@ -632,7 +632,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
'decimal_places' => $journal['currency_decimal_places'],
'sum' => '0',
];
$array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->negative($journal['amount']));
$array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], (string) app('steam')->negative($journal['amount']));
// also do foreign amount:
$foreignId = (int) $journal['foreign_currency_id'];
@@ -645,7 +645,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
'decimal_places' => $journal['foreign_currency_decimal_places'],
'sum' => '0',
];
$array[$foreignId]['sum'] = bcadd($array[$foreignId]['sum'], app('steam')->negative($journal['foreign_amount']));
$array[$foreignId]['sum'] = bcadd($array[$foreignId]['sum'], (string) app('steam')->negative($journal['foreign_amount']));
}
}
@@ -694,7 +694,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
'decimal_places' => $journal['currency_decimal_places'],
'sum' => '0',
];
$array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], app('steam')->negative($journal['amount']));
$array[$currencyId]['sum'] = bcadd($array[$currencyId]['sum'], (string) app('steam')->negative($journal['amount']));
// also do foreign amount:
$foreignId = (int) $journal['foreign_currency_id'];
@@ -707,7 +707,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
'decimal_places' => $journal['foreign_currency_decimal_places'],
'sum' => '0',
];
$array[$foreignId]['sum'] = bcadd($array[$foreignId]['sum'], app('steam')->negative($journal['foreign_amount']));
$array[$foreignId]['sum'] = bcadd($array[$foreignId]['sum'], (string) app('steam')->negative($journal['foreign_amount']));
}
}

View File

@@ -73,7 +73,7 @@ class NoBudgetRepository implements NoBudgetRepositoryInterface, UserGroupInterf
if (!array_key_exists($date, $data[$currencyId]['entries'])) {
$data[$currencyId]['entries'][$date] = '0';
}
$data[$currencyId]['entries'][$date] = bcadd($data[$currencyId]['entries'][$date], $journal['amount']);
$data[$currencyId]['entries'][$date] = bcadd($data[$currencyId]['entries'][$date], (string) $journal['amount']);
}
return $data;

View File

@@ -57,7 +57,7 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
$diff = (int) $limit->start_date->diffInDays($limit->end_date, true);
$diff = 0 === $diff ? 1 : $diff;
$amount = $limit->amount;
$perDay = bcdiv($amount, (string) $diff);
$perDay = bcdiv((string) $amount, (string) $diff);
$total = bcadd($total, $perDay);
++$count;
app('log')->debug(sprintf('Found %d budget limits. Per day is %s, total is %s', $count, $perDay, $total));
@@ -110,7 +110,7 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
'entries' => [],
];
$date = $journal['date']->format($carbonFormat);
$data[$key]['entries'][$date] = bcadd($data[$key]['entries'][$date] ?? '0', $journal['amount']);
$data[$key]['entries'][$date] = bcadd($data[$key]['entries'][$date] ?? '0', (string) $journal['amount']);
}
return $data;