Small php fixes.

This commit is contained in:
James Cole
2025-09-10 16:16:31 +02:00
parent cb0b42e44b
commit 28e7df2527
17 changed files with 14 additions and 31 deletions

View File

@@ -57,8 +57,6 @@ class CorrectsPiggyBanks extends Command
$event->transaction_journal_id = null;
$event->save();
++$count;
continue;
}
}
if (0 !== $count) {

View File

@@ -71,7 +71,6 @@ class RestoresOAuthKeys extends Command
$this->storeKeysInDB();
$this->friendlyInfo('Stored OAuth keys in database.');
return;
}
}

View File

@@ -515,7 +515,7 @@ class ForcesDecimalSize extends Command
continue;
}
// fix $field by rounding it down correctly.
$pow = (float) 10 ** $currency->decimal_places;
$pow = 10.0 ** $currency->decimal_places;
$correct = bcdiv((string) round((float) $value * $pow), (string) $pow, 12);
$this->friendlyWarning(sprintf('Transaction #%d has amount with value "%s", this has been corrected to "%s".', $item->id, $value, $correct));
@@ -546,7 +546,7 @@ class ForcesDecimalSize extends Command
continue;
}
// fix $field by rounding it down correctly.
$pow = (float) 10 ** $currency->decimal_places;
$pow = 10.0 ** $currency->decimal_places;
$correct = bcdiv((string) round((float) $value * $pow), (string) $pow, 12);
$this->friendlyWarning(
sprintf('Transaction #%d has foreign amount with value "%s", this has been corrected to "%s".', $item->id, $value, $correct)

View File

@@ -157,7 +157,6 @@ class UpgradesLiabilitiesEight extends Command
$service = new TransactionGroupDestroyService();
$service->destroy($group);
return;
}
}

View File

@@ -128,10 +128,6 @@ class GracefulNotFoundHandler extends ExceptionHandler
return redirect(route('categories.index'));
case 'rules.edit':
$request->session()->reflash();
return redirect(route('rules.index'));
case 'rule-groups.edit':
$request->session()->reflash();

View File

@@ -560,7 +560,7 @@ class GroupCollector implements GroupCollectorInterface
}
$groups = $this->parseSums($groups);
return new Collection($groups);
return new Collection()->push(...$groups);
}
/**

View File

@@ -49,7 +49,6 @@ use Illuminate\Support\Facades\Log;
class NetWorth implements NetWorthInterface
{
private AccountRepositoryInterface $accountRepository;
private CurrencyRepositoryInterface $currencyRepos;
private User $user; // @phpstan-ignore-line
private ?UserGroup $userGroup = null;
@@ -131,8 +130,6 @@ class NetWorth implements NetWorthInterface
$this->accountRepository = app(AccountRepositoryInterface::class);
$this->accountRepository->setUserGroup($userGroup);
$this->currencyRepos = app(CurrencyRepositoryInterface::class);
$this->currencyRepos->setUserGroup($this->userGroup);
}
#[Deprecated]

View File

@@ -86,7 +86,7 @@ class CreateController extends Controller
'latitude' => $hasOldInput ? old('location_latitude') : config('firefly.default_location.latitude'),
'longitude' => $hasOldInput ? old('location_longitude') : config('firefly.default_location.longitude'),
'zoom_level' => $hasOldInput ? old('location_zoom_level') : config('firefly.default_location.zoom_level'),
'has_location' => $hasOldInput ? 'true' === old('location_has_location') : false,
'has_location' => $hasOldInput && 'true' === old('location_has_location'),
],
];
$liabilityDirections = [
@@ -106,7 +106,7 @@ class CreateController extends Controller
'preFilled',
[
'currency_id' => $this->primaryCurrency->id,
'include_net_worth' => $hasOldInput ? (bool) $request->old('include_net_worth') : true,
'include_net_worth' => !$hasOldInput || (bool)$request->old('include_net_worth'),
]
);
// issue #8321

View File

@@ -171,7 +171,7 @@ class BoxController extends Controller
$filtered = $allAccounts->filter(
static function (Account $account) use ($accountRepository) {
$includeNetWorth = $accountRepository->getMetaValue($account, 'include_net_worth');
$result = null === $includeNetWorth ? true : '1' === $includeNetWorth;
$result = null === $includeNetWorth || '1' === $includeNetWorth;
if (false === $result) {
app('log')->debug(sprintf('Will not include "%s" in net worth charts.', $account->name));
}

View File

@@ -291,7 +291,7 @@ class BudgetController extends Controller
$cache->addProperty('budget-period-report');
$cache->addProperty($accounts->pluck('id')->toArray());
if ($cache->has()) {
// return $cache->get();
return $cache->get();
}
$periods = Navigation::listOfPeriods($start, $end);

View File

@@ -209,7 +209,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface, U
#[Deprecated]
public function setAvailableBudget(TransactionCurrency $currency, Carbon $start, Carbon $end, string $amount): AvailableBudget
{
/** @var null|AvailableBudget */
/** @var AvailableBudget|null $availableBudget */
$availableBudget = $this->user->availableBudgets()
->where('transaction_currency_id', $currency->id)
->where('start_date', $start->format('Y-m-d'))

