Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
fix various phpstan errors
James Cole7cb919e9c21c
diff --git a/app/Support/Http/Controllers/RequestInformation.php b/app/Support/Http/Controllers/RequestInformation.phpindex faef448fbc..98f97777f1 100644--- a/app/Support/Http/Controllers/RequestInformation.php+++ b/app/Support/Http/Controllers/RequestInformation.php@@ -34,7 +34,6 @@ use Hash;use Illuminate\Contracts\Validation\Validator as ValidatorContract;use Illuminate\Routing\Route;use Illuminate\Support\Facades\Validator;-use InvalidArgumentException;use Psr\Container\ContainerExceptionInterface;use Psr\Container\NotFoundExceptionInterface;use Route as RouteFacade;@@ -171,21 +170,15 @@ trait RequestInformation{$attributes['location'] = $attributes['location'] ?? '';$attributes['accounts'] = AccountList::routeBinder($attributes['accounts'] ?? '', new Route('get', '', []));- try {- $date = Carbon::createFromFormat('Ymd', $attributes['startDate']);- } catch (InvalidArgumentException $e) {- app('log')->debug(sprintf('Not important error message: %s', $e->getMessage()));+ $date = Carbon::createFromFormat('Ymd', $attributes['startDate']);+ if (false === $date) {$date = today(config('app.timezone'));-}$date->startOfMonth();$attributes['startDate'] = $date;- unset($date);- try {- $date2 = Carbon::createFromFormat('Ymd', $attributes['endDate']);- } catch (InvalidArgumentException $e) {- app('log')->debug(sprintf('Not important error message: %s', $e->getMessage()));+ $date2 = Carbon::createFromFormat('Ymd', $attributes['endDate']);+ if (false === $date2) {$date2 = today(config('app.timezone'));}$date2->endOfDay();diff --git a/app/Support/Logging/AuditProcessor.php b/app/Support/Logging/AuditProcessor.phpindex 8e64183298..d23d8b32fe 100644--- a/app/Support/Logging/AuditProcessor.php+++ b/app/Support/Logging/AuditProcessor.php@@ -43,7 +43,7 @@ class AuditProcessorif (auth()->check()) {$message = sprintf('AUDIT: %s (%s (%s) -> %s:%s)',- $record['message'],+ $record['message'], // @phpstan-ignore-lineapp('request')->ip(),auth()->user()->email,request()->method(),@@ -54,7 +54,7 @@ class AuditProcessor$message = sprintf('AUDIT: %s (%s -> %s:%s)',- $record['message'],+ $record['message'], // @phpstan-ignore-lineapp('request')->ip(),request()->method(),request()->url()diff --git a/app/Support/Navigation.php b/app/Support/Navigation.phpindex 4f0b0d2210..7ee476d0dc 100644--- a/app/Support/Navigation.php+++ b/app/Support/Navigation.php@@ -89,10 +89,10 @@ class Navigationif (!array_key_exists($repeatFreq, $functionMap)) {Log::error(sprintf(- 'The periodicity %s is unknown. Choose one of available periodicity: %s',- $repeatFreq,- implode(', ', array_keys($functionMap))- ));+ 'The periodicity %s is unknown. Choose one of available periodicity: %s',+ $repeatFreq,+ implode(', ', array_keys($functionMap))+ ));return $theDate;}@@ -352,12 +352,12 @@ class Navigationpublic function diffInPeriods(string $period, int $skip, Carbon $beginning, Carbon $end): int{Log::debug(sprintf(- 'diffInPeriods: %s (skip: %d), between %s and %s.',- $period,- $skip,- $beginning->format('Y-m-d'),- $end->format('Y-m-d')- ));+ 'diffInPeriods: %s (skip: %d), between %s and %s.',+ $period,+ $skip,+ $beginning->format('Y-m-d'),+ $end->format('Y-m-d')+ ));$map = ['daily' => 'floatDiffInDays','weekly' => 'floatDiffInWeeks',@@ -394,11 +394,11 @@ class Navigation$parameter = $skip + 1;$diff = ceil($diff / $parameter) * $parameter;Log::debug(sprintf(- 'diffInPeriods: skip is %d, so param is %d, and diff becomes %d',- $skip,- $parameter,- $diff- ));+ 'diffInPeriods: skip is %d, so param is %d, and diff becomes %d',+ $skip,+ $parameter,+ $diff+ ));}return (int)$diff;@@ -456,7 +456,11 @@ class Navigation*/public function getViewRange(bool $correct): string{- $range = (string)app('preferences')->get('viewRange', '1M')?->data ?? '1M';+ $range = app('preferences')->get('viewRange', '1M')?->data ?? '1M';+ if (is_array($range)) {+ $range = '1M';+ }+ $range = (string)$range;if (!$correct) {return $range;}diff --git a/app/Support/ParseDateString.php b/app/Support/ParseDateString.phpindex f70d35df9c..0fac8df511 100644--- a/app/Support/ParseDateString.php+++ b/app/Support/ParseDateString.php@@ -88,7 +88,7 @@ class ParseDateString// if regex for YYYY-MM-DD:$pattern = '/^(19|20)\d\d-(0[1-9]|1[012])-(0[1-9]|[12]\d|3[01])$/';- if (preg_match($pattern, $date)) {+ if (false !== preg_match($pattern, $date)) {return $this->parseDefaultDate($date);}@@ -151,7 +151,11 @@ class ParseDateString*/protected function parseDefaultDate(string $date): Carbon{- return Carbon::createFromFormat('Y-m-d', $date);+ $result = Carbon::createFromFormat('Y-m-d', $date);+ if(false === $result) {+ $result = today(config('app.timezone'))->startOfDay();+ }+ return $result;}/**@@ -254,7 +258,7 @@ class ParseDateString{// if regex for xxxx-xx-DD:$pattern = '/^xxxx-xx-(0[1-9]|[12]\d|3[01])$/';- if (preg_match($pattern, $date)) {+ if (false !== preg_match($pattern, $date)) {app('log')->debug(sprintf('"%s" is a day range.', $date));return true;@@ -289,7 +293,7 @@ class ParseDateString{// if regex for xxxx-MM-xx:$pattern = '/^xxxx-(0[1-9]|1[012])-xx$/';- if (preg_match($pattern, $date)) {+ if (false !== preg_match($pattern, $date)) {app('log')->debug(sprintf('"%s" is a month range.', $date));return true;@@ -325,7 +329,7 @@ class ParseDateString{// if regex for YYYY-xx-xx:$pattern = '/^(19|20)\d\d-xx-xx$/';- if (preg_match($pattern, $date)) {+ if (false !== preg_match($pattern, $date)) {app('log')->debug(sprintf('"%s" is a year range.', $date));return true;@@ -361,7 +365,7 @@ class ParseDateString{// if regex for xxxx-MM-DD:$pattern = '/^xxxx-(0[1-9]|1[012])-(0[1-9]|[12]\d|3[01])$/';- if (preg_match($pattern, $date)) {+ if (false !== preg_match($pattern, $date)) {app('log')->debug(sprintf('"%s" is a month/day range.', $date));return true;@@ -398,7 +402,7 @@ class ParseDateString{// if regex for YYYY-xx-DD:$pattern = '/^(19|20)\d\d-xx-(0[1-9]|[12]\d|3[01])$/';- if (preg_match($pattern, $date)) {+ if (false !== preg_match($pattern, $date)) {app('log')->debug(sprintf('"%s" is a day/year range.', $date));return true;@@ -435,7 +439,7 @@ class ParseDateString{// if regex for YYYY-MM-xx:$pattern = '/^(19|20)\d\d-(0[1-9]|1[012])-xx$/';- if (preg_match($pattern, $date)) {+ if (false !== preg_match($pattern, $date)) {app('log')->debug(sprintf('"%s" is a month/year range.', $date));return true;diff --git a/app/Support/Preferences.php b/app/Support/Preferences.phpindex dc4d913817..5e32150ac5 100644--- a/app/Support/Preferences.php+++ b/app/Support/Preferences.php@@ -168,7 +168,7 @@ class Preferences}if (null === $pref) {$pref = new Preference();- $pref->user_id = $user->id;+ $pref->user_id = (int) $user->id;$pref->name = $name;}$pref->data = $value;@@ -286,7 +286,7 @@ class Preferences$lastActivity = implode(',', $lastActivity);}- return hash('sha256', $lastActivity);+ return hash('sha256', (string) $lastActivity);}/**diff --git a/app/Support/Repositories/Recurring/FiltersWeekends.php b/app/Support/Repositories/Recurring/FiltersWeekends.phpindex f5c3101cad..efc792a1cc 100644--- a/app/Support/Repositories/Recurring/FiltersWeekends.php+++ b/app/Support/Repositories/Recurring/FiltersWeekends.php@@ -45,7 +45,7 @@ trait FiltersWeekendsprotected function filterWeekends(RecurrenceRepetition $repetition, array $dates): array{app('log')->debug(sprintf('Now in %s', __METHOD__));- if ((int)$repetition->weekend === RecurrenceRepetition::WEEKEND_DO_NOTHING) {+ if ($repetition->weekend === RecurrenceRepetition::WEEKEND_DO_NOTHING) {app('log')->debug('Repetition will not be filtered on weekend days.');return $dates;diff --git a/app/Support/Search/OperatorQuerySearch.php b/app/Support/Search/OperatorQuerySearch.phpindex 39d795403a..74fab7ca7a 100644--- a/app/Support/Search/OperatorQuerySearch.php+++ b/app/Support/Search/OperatorQuerySearch.php@@ -213,12 +213,12 @@ class OperatorQuerySearch implements SearchInterface// is an operator that needs no context, and value is false, then prohibited = true.if ('false' === $value && in_array($operator, $this->validOperators, true) && false === $context && !$prohibited) {$prohibited = true;- $value = 'true';+ $value = 'true';}// if the operator is prohibited, but the value is false, do an uno reverseif ('false' === $value && $prohibited && in_array($operator, $this->validOperators, true) && false === $context) {$prohibited = false;- $value = 'true';+ $value = 'true';}// must be valid operator:@@ -264,14 +264,14 @@ class OperatorQuerySearch implements SearchInterfacedefault:app('log')->error(sprintf('No such operator: %s', $operator));throw new FireflyException(sprintf('Unsupported search operator: "%s"', $operator));- // some search operators are ignored, basically:+ // some search operators are ignored, basically:case 'user_action':app('log')->info(sprintf('Ignore search operator "%s"', $operator));return false;- //- // all account related searches:- //+ //+ // all account related searches:+ //case 'account_is':$this->searchAccount($value, 3, 4);break;@@ -502,9 +502,9 @@ class OperatorQuerySearch implements SearchInterface$this->collector->findNothing();}break;- //- // cash account- //+ //+ // cash account+ //case 'source_is_cash':$account = $this->getCashAccount();$this->collector->setSourceAccounts(new Collection([$account]));@@ -529,9 +529,9 @@ class OperatorQuerySearch implements SearchInterface$account = $this->getCashAccount();$this->collector->excludeAccounts(new Collection([$account]));break;- //- // description- //+ //+ // description+ //case 'description_starts':$this->collector->descriptionStarts([$value]);break;@@ -558,9 +558,9 @@ class OperatorQuerySearch implements SearchInterfacecase '-description_is':$this->collector->descriptionIsNot($value);break;- //- // currency- //+ //+ // currency+ //case 'currency_is':$currency = $this->findCurrency($value);if (null !== $currency) {@@ -597,9 +597,9 @@ class OperatorQuerySearch implements SearchInterface$this->collector->findNothing();}break;- //- // attachments- //+ //+ // attachments+ //case 'has_attachments':case '-has_no_attachments':app('log')->debug('Set collector to filter on attachments.');@@ -610,8 +610,8 @@ class OperatorQuerySearch implements SearchInterfaceapp('log')->debug('Set collector to filter on NO attachments.');$this->collector->hasNoAttachments();break;- //- // categories+ //+ // categoriescase '-has_any_category':case 'has_no_category':$this->collector->withoutCategory();@@ -689,9 +689,9 @@ class OperatorQuerySearch implements SearchInterface$this->collector->findNothing();}break;- //- // budgets- //+ //+ // budgets+ //case '-has_any_budget':case 'has_no_budget':$this->collector->withoutBudget();@@ -770,9 +770,9 @@ class OperatorQuerySearch implements SearchInterface$this->collector->findNothing();}break;- //- // bill- //+ //+ // bill+ //case '-has_any_bill':case 'has_no_bill':$this->collector->withoutBill();@@ -849,9 +849,9 @@ class OperatorQuerySearch implements SearchInterface$this->collector->findNothing();}break;- //- // tags- //+ //+ // tags+ //case '-has_any_tag':case 'has_no_tag':$this->collector->withoutTags();@@ -879,9 +879,9 @@ class OperatorQuerySearch implements SearchInterface$this->collector->setWithoutSpecificTags($result);}break;- //- // notes- //+ //+ // notes+ //case 'notes_contains':$this->collector->notesContain($value);break;@@ -920,9 +920,9 @@ class OperatorQuerySearch implements SearchInterfacecase '-reconciled':$this->collector->isNotReconciled();break;- //- // amount- //+ //+ // amount+ //case 'amount_is':// strip comma's, make dots.app('log')->debug(sprintf('Original value "%s"', $value));@@ -993,9 +993,9 @@ class OperatorQuerySearch implements SearchInterfaceapp('log')->debug(sprintf('Set "%s" using collector with value "%s"', $operator, $amount));$this->collector->foreignAmountMore($amount);break;- //- // transaction type- //+ //+ // transaction type+ //case 'transaction_type':$this->collector->setTypes([ucfirst($value)]);app('log')->debug(sprintf('Set "%s" using collector with value "%s"', $operator, $value));@@ -1004,9 +1004,9 @@ class OperatorQuerySearch implements SearchInterface$this->collector->excludeTypes([ucfirst($value)]);app('log')->debug(sprintf('Set "%s" using collector with value "%s"', $operator, $value));break;- //- // dates- //+ //+ // dates+ //case '-date_on':case 'date_on':$range = $this->parseDateRange($operator, $value);@@ -1156,9 +1156,9 @@ class OperatorQuerySearch implements SearchInterface$range = $this->parseDateRange($operator, $value);$this->setObjectDateAfterParams('updated_at', $range);return false;- //- // external URL- //+ //+ // external URL+ //case '-any_external_url':case 'no_external_url':$this->collector->withoutExternalUrl();@@ -1201,9 +1201,9 @@ class OperatorQuerySearch implements SearchInterface$this->collector->externalUrlDoesNotEnd($value);break;- //- // other fields- //+ //+ // other fields+ //case 'external_id_is':$this->collector->setExternalId($value);break;@@ -1593,43 +1593,59 @@ class OperatorQuerySearch implements SearchInterfacedefault:throw new FireflyException(sprintf('Cannot handle key "%s" in setExactParameters()', $key));case 'exact':- app('log')->debug(sprintf('Set date_is_exact value "%s"', $value->format('Y-m-d')));- $this->collector->setRange($value, $value);- $this->operators->push(['type' => 'date_on', 'value' => $value->format('Y-m-d'),]);+ if ($value instanceof Carbon) {+ app('log')->debug(sprintf('Set date_is_exact value "%s"', $value->format('Y-m-d')));+ $this->collector->setRange($value, $value);+ $this->operators->push(['type' => 'date_on', 'value' => $value->format('Y-m-d'),]);+ }break;case 'exact_not':- $this->collector->excludeRange($value, $value);- $this->operators->push(['type' => 'not_date_on', 'value' => $value->format('Y-m-d'),]);+ if ($value instanceof Carbon) {+ $this->collector->excludeRange($value, $value);+ $this->operators->push(['type' => 'not_date_on', 'value' => $value->format('Y-m-d'),]);+ }break;case 'year':- app('log')->debug(sprintf('Set date_is_exact YEAR value "%s"', $value));- $this->collector->yearIs($value);- $this->operators->push(['type' => 'date_on_year', 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set date_is_exact YEAR value "%s"', $value));+ $this->collector->yearIs($value);+ $this->operators->push(['type' => 'date_on_year', 'value' => $value,]);+ }break;case 'year_not':- app('log')->debug(sprintf('Set date_is_exact_not YEAR value "%s"', $value));- $this->collector->yearIsNot($value);- $this->operators->push(['type' => 'not_date_on_year', 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set date_is_exact_not YEAR value "%s"', $value));+ $this->collector->yearIsNot($value);+ $this->operators->push(['type' => 'not_date_on_year', 'value' => $value,]);+ }break;case 'month':- app('log')->debug(sprintf('Set date_is_exact MONTH value "%s"', $value));- $this->collector->monthIs($value);- $this->operators->push(['type' => 'date_on_month', 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set date_is_exact MONTH value "%s"', $value));+ $this->collector->monthIs($value);+ $this->operators->push(['type' => 'date_on_month', 'value' => $value,]);+ }break;case 'month_not':- app('log')->debug(sprintf('Set date_is_exact not MONTH value "%s"', $value));- $this->collector->monthIsNot($value);- $this->operators->push(['type' => 'not_date_on_month', 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set date_is_exact not MONTH value "%s"', $value));+ $this->collector->monthIsNot($value);+ $this->operators->push(['type' => 'not_date_on_month', 'value' => $value,]);+ }break;case 'day':- app('log')->debug(sprintf('Set date_is_exact DAY value "%s"', $value));- $this->collector->dayIs($value);- $this->operators->push(['type' => 'date_on_day', 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set date_is_exact DAY value "%s"', $value));+ $this->collector->dayIs($value);+ $this->operators->push(['type' => 'date_on_day', 'value' => $value,]);+ }break;case 'day_not':- app('log')->debug(sprintf('Set not date_is_exact DAY value "%s"', $value));- $this->collector->dayIsNot($value);- $this->operators->push(['type' => 'not_date_on_day', 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set not date_is_exact DAY value "%s"', $value));+ $this->collector->dayIsNot($value);+ $this->operators->push(['type' => 'not_date_on_day', 'value' => $value,]);+ }break;}}@@ -1651,23 +1667,31 @@ class OperatorQuerySearch implements SearchInterfacedefault:throw new FireflyException(sprintf('Cannot handle key "%s" in setDateBeforeParams()', $key));case 'exact':- $this->collector->setBefore($value);- $this->operators->push(['type' => 'date_before', 'value' => $value->format('Y-m-d'),]);+ if ($value instanceof Carbon) {+ $this->collector->setBefore($value);+ $this->operators->push(['type' => 'date_before', 'value' => $value->format('Y-m-d'),]);+ }break;case 'year':- app('log')->debug(sprintf('Set date_is_before YEAR value "%s"', $value));- $this->collector->yearBefore($value);- $this->operators->push(['type' => 'date_before_year', 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set date_is_before YEAR value "%s"', $value));+ $this->collector->yearBefore($value);+ $this->operators->push(['type' => 'date_before_year', 'value' => $value,]);+ }break;case 'month':- app('log')->debug(sprintf('Set date_is_before MONTH value "%s"', $value));- $this->collector->monthBefore($value);- $this->operators->push(['type' => 'date_before_month', 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set date_is_before MONTH value "%s"', $value));+ $this->collector->monthBefore($value);+ $this->operators->push(['type' => 'date_before_month', 'value' => $value,]);+ }break;case 'day':- app('log')->debug(sprintf('Set date_is_before DAY value "%s"', $value));- $this->collector->dayBefore($value);- $this->operators->push(['type' => 'date_before_day', 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set date_is_before DAY value "%s"', $value));+ $this->collector->dayBefore($value);+ $this->operators->push(['type' => 'date_before_day', 'value' => $value,]);+ }break;}}@@ -1689,23 +1713,31 @@ class OperatorQuerySearch implements SearchInterfacedefault:throw new FireflyException(sprintf('Cannot handle key "%s" in setDateAfterParams()', $key));case 'exact':- $this->collector->setAfter($value);- $this->operators->push(['type' => 'date_after', 'value' => $value->format('Y-m-d'),]);+ if ($value instanceof Carbon) {+ $this->collector->setAfter($value);+ $this->operators->push(['type' => 'date_after', 'value' => $value->format('Y-m-d'),]);+ }break;case 'year':- app('log')->debug(sprintf('Set date_is_after YEAR value "%s"', $value));- $this->collector->yearAfter($value);- $this->operators->push(['type' => 'date_after_year', 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set date_is_after YEAR value "%s"', $value));+ $this->collector->yearAfter($value);+ $this->operators->push(['type' => 'date_after_year', 'value' => $value,]);+ }break;case 'month':- app('log')->debug(sprintf('Set date_is_after MONTH value "%s"', $value));- $this->collector->monthAfter($value);- $this->operators->push(['type' => 'date_after_month', 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set date_is_after MONTH value "%s"', $value));+ $this->collector->monthAfter($value);+ $this->operators->push(['type' => 'date_after_month', 'value' => $value,]);+ }break;case 'day':- app('log')->debug(sprintf('Set date_is_after DAY value "%s"', $value));- $this->collector->dayAfter($value);- $this->operators->push(['type' => 'date_after_day', 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set date_is_after DAY value "%s"', $value));+ $this->collector->dayAfter($value);+ $this->operators->push(['type' => 'date_after_day', 'value' => $value,]);+ }break;}}@@ -1727,44 +1759,60 @@ class OperatorQuerySearch implements SearchInterfacedefault:throw new FireflyException(sprintf('Cannot handle key "%s" in setExactMetaDateParams()', $key));case 'exact':- app('log')->debug(sprintf('Set %s_is_exact value "%s"', $field, $value->format('Y-m-d')));- $this->collector->setMetaDateRange($value, $value, $field);- $this->operators->push(['type' => sprintf('%s_on', $field), 'value' => $value->format('Y-m-d'),]);+ if ($value instanceof Carbon) {+ app('log')->debug(sprintf('Set %s_is_exact value "%s"', $field, $value->format('Y-m-d')));+ $this->collector->setMetaDateRange($value, $value, $field);+ $this->operators->push(['type' => sprintf('%s_on', $field), 'value' => $value->format('Y-m-d'),]);+ }break;case 'exact_not':- app('log')->debug(sprintf('Set NOT %s_is_exact value "%s"', $field, $value->format('Y-m-d')));- $this->collector->excludeMetaDateRange($value, $value, $field);- $this->operators->push(['type' => sprintf('not_%s_on', $field), 'value' => $value->format('Y-m-d'),]);+ if ($value instanceof Carbon) {+ app('log')->debug(sprintf('Set NOT %s_is_exact value "%s"', $field, $value->format('Y-m-d')));+ $this->collector->excludeMetaDateRange($value, $value, $field);+ $this->operators->push(['type' => sprintf('not_%s_on', $field), 'value' => $value->format('Y-m-d'),]);+ }break;case 'year':- app('log')->debug(sprintf('Set %s_is_exact YEAR value "%s"', $field, $value));- $this->collector->metaYearIs($value, $field);- $this->operators->push(['type' => sprintf('%s_on_year', $field), 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set %s_is_exact YEAR value "%s"', $field, $value));+ $this->collector->metaYearIs($value, $field);+ $this->operators->push(['type' => sprintf('%s_on_year', $field), 'value' => $value,]);+ }break;case 'year_not':- app('log')->debug(sprintf('Set NOT %s_is_exact YEAR value "%s"', $field, $value));- $this->collector->metaYearIsNot($value, $field);- $this->operators->push(['type' => sprintf('not_%s_on_year', $field), 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set NOT %s_is_exact YEAR value "%s"', $field, $value));+ $this->collector->metaYearIsNot($value, $field);+ $this->operators->push(['type' => sprintf('not_%s_on_year', $field), 'value' => $value,]);+ }break;case 'month':- app('log')->debug(sprintf('Set %s_is_exact MONTH value "%s"', $field, $value));- $this->collector->metaMonthIs($value, $field);- $this->operators->push(['type' => sprintf('%s_on_month', $field), 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set %s_is_exact MONTH value "%s"', $field, $value));+ $this->collector->metaMonthIs($value, $field);+ $this->operators->push(['type' => sprintf('%s_on_month', $field), 'value' => $value,]);+ }break;case 'month_not':- app('log')->debug(sprintf('Set NOT %s_is_exact MONTH value "%s"', $field, $value));- $this->collector->metaMonthIsNot($value, $field);- $this->operators->push(['type' => sprintf('not_%s_on_month', $field), 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set NOT %s_is_exact MONTH value "%s"', $field, $value));+ $this->collector->metaMonthIsNot($value, $field);+ $this->operators->push(['type' => sprintf('not_%s_on_month', $field), 'value' => $value,]);+ }break;case 'day':- app('log')->debug(sprintf('Set %s_is_exact DAY value "%s"', $field, $value));- $this->collector->metaDayIs($value, $field);- $this->operators->push(['type' => sprintf('%s_on_day', $field), 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set %s_is_exact DAY value "%s"', $field, $value));+ $this->collector->metaDayIs($value, $field);+ $this->operators->push(['type' => sprintf('%s_on_day', $field), 'value' => $value,]);+ }break;case 'day_not':- app('log')->debug(sprintf('Set NOT %s_is_exact DAY value "%s"', $field, $value));- $this->collector->metaDayIsNot($value, $field);- $this->operators->push(['type' => sprintf('not_%s_on_day', $field), 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set NOT %s_is_exact DAY value "%s"', $field, $value));+ $this->collector->metaDayIsNot($value, $field);+ $this->operators->push(['type' => sprintf('not_%s_on_day', $field), 'value' => $value,]);+ }break;}}@@ -1785,23 +1833,31 @@ class OperatorQuerySearch implements SearchInterfacedefault:throw new FireflyException(sprintf('Cannot handle key "%s" in setMetaDateBeforeParams()', $key));case 'exact':- $this->collector->setMetaBefore($value, $field);- $this->operators->push(['type' => sprintf('%s_before', $field), 'value' => $value->format('Y-m-d'),]);+ if ($value instanceof Carbon) {+ $this->collector->setMetaBefore($value, $field);+ $this->operators->push(['type' => sprintf('%s_before', $field), 'value' => $value->format('Y-m-d'),]);+ }break;case 'year':- app('log')->debug(sprintf('Set %s_is_before YEAR value "%s"', $field, $value));- $this->collector->metaYearBefore($value, $field);- $this->operators->push(['type' => sprintf('%s_before_year', $field), 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set %s_is_before YEAR value "%s"', $field, $value));+ $this->collector->metaYearBefore($value, $field);+ $this->operators->push(['type' => sprintf('%s_before_year', $field), 'value' => $value,]);+ }break;case 'month':- app('log')->debug(sprintf('Set %s_is_before MONTH value "%s"', $field, $value));- $this->collector->metaMonthBefore($value, $field);- $this->operators->push(['type' => sprintf('%s_before_month', $field), 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set %s_is_before MONTH value "%s"', $field, $value));+ $this->collector->metaMonthBefore($value, $field);+ $this->operators->push(['type' => sprintf('%s_before_month', $field), 'value' => $value,]);+ }break;case 'day':- app('log')->debug(sprintf('Set %s_is_before DAY value "%s"', $field, $value));- $this->collector->metaDayBefore($value, $field);- $this->operators->push(['type' => sprintf('%s_before_day', $field), 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set %s_is_before DAY value "%s"', $field, $value));+ $this->collector->metaDayBefore($value, $field);+ $this->operators->push(['type' => sprintf('%s_before_day', $field), 'value' => $value,]);+ }break;}}@@ -1822,23 +1878,31 @@ class OperatorQuerySearch implements SearchInterfacedefault:throw new FireflyException(sprintf('Cannot handle key "%s" in setMetaDateAfterParams()', $key));case 'exact':- $this->collector->setMetaAfter($value, $field);- $this->operators->push(['type' => sprintf('%s_after', $field), 'value' => $value->format('Y-m-d'),]);+ if ($value instanceof Carbon) {+ $this->collector->setMetaAfter($value, $field);+ $this->operators->push(['type' => sprintf('%s_after', $field), 'value' => $value->format('Y-m-d'),]);+ }break;case 'year':- app('log')->debug(sprintf('Set %s_is_after YEAR value "%s"', $field, $value));- $this->collector->metaYearAfter($value, $field);- $this->operators->push(['type' => sprintf('%s_after_year', $field), 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set %s_is_after YEAR value "%s"', $field, $value));+ $this->collector->metaYearAfter($value, $field);+ $this->operators->push(['type' => sprintf('%s_after_year', $field), 'value' => $value,]);+ }break;case 'month':- app('log')->debug(sprintf('Set %s_is_after MONTH value "%s"', $field, $value));- $this->collector->metaMonthAfter($value, $field);- $this->operators->push(['type' => sprintf('%s_after_month', $field), 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set %s_is_after MONTH value "%s"', $field, $value));+ $this->collector->metaMonthAfter($value, $field);+ $this->operators->push(['type' => sprintf('%s_after_month', $field), 'value' => $value,]);+ }break;case 'day':- app('log')->debug(sprintf('Set %s_is_after DAY value "%s"', $field, $value));- $this->collector->metaDayAfter($value, $field);- $this->operators->push(['type' => sprintf('%s_after_day', $field), 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set %s_is_after DAY value "%s"', $field, $value));+ $this->collector->metaDayAfter($value, $field);+ $this->operators->push(['type' => sprintf('%s_after_day', $field), 'value' => $value,]);+ }break;}}@@ -1859,44 +1923,60 @@ class OperatorQuerySearch implements SearchInterfacedefault:throw new FireflyException(sprintf('Cannot handle key "%s" in setExactObjectDateParams()', $key));case 'exact':- app('log')->debug(sprintf('Set %s_is_exact value "%s"', $field, $value->format('Y-m-d')));- $this->collector->setObjectRange($value, clone $value, $field);- $this->operators->push(['type' => sprintf('%s_on', $field), 'value' => $value->format('Y-m-d'),]);+ if ($value instanceof Carbon) {+ app('log')->debug(sprintf('Set %s_is_exact value "%s"', $field, $value->format('Y-m-d')));+ $this->collector->setObjectRange($value, clone $value, $field);+ $this->operators->push(['type' => sprintf('%s_on', $field), 'value' => $value->format('Y-m-d'),]);+ }break;case 'exact_not':- app('log')->debug(sprintf('Set NOT %s_is_exact value "%s"', $field, $value->format('Y-m-d')));- $this->collector->excludeObjectRange($value, clone $value, $field);- $this->operators->push(['type' => sprintf('not_%s_on', $field), 'value' => $value->format('Y-m-d'),]);+ if ($value instanceof Carbon) {+ app('log')->debug(sprintf('Set NOT %s_is_exact value "%s"', $field, $value->format('Y-m-d')));+ $this->collector->excludeObjectRange($value, clone $value, $field);+ $this->operators->push(['type' => sprintf('not_%s_on', $field), 'value' => $value->format('Y-m-d'),]);+ }break;case 'year':- app('log')->debug(sprintf('Set %s_is_exact YEAR value "%s"', $field, $value));- $this->collector->objectYearIs($value, $field);- $this->operators->push(['type' => sprintf('%s_on_year', $field), 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set %s_is_exact YEAR value "%s"', $field, $value));+ $this->collector->objectYearIs($value, $field);+ $this->operators->push(['type' => sprintf('%s_on_year', $field), 'value' => $value,]);+ }break;case 'year_not':- app('log')->debug(sprintf('Set NOT %s_is_exact YEAR value "%s"', $field, $value));- $this->collector->objectYearIsNot($value, $field);- $this->operators->push(['type' => sprintf('not_%s_on_year', $field), 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set NOT %s_is_exact YEAR value "%s"', $field, $value));+ $this->collector->objectYearIsNot($value, $field);+ $this->operators->push(['type' => sprintf('not_%s_on_year', $field), 'value' => $value,]);+ }break;case 'month':- app('log')->debug(sprintf('Set %s_is_exact MONTH value "%s"', $field, $value));- $this->collector->objectMonthIs($value, $field);- $this->operators->push(['type' => sprintf('%s_on_month', $field), 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set %s_is_exact MONTH value "%s"', $field, $value));+ $this->collector->objectMonthIs($value, $field);+ $this->operators->push(['type' => sprintf('%s_on_month', $field), 'value' => $value,]);+ }break;case 'month_not':- app('log')->debug(sprintf('Set NOT %s_is_exact MONTH value "%s"', $field, $value));- $this->collector->objectMonthIsNot($value, $field);- $this->operators->push(['type' => sprintf('not_%s_on_month', $field), 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set NOT %s_is_exact MONTH value "%s"', $field, $value));+ $this->collector->objectMonthIsNot($value, $field);+ $this->operators->push(['type' => sprintf('not_%s_on_month', $field), 'value' => $value,]);+ }break;case 'day':- app('log')->debug(sprintf('Set %s_is_exact DAY value "%s"', $field, $value));- $this->collector->objectDayIs($value, $field);- $this->operators->push(['type' => sprintf('%s_on_day', $field), 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set %s_is_exact DAY value "%s"', $field, $value));+ $this->collector->objectDayIs($value, $field);+ $this->operators->push(['type' => sprintf('%s_on_day', $field), 'value' => $value,]);+ }break;case 'day_not':- app('log')->debug(sprintf('Set NOT %s_is_exact DAY value "%s"', $field, $value));- $this->collector->objectDayIsNot($value, $field);- $this->operators->push(['type' => sprintf('not_%s_on_day', $field), 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set NOT %s_is_exact DAY value "%s"', $field, $value));+ $this->collector->objectDayIsNot($value, $field);+ $this->operators->push(['type' => sprintf('not_%s_on_day', $field), 'value' => $value,]);+ }break;}}@@ -1918,23 +1998,31 @@ class OperatorQuerySearch implements SearchInterfacedefault:throw new FireflyException(sprintf('Cannot handle key "%s" in setObjectDateBeforeParams()', $key));case 'exact':- $this->collector->setObjectBefore($value, $field);- $this->operators->push(['type' => sprintf('%s_before', $field), 'value' => $value->format('Y-m-d'),]);+ if ($value instanceof Carbon) {+ $this->collector->setObjectBefore($value, $field);+ $this->operators->push(['type' => sprintf('%s_before', $field), 'value' => $value->format('Y-m-d'),]);+ }break;case 'year':- app('log')->debug(sprintf('Set date_is_before YEAR value "%s"', $value));- $this->collector->objectYearBefore($value, $field);- $this->operators->push(['type' => sprintf('%s_before_year', $field), 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set date_is_before YEAR value "%s"', $value));+ $this->collector->objectYearBefore($value, $field);+ $this->operators->push(['type' => sprintf('%s_before_year', $field), 'value' => $value,]);+ }break;case 'month':- app('log')->debug(sprintf('Set date_is_before MONTH value "%s"', $value));- $this->collector->objectMonthBefore($value, $field);- $this->operators->push(['type' => sprintf('%s_before_month', $field), 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set date_is_before MONTH value "%s"', $value));+ $this->collector->objectMonthBefore($value, $field);+ $this->operators->push(['type' => sprintf('%s_before_month', $field), 'value' => $value,]);+ }break;case 'day':- app('log')->debug(sprintf('Set date_is_before DAY value "%s"', $value));- $this->collector->objectDayBefore($value, $field);- $this->operators->push(['type' => sprintf('%s_before_day', $field), 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set date_is_before DAY value "%s"', $value));+ $this->collector->objectDayBefore($value, $field);+ $this->operators->push(['type' => sprintf('%s_before_day', $field), 'value' => $value,]);+ }break;}}@@ -1956,23 +2044,31 @@ class OperatorQuerySearch implements SearchInterfacedefault:throw new FireflyException(sprintf('Cannot handle key "%s" in setObjectDateAfterParams()', $key));case 'exact':- $this->collector->setObjectAfter($value, $field);- $this->operators->push(['type' => sprintf('%s_after', $field), 'value' => $value->format('Y-m-d'),]);+ if ($value instanceof Carbon) {+ $this->collector->setObjectAfter($value, $field);+ $this->operators->push(['type' => sprintf('%s_after', $field), 'value' => $value->format('Y-m-d'),]);+ }break;case 'year':- app('log')->debug(sprintf('Set date_is_after YEAR value "%s"', $value));- $this->collector->objectYearAfter($value, $field);- $this->operators->push(['type' => sprintf('%s_after_year', $field), 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set date_is_after YEAR value "%s"', $value));+ $this->collector->objectYearAfter($value, $field);+ $this->operators->push(['type' => sprintf('%s_after_year', $field), 'value' => $value,]);+ }break;case 'month':- app('log')->debug(sprintf('Set date_is_after MONTH value "%s"', $value));- $this->collector->objectMonthAfter($value, $field);- $this->operators->push(['type' => sprintf('%s_after_month', $field), 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set date_is_after MONTH value "%s"', $value));+ $this->collector->objectMonthAfter($value, $field);+ $this->operators->push(['type' => sprintf('%s_after_month', $field), 'value' => $value,]);+ }break;case 'day':- app('log')->debug(sprintf('Set date_is_after DAY value "%s"', $value));- $this->collector->objectDayAfter($value, $field);- $this->operators->push(['type' => sprintf('%s_after_day', $field), 'value' => $value,]);+ if (is_string($value)) {+ app('log')->debug(sprintf('Set date_is_after DAY value "%s"', $value));+ $this->collector->objectDayAfter($value, $field);+ $this->operators->push(['type' => sprintf('%s_after_day', $field), 'value' => $value,]);+ }break;}}diff --git a/app/Support/Steam.php b/app/Support/Steam.phpindex 4f2e29d43f..eeef4b2a3f 100644--- a/app/Support/Steam.php+++ b/app/Support/Steam.php@@ -152,7 +152,7 @@ class Steam->orderBy('transaction_journals.date', 'ASC')->whereNull('transaction_journals.deleted_at')->get(- [+ [ // @phpstan-ignore-line'transaction_journals.date','transactions.transaction_currency_id',DB::raw('SUM(transactions.amount) AS modified'),@@ -295,7 +295,10 @@ class Steam$currentBalance = $startBalance;/** @var Transaction $transaction */foreach ($set as $transaction) {- $day = Carbon::createFromFormat('Y-m-d H:i:s', $transaction['date'], config('app.timezone'));+ $day = Carbon::createFromFormat('Y-m-d H:i:s', $transaction['date'], config('app.timezone'));+ if (false === $day) {+ $day = today(config('app.timezone'));+ }$format = $day->format('Y-m-d');// if the transaction is in the expected currency, change nothing.if ((int)$transaction['transaction_currency_id'] === $native->id) {@@ -449,6 +452,9 @@ class Steamforeach ($new as $index => $set) {foreach ($set as $transaction) {$date = Carbon::createFromFormat('Y-m-d H:i:s', $transaction['date']);+ if(false === $date) {+ $date = today(config('app.timezone'));+ }$rate = $converter->getCurrencyRate($currency, $native, $date);$convertedAmount = bcmul($transaction['amount'], $rate);$balance = bcadd($balance, $convertedAmount);@@ -598,7 +604,7 @@ class Steam->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))->groupBy('transactions.transaction_currency_id');- $balances = $query->get(['transactions.transaction_currency_id', DB::raw('SUM(transactions.amount) as sum_for_currency')]);+ $balances = $query->get(['transactions.transaction_currency_id', DB::raw('SUM(transactions.amount) as sum_for_currency')]); // @phpstan-ignore-line$return = [];/** @var stdClass $entry */foreach ($balances as $entry) {@@ -717,7 +723,7 @@ class Steam} catch (Exception $e) { // intentional generic exceptionthrow new FireflyException($e->getMessage(), 0, $e);}- return $hostName;+ return (string)$hostName;}/**@@ -732,7 +738,7 @@ class Steam$set = auth()->user()->transactions()->whereIn('transactions.account_id', $accounts)->groupBy(['transactions.account_id', 'transaction_journals.user_id'])- ->get(['transactions.account_id', DB::raw('MAX(transaction_journals.date) AS max_date')]);+ ->get(['transactions.account_id', DB::raw('MAX(transaction_journals.date) AS max_date')]); // @phpstan-ignore-line/** @var Transaction $entry */foreach ($set as $entry) {@@ -755,9 +761,14 @@ class Steampublic function getLocale(): string // get preference{$locale = app('preferences')->get('locale', config('firefly.default_locale', 'equal'))->data;+ if (is_array($locale)) {+ $locale = 'equal';+ }if ('equal' === $locale) {$locale = $this->getLanguage();}+ $locale = (string)$locale;+// Check for Windows to replace the locale correctly.if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {@@ -879,10 +890,10 @@ class Steamreturn $value;}- $number = substr($value, 0, strpos($value, 'E'));+ $number = substr($value, 0, (int) strpos($value, 'E'));if (str_contains($number, '.')) {- $post = strlen(substr($number, strpos($number, '.') + 1));- $mantis = substr($value, strpos($value, 'E') + 1);+ $post = strlen(substr($number, (int) strpos($number, '.') + 1));+ $mantis = substr($value, (int) strpos($value, 'E') + 1);if ($mantis < 0) {$post += abs((int)$mantis);}