mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 02:36:28 +00:00 
			
		
		
		
	Various phpstan fixes
This commit is contained in:
		| @@ -31,7 +31,6 @@ use FireflyIII\Exceptions\FireflyException; | ||||
| use FireflyIII\Helpers\Collector\GroupCollectorInterface; | ||||
| use FireflyIII\Http\Middleware\Installer; | ||||
| use FireflyIII\Models\AccountType; | ||||
| use FireflyIII\Models\TransactionJournal; | ||||
| use FireflyIII\Repositories\Account\AccountRepositoryInterface; | ||||
| use FireflyIII\Repositories\Bill\BillRepositoryInterface; | ||||
| use FireflyIII\User; | ||||
| @@ -69,7 +68,7 @@ class HomeController extends Controller | ||||
|     public function dateRange(Request $request): JsonResponse | ||||
|     { | ||||
|         $stringStart = ''; | ||||
|         $stringEnd = ''; | ||||
|         $stringEnd   = ''; | ||||
|         try { | ||||
|             $stringStart = e((string)$request->get('start')); | ||||
|             $start       = Carbon::createFromFormat('Y-m-d', $stringStart); | ||||
| @@ -84,6 +83,13 @@ class HomeController extends Controller | ||||
|             app('log')->error(sprintf('End could not parse date string "%s" so ignore it.', $stringEnd)); | ||||
|             $end = Carbon::now()->endOfMonth(); | ||||
|         } | ||||
|         if (false === $start) { | ||||
|             $start = Carbon::now()->startOfMonth(); | ||||
|         } | ||||
|         if (false === $end) { | ||||
|             $end = Carbon::now()->endOfMonth(); | ||||
|         } | ||||
| 
 | ||||
|         $label         = $request->get('label'); | ||||
|         $isCustomRange = false; | ||||
| 
 | ||||
| @@ -128,20 +134,26 @@ class HomeController extends Controller | ||||
|         if (0 === $count) { | ||||
|             return redirect(route('new-user.index')); | ||||
|         } | ||||
|         $subTitle     = (string)trans('firefly.welcome_back'); | ||||
|         $transactions = []; | ||||
|         $frontPage    = app('preferences')->getFresh('frontPageAccounts', $repository->getAccountsByType([AccountType::ASSET])->pluck('id')->toArray()); | ||||
|         $subTitle       = (string)trans('firefly.welcome_back'); | ||||
|         $transactions   = []; | ||||
|         $frontPage      = app('preferences')->getFresh('frontPageAccounts', $repository->getAccountsByType([AccountType::ASSET])->pluck('id')->toArray()); | ||||
|         $frontPageArray = $frontPage->data; | ||||
|         if (!is_array($frontPageArray)) { | ||||
|             $frontPageArray = []; | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         /** @var Carbon $start */ | ||||
|         $start = session('start', today(config('app.timezone'))->startOfMonth()); | ||||
|         /** @var Carbon $end */ | ||||
|         $end      = session('end', today(config('app.timezone'))->endOfMonth()); | ||||
|         $accounts = $repository->getAccountsById($frontPage->data); | ||||
|         $accounts = $repository->getAccountsById($frontPageArray); | ||||
|         $today    = today(config('app.timezone')); | ||||
| 
 | ||||
|         // sort frontpage accounts by order
 | ||||
|         $accounts = $accounts->sortBy('order'); | ||||
| 
 | ||||
|         app('log')->debug('Frontpage accounts are ', $frontPage->data); | ||||
|         app('log')->debug('Frontpage accounts are ', $frontPageArray); | ||||
| 
 | ||||
|         /** @var BillRepositoryInterface $billRepository */ | ||||
|         $billRepository = app(BillRepositoryInterface::class); | ||||
|   | ||||
| @@ -79,6 +79,11 @@ class RecurrenceController extends Controller | ||||
|         $repetitionType   = explode(',', $request->get('type'))[0]; | ||||
|         $repetitions      = (int)$request->get('reps'); | ||||
|         $repetitionMoment = ''; | ||||
| 
 | ||||
|         if(false === $start || false === $end || false === $firstDate || false === $endDate) { | ||||
|             return response()->json(); | ||||
|         } | ||||
| 
 | ||||
|         $start->startOfDay(); | ||||
| 
 | ||||
|         // if $firstDate is beyond $end, simply return an empty array.
 | ||||
| @@ -148,10 +153,14 @@ class RecurrenceController extends Controller | ||||
|         $string = '' === (string)$request->get('date') ? date('Y-m-d') : (string)$request->get('date'); | ||||
|         $today  = today(config('app.timezone'))->startOfDay(); | ||||
|         try { | ||||
|             $date = Carbon::createFromFormat('Y-m-d', $string, config('app.timezone'))->startOfDay(); | ||||
|             $date = Carbon::createFromFormat('Y-m-d', $string, config('app.timezone')); | ||||
|         } catch (InvalidFormatException $e) { | ||||
|             $date = Carbon::today(config('app.timezone')); | ||||
|         } | ||||
|         if(false === $date) { | ||||
|             return response()->json(); | ||||
|         } | ||||
|         $date->startOfDay(); | ||||
|         $preSelected = (string)$request->get('pre_select'); | ||||
|         $locale      = app('steam')->getLocale(); | ||||
| 
 | ||||
|   | ||||
| @@ -91,13 +91,18 @@ class PreferencesController extends Controller | ||||
|             if ('opt_group_' === $role) { | ||||
|                 $role = 'opt_group_defaultAsset'; | ||||
|             } | ||||
|             $groupedAccounts[trans(sprintf('firefly.%s', $role))][$account->id] = $account->name; | ||||
|             $groupedAccounts[(string)trans(sprintf('firefly.%s', $role))][$account->id] = $account->name; | ||||
|         } | ||||
|         ksort($groupedAccounts); | ||||
| 
 | ||||
|         $accountIds         = $accounts->pluck('id')->toArray(); | ||||
|         $viewRange          = app('navigation')->getViewRange(false); | ||||
|         $frontPageAccounts  = app('preferences')->get('frontPageAccounts', $accountIds); | ||||
|         /** @var array<int, int> $accountIds */ | ||||
|         $accountIds            = $accounts->pluck('id')->toArray(); | ||||
|         $viewRange             = app('navigation')->getViewRange(false); | ||||
|         $frontPageAccountsPref     = app('preferences')->get('frontPageAccounts', $accountIds); | ||||
|         $frontPageAccounts = $frontPageAccountsPref->data; | ||||
|         if (!is_array($frontPageAccounts)) { | ||||
|             $frontPageAccounts = $accountIds; | ||||
|         } | ||||
|         $language           = app('steam')->getLanguage(); | ||||
|         $languages          = config('firefly.languages'); | ||||
|         $locale             = app('preferences')->get('locale', config('firefly.default_locale', 'equal'))->data; | ||||
| @@ -106,7 +111,10 @@ class PreferencesController extends Controller | ||||
|         $slackUrl           = app('preferences')->get('slack_webhook_url', '')->data; | ||||
|         $customFiscalYear   = app('preferences')->get('customFiscalYear', 0)->data; | ||||
|         $fiscalYearStartStr = app('preferences')->get('fiscalYearStart', '01-01')->data; | ||||
|         $fiscalYearStart    = date('Y') . '-' . $fiscalYearStartStr; | ||||
|         if (is_array($fiscalYearStartStr)) { | ||||
|             $fiscalYearStartStr = '01-01'; | ||||
|         } | ||||
|         $fiscalYearStart    = sprintf('%s-%s', date('Y'), (string)$fiscalYearStartStr); | ||||
|         $tjOptionalFields   = app('preferences')->get('transaction_journal_optional_fields', [])->data; | ||||
|         $availableDarkModes = config('firefly.available_dark_modes'); | ||||
| 
 | ||||
| @@ -121,7 +129,7 @@ class PreferencesController extends Controller | ||||
|         // list of locales also has "equal" which makes it equal to whatever the language is.
 | ||||
| 
 | ||||
|         try { | ||||
|             $locales = json_decode(file_get_contents(resource_path(sprintf('lang/%s/locales.json', $language))), true, 512, JSON_THROW_ON_ERROR); | ||||
|             $locales = json_decode((string)file_get_contents(resource_path(sprintf('lang/%s/locales.json', $language))), true, 512, JSON_THROW_ON_ERROR); | ||||
|         } catch (JsonException $e) { | ||||
|             app('log')->error($e->getMessage()); | ||||
|             $locales = []; | ||||
| @@ -129,12 +137,12 @@ class PreferencesController extends Controller | ||||
|         $locales = ['equal' => (string)trans('firefly.equal_to_language')] + $locales; | ||||
|         // an important fallback is that the frontPageAccount array gets refilled automatically
 | ||||
|         // when it turns up empty.
 | ||||
|         if (0 === count($frontPageAccounts->data)) { | ||||
|         if (0 === count($frontPageAccounts)) { | ||||
|             $frontPageAccounts = $accountIds; | ||||
|         } | ||||
| 
 | ||||
|         // for the demo user, the slackUrl is automatically emptied.
 | ||||
|         // this isn't really secure but it means that the demo site has a semi-secret
 | ||||
|         // this isn't really secure, but it means that the demo site has a semi-secret
 | ||||
|         // slackUrl.
 | ||||
|         if (auth()->user()->hasRole('demo')) { | ||||
|             $slackUrl = ''; | ||||
|   | ||||
| @@ -36,7 +36,6 @@ use FireflyIII\Http\Requests\ProfileFormRequest; | ||||
| use FireflyIII\Http\Requests\TokenFormRequest; | ||||
| use FireflyIII\Models\Preference; | ||||
| use FireflyIII\Repositories\User\UserRepositoryInterface; | ||||
| use FireflyIII\Support\Facades\Preferences; | ||||
| use FireflyIII\Support\Http\Controllers\CreateStuff; | ||||
| use FireflyIII\User; | ||||
| use Google2FA; | ||||
| @@ -129,6 +128,9 @@ class ProfileController extends Controller | ||||
|             // get secret from session and flash
 | ||||
|             $secret = $secretPreference->data; | ||||
|         } | ||||
|         if (is_array($secret)) { | ||||
|             $secret = ''; | ||||
|         } | ||||
| 
 | ||||
|         // generate recovery codes if not in session:
 | ||||
|         $recoveryCodes = ''; | ||||
| @@ -144,10 +146,13 @@ class ProfileController extends Controller | ||||
|         if (null !== $codesPreference) { | ||||
|             $recoveryCodes = $codesPreference->data; | ||||
|         } | ||||
|         if (!is_array($recoveryCodes)) { | ||||
|             $recoveryCodes = []; | ||||
|         } | ||||
| 
 | ||||
|         $codes = implode("\r\n", $recoveryCodes); | ||||
| 
 | ||||
|         $image = Google2FA::getQRCodeInline($domain, auth()->user()->email, $secret); | ||||
|         $image = Google2FA::getQRCodeInline($domain, auth()->user()->email, (string)$secret); | ||||
| 
 | ||||
|         return view('profile.code', compact('image', 'secret', 'codes')); | ||||
|     } | ||||
| @@ -283,7 +288,11 @@ class ProfileController extends Controller | ||||
|         $subTitle       = $user->email; | ||||
|         $userId         = $user->id; | ||||
|         $enabled2FA     = null !== $user->mfa_secret; | ||||
|         $mfaBackupCount = count(app('preferences')->get('mfa_recovery', [])->data); | ||||
|         $recoveryData   = app('preferences')->get('mfa_recovery', [])->data; | ||||
|         if (!is_array($recoveryData)) { | ||||
|             $recoveryData = []; | ||||
|         } | ||||
|         $mfaBackupCount = count($recoveryData); | ||||
|         $this->createOAuthKeys(); | ||||
| 
 | ||||
|         if (0 === $count) { | ||||
| @@ -499,6 +508,12 @@ class ProfileController extends Controller | ||||
|         /** @var UserRepositoryInterface $repository */ | ||||
|         $repository = app(UserRepositoryInterface::class); | ||||
|         $secret     = app('preferences')->get('temp-mfa-secret')?->data; | ||||
|         if (is_array($secret)) { | ||||
|             $secret = null; | ||||
|         } | ||||
|         if (is_int($secret)) { | ||||
|             $secret = (string)$secret; | ||||
|         } | ||||
| 
 | ||||
|         $repository->setMFACode($user, $secret); | ||||
| 
 | ||||
|   | ||||
| @@ -181,6 +181,7 @@ class EditController extends Controller | ||||
|         $request->session()->flash('success', (string)trans('firefly.updated_recurrence', ['title' => $recurrence->title])); | ||||
| 
 | ||||
|         // store new attachment(s):
 | ||||
|         /** @var array|null $files */ | ||||
|         $files = $request->hasFile('attachments') ? $request->file('attachments') : null; | ||||
|         if (null !== $files && !auth()->user()->hasRole('demo')) { | ||||
|             $this->attachments->saveAttachmentsForModel($recurrence, $files); | ||||
|   | ||||
| @@ -49,12 +49,8 @@ use Psr\Container\NotFoundExceptionInterface; | ||||
| class ReportController extends Controller | ||||
| { | ||||
|     use RenderPartialViews; | ||||
| 
 | ||||
|     /** @var ReportHelperInterface Helper interface. */ | ||||
|     protected $helper; | ||||
| 
 | ||||
|     /** @var BudgetRepositoryInterface The budget repository */ | ||||
|     private $repository; | ||||
|     protected ReportHelperInterface $helper; | ||||
|     private BudgetRepositoryInterface $repository; | ||||
| 
 | ||||
|     /** | ||||
|      * ReportController constructor. | ||||
| @@ -291,7 +287,7 @@ class ReportController extends Controller | ||||
|             if ('opt_group_' === $role) { | ||||
|                 $role = 'opt_group_defaultAsset'; | ||||
|             } | ||||
|             $groupedAccounts[trans(sprintf('firefly.%s', $role))][$account->id] = $account; | ||||
|             $groupedAccounts[(string)trans(sprintf('firefly.%s', $role))][$account->id] = $account; | ||||
|         } | ||||
|         ksort($groupedAccounts); | ||||
| 
 | ||||
|   | ||||
| @@ -220,7 +220,7 @@ class CreateController extends Controller | ||||
|         ]; | ||||
| 
 | ||||
|         // restore actions and triggers from old input:
 | ||||
|         if (null !== $request->old() && count($request->old()) > 0) { | ||||
|         if (null !== $request->old() && is_array($request->old()) && count($request->old()) > 0) { | ||||
|             $oldTriggers = $this->getPreviousTriggers($request); | ||||
|             $oldActions  = $this->getPreviousActions($request); | ||||
|         } | ||||
|   | ||||
| @@ -100,7 +100,7 @@ class EditController extends Controller | ||||
|             $oldTriggers = $this->parseFromOperators($operators); | ||||
|         } | ||||
|         // has old input?
 | ||||
|         if (count($request->old()) > 0) { | ||||
|         if (null !== $request->old() && is_array($request->old()) && count($request->old()) > 0) { | ||||
|             $oldTriggers = $this->getPreviousTriggers($request); | ||||
|             $oldActions  = $this->getPreviousActions($request); | ||||
|         } | ||||
|   | ||||
| @@ -137,6 +137,7 @@ class SelectController extends Controller | ||||
|     { | ||||
|         // build fake rule
 | ||||
|         $rule         = new Rule(); | ||||
|         /** @var \Illuminate\Database\Eloquent\Collection<int, RuleTrigger> $triggers */ | ||||
|         $triggers     = new Collection(); | ||||
|         $rule->strict = '1' === $request->get('strict'); | ||||
| 
 | ||||
|   | ||||
| @@ -117,7 +117,7 @@ class InstallController extends Controller | ||||
|             } catch (FireflyException $e) { | ||||
|                 app('log')->error($e->getMessage()); | ||||
|                 app('log')->error($e->getTraceAsString()); | ||||
|                 if (strpos($e->getMessage(), 'open_basedir restriction in effect')) { | ||||
|                 if (str_contains($e->getMessage(), 'open_basedir restriction in effect')) { | ||||
|                     $this->lastError = self::BASEDIR_ERROR; | ||||
|                 } | ||||
|                 $result          = false; | ||||
|   | ||||
| @@ -99,9 +99,9 @@ class DeleteController extends Controller | ||||
|      * | ||||
|      * @param TransactionGroup $group | ||||
|      * | ||||
|      * @return RedirectResponse | ||||
|      * @return RedirectResponse|Redirector | ||||
|      */ | ||||
|     public function destroy(TransactionGroup $group): RedirectResponse | ||||
|     public function destroy(TransactionGroup $group): RedirectResponse|Redirector | ||||
|     { | ||||
|         app('log')->debug(sprintf('Now in %s(#%d).', __METHOD__, $group->id)); | ||||
|         if (!$this->isEditableGroup($group)) { | ||||
|   | ||||
| @@ -163,9 +163,9 @@ class ShowController extends Controller | ||||
|             $amounts[$symbol]['amount'] = bcadd($amounts[$symbol]['amount'], $transaction['amount']); | ||||
|             if (null !== $transaction['foreign_amount'] && '' !== $transaction['foreign_amount'] | ||||
|                 && bccomp( | ||||
|                     '0', | ||||
|                     $transaction['foreign_amount'] | ||||
|                 ) !== 0) { | ||||
|                        '0', | ||||
|                        $transaction['foreign_amount'] | ||||
|                    ) !== 0) { | ||||
|                 // same for foreign currency:
 | ||||
|                 $foreignSymbol = $transaction['foreign_currency_symbol']; | ||||
|                 if (!array_key_exists($foreignSymbol, $amounts)) { | ||||
| @@ -192,7 +192,10 @@ class ShowController extends Controller | ||||
|      */ | ||||
|     private function getAccounts(array $group): array | ||||
|     { | ||||
|         $accounts = []; | ||||
|         $accounts = [ | ||||
|             'source'      => [], | ||||
|             'destination' => [], | ||||
|         ]; | ||||
| 
 | ||||
|         foreach ($group['transactions'] as $transaction) { | ||||
|             $accounts['source'][]      = [ | ||||
|   | ||||
| @@ -69,6 +69,10 @@ class Range | ||||
|         // ignore preference. set the range to be the current month:
 | ||||
|         if (!app('session')->has('start') && !app('session')->has('end')) { | ||||
|             $viewRange = app('preferences')->get('viewRange', '1M')->data; | ||||
|             if(is_array($viewRange)) { | ||||
|                 $viewRange = '1M'; | ||||
|             } | ||||
| 
 | ||||
|             $today     = today(config('app.timezone')); | ||||
|             $start     = app('navigation')->updateStartDate($viewRange, $today); | ||||
|             $end       = app('navigation')->updateEndDate($viewRange, $start); | ||||
|   | ||||
| @@ -151,7 +151,7 @@ class ReportFormRequest extends FormRequest | ||||
|             // validate as date
 | ||||
|             // 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, $string)) { | ||||
|             if (false !== preg_match($pattern, $string)) { | ||||
|                 try { | ||||
|                     $date = new Carbon($parts[1]); | ||||
|                 } catch (Exception $e) { // intentional generic exception
 | ||||
| @@ -186,7 +186,7 @@ class ReportFormRequest extends FormRequest | ||||
|             // validate as date
 | ||||
|             // 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, $string)) { | ||||
|             if (false !== preg_match($pattern, $string)) { | ||||
|                 try { | ||||
|                     $date = new Carbon($parts[0]); | ||||
|                 } catch (Exception $e) { // intentional generic exception
 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user