View File

@@ -34,15 +34,12 @@ use Closure;
*/
class IsDuplicateTransaction implements ValidationRule
{
private string $value;
/**
* @SuppressWarnings("PHPMD.UnusedFormalParameter")
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
$this->value = $value;
$fail($this->value);
$fail($value);
}
}

View File

@@ -227,7 +227,6 @@ class CreditRecalculateService
$source->save();
$dest->save();
return;
}
// Log::debug('Opening balance is valid');
}

View File

@@ -70,7 +70,7 @@ class Calculator
}
self::$intervalMap = new SplObjectStorage();
foreach (Periodicity::cases() as $interval) {
$periodicityClass = __NAMESPACE__."\\Periodicity\\{$interval->name}";
$periodicityClass = sprintf('%s\\Periodicity\\%s',__NAMESPACE__,$interval->name);
self::$intervals[] = $interval->name;
self::$intervalMap->attach($interval, new $periodicityClass());
}

View File

@@ -47,7 +47,6 @@ class BudgetLimitEnrichment implements EnrichmentInterface
private array $notes = [];
private Carbon $start;
private Carbon $end;
private Collection $budgets;
private array $expenses = [];
private array $pcExpenses = [];
private array $currencyIds = [];
@@ -147,11 +146,11 @@ class BudgetLimitEnrichment implements EnrichmentInterface
private function collectBudgets(): void
{
$budgetIds = $this->collection->pluck('budget_id')->unique()->toArray();
$this->budgets = Budget::whereIn('id', $budgetIds)->get();
$budgets = Budget::whereIn('id', $budgetIds)->get();
$repository = app(OperationsRepository::class);
$repository->setUser($this->user);
$expenses = $repository->collectExpenses($this->start, $this->end, null, $this->budgets, null);
$expenses = $repository->collectExpenses($this->start, $this->end, null, $budgets, null);
/** @var BudgetLimit $budgetLimit */
foreach ($this->collection as $budgetLimit) {

View File

@@ -206,7 +206,7 @@ class AccountBalanceCalculator
foreach ($transactionJournal->transactions as $transaction) {
$set[$transaction->account_id] = $transaction->account;
}
$accounts = new Collection($set);
$accounts = new Collection()->push(...$set);
$object->optimizedCalculation($accounts, $transactionJournal->date);
}
}

View File

@@ -79,14 +79,13 @@ trait FiltersWeekends
);
$return[] = $clone;
continue;
}
// Log::debug(sprintf('Date is %s, removed from final result', $date->format('D d M Y')));
}
// filter unique dates
Log::debug(sprintf('Count before filtering: %d', count($dates)));
$collection = new Collection($return);
$collection = new Collection()->push(...$return);
$filtered = $collection->unique();
$return = $filtered->toArray();