Fix various phpstan things

This commit is contained in:
James Cole
2023-11-29 06:30:35 +01:00
parent 1c3cb85a46
commit b9feb0aa71
19 changed files with 77 additions and 78 deletions

View File

@@ -52,7 +52,7 @@ trait ValidatesUserGroupTrait
$user = auth()->user();
if (!$request->has('user_group_id')) {
$group = $user->userGroup;
app('log')->debug(sprintf('validateUserGroup: no user group submitted, return default group #%d.', $group->id));
app('log')->debug(sprintf('validateUserGroup: no user group submitted, return default group #%d.', $group?->id));
return $group;
}
$groupId = (int)$request->get('user_group_id');

View File

@@ -36,6 +36,7 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Support\CacheProperties;
use FireflyIII\Support\Facades\Amount;
use Illuminate\Support\Collection;
/**
@@ -216,9 +217,20 @@ trait AugumentData
/** @var BudgetLimit $entry */
foreach ($set as $entry) {
$currency = $entry->transactionCurrency;
if(null === $currency) {
$currency = app('amount')->getDefaultCurrency();
}
// clone because these objects change each other.
$currentStart = clone $entry->start_date;
$currentEnd = clone $entry->end_date;
$currentEnd = null === $entry->end_date ? null : clone $entry->end_date;
if(null === $currentEnd) {
$currentEnd = clone $currentStart;
$currentEnd->addMonth();
}
$expenses = $opsRepository->sumExpenses($currentStart, $currentEnd, null, $budgetCollection, $currency);
$spent = $expenses[$currency->id]['sum'] ?? '0';
$entry->spent = $spent;

View File

@@ -220,9 +220,9 @@ trait GetConfigurationData
protected function verifyRecurringCronJob(): void
{
$config = app('fireflyconfig')->get('last_rt_job', 0);
$lastTime = (int)$config->data;
$lastTime = (int)$config?->data;
$now = time();
app('log')->debug(sprintf('verifyRecurringCronJob: last time is %d ("%s"), now is %d', $lastTime, $config->data, $now));
app('log')->debug(sprintf('verifyRecurringCronJob: last time is %d ("%s"), now is %d', $lastTime, $config?->data, $now));
if (0 === $lastTime) {
request()->session()->flash('info', trans('firefly.recurring_never_cron'));

View File

@@ -79,6 +79,7 @@ trait ModelInformation
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
// types of liability:
/** @var AccountType $debt */
$debt = $repository->getAccountTypeByType(AccountType::DEBT);
$loan = $repository->getAccountTypeByType(AccountType::LOAN);
$mortgage = $repository->getAccountTypeByType(AccountType::MORTGAGE);

View File

@@ -64,6 +64,10 @@ trait RenderPartialViews
$accountRepos = app(AccountRepositoryInterface::class);
$account = $accountRepos->find((int)$attributes['accountId']);
if(null === $budget || null === $account) {
throw new FireflyException('Could not render popup.report.balance-amount because budget or account is null.');
}
$journals = $popupHelper->balanceForBudget($budget, $account, $attributes);
try {
@@ -330,7 +334,7 @@ trait RenderPartialViews
if ('user_action' !== $entry->trigger_type) {
$count = ($index + 1);
try {
$rootOperator = OperatorQuerySearch::getRootOperator($entry->trigger_type);
$rootOperator = OperatorQuerySearch::getRootOperator((string) $entry->trigger_type);
if (str_starts_with($rootOperator, '-')) {
$rootOperator = substr($rootOperator, 1);
}
@@ -340,7 +344,7 @@ trait RenderPartialViews
'oldTrigger' => $rootOperator,
'oldValue' => $entry->trigger_value,
'oldChecked' => $entry->stop_processing,
'oldProhibited' => str_starts_with($entry->trigger_type, '-'),
'oldProhibited' => str_starts_with((string) $entry->trigger_type, '-'),
'count' => $count,
'triggers' => $triggers,
]

View File

@@ -63,11 +63,15 @@ trait UserGroupTrait
* @param Authenticatable|User|null $user
*
* @return void
* @throws FireflyException
*/
public function setUser(Authenticatable | User | null $user): void
{
if ($user instanceof User) {
$this->user = $user;
if(null === $user->userGroup) {
throw new FireflyException(sprintf('User #%d has no user group.', $user->id));
}
$this->userGroup = $user->userGroup;
}
}

View File

@@ -79,7 +79,7 @@ trait ChecksLogin
$user = auth()->user();
app('log')->debug('Now in getUserGroup()');
/** @var UserGroup|null $userGroup */
$userGroup = $this->route()->parameter('userGroup');
$userGroup = $this->route()?->parameter('userGroup');
if (null === $userGroup) {
app('log')->debug('Request class has no userGroup parameter, but perhaps there is a parameter.');
$userGroupId = (int)$this->get('user_group_id');

View File

@@ -70,7 +70,7 @@ trait ConvertsDataTypes
if (!is_scalar($entry)) {
return '';
}
return $this->clearString((string)$entry, false);
return (string) $this->clearString((string)$entry, false);
}
/**
@@ -199,7 +199,7 @@ trait ConvertsDataTypes
*/
public function stringWithNewlines(string $field): string
{
return $this->clearString((string)($this->get($field) ?? ''));
return (string) $this->clearString((string)($this->get($field) ?? ''));
}
/**
@@ -255,7 +255,7 @@ trait ConvertsDataTypes
*/
protected function convertDateTime(?string $string): ?Carbon
{
$value = $this->get($string);
$value = $this->get((string)$string);
if (null === $value) {
return null;
}