mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-20 19:35:16 +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;
|
||||
@@ -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;
|
||||
|
||||
@@ -131,17 +137,23 @@ class HomeController extends Controller
|
||||
$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);
|
||||
|
||||
/** @var array<int, int> $accountIds */
|
||||
$accountIds = $accounts->pluck('id')->toArray();
|
||||
$viewRange = app('navigation')->getViewRange(false);
|
||||
$frontPageAccounts = app('preferences')->get('frontPageAccounts', $accountIds);
|
||||
$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)) {
|
||||
|
@@ -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
|
||||
|
@@ -121,6 +121,9 @@ class DownloadExchangeRates implements ShouldQueue
|
||||
return;
|
||||
}
|
||||
$date = Carbon::createFromFormat('Y-m-d', $json['date'], config('app.timezone'));
|
||||
if(false === $date) {
|
||||
return;
|
||||
}
|
||||
$this->saveRates($currency, $date, $json['rates']);
|
||||
}
|
||||
|
||||
|
@@ -53,7 +53,7 @@ class InvitationMail extends Mailable
|
||||
$this->invitee = $invitee;
|
||||
$this->admin = $admin;
|
||||
$this->url = $url;
|
||||
$this->host = parse_url($url, PHP_URL_HOST);
|
||||
$this->host = (string) parse_url($url, PHP_URL_HOST);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Eloquent;
|
||||
use FireflyIII\Support\Models\ReturnsIntegerIdTrait;
|
||||
use FireflyIII\Support\Models\ReturnsIntegerUserIdTrait;
|
||||
@@ -33,11 +34,9 @@ use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphToMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Carbon\Carbon;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
@@ -57,7 +56,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
* @property Carbon|null $end_date
|
||||
* @property Carbon|null $extension_date
|
||||
* @property string $repeat_freq
|
||||
* @property int|string $skip
|
||||
* @property int $skip
|
||||
* @property bool $automatch
|
||||
* @property bool $active
|
||||
* @property bool $name_encrypted
|
||||
@@ -247,6 +246,18 @@ class Bill extends Model
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the skip
|
||||
*
|
||||
* @return Attribute
|
||||
*/
|
||||
protected function skip(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: static fn ($value) => (int)$value,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the min amount
|
||||
*
|
||||
|
@@ -94,7 +94,7 @@ class Preference extends Model
|
||||
$preference = new self();
|
||||
$preference->name = $value;
|
||||
$preference->data = $default[$value];
|
||||
$preference->user_id = $user->id;
|
||||
$preference->user_id = (int) $user->id;
|
||||
$preference->save();
|
||||
|
||||
return $preference;
|
||||
|
@@ -95,7 +95,7 @@ class TransactionJournalMeta extends Model
|
||||
{
|
||||
$data = json_encode($value);
|
||||
$this->attributes['data'] = $data;
|
||||
$this->attributes['hash'] = hash('sha256', $data);
|
||||
$this->attributes['hash'] = (string) hash('sha256', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -122,8 +122,11 @@ class BillReminder extends Notification
|
||||
{
|
||||
/** @var User|null $user */
|
||||
$user = auth()->user();
|
||||
$slackUrl = null === $user ? '' : (string)app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;
|
||||
if (UrlValidator::isValidWebhookURL($slackUrl)) {
|
||||
$slackUrl = null === $user ? '' : app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;
|
||||
if (is_array($slackUrl)) {
|
||||
$slackUrl = '';
|
||||
}
|
||||
if (UrlValidator::isValidWebhookURL((string) $slackUrl)) {
|
||||
return ['mail', 'slack'];
|
||||
}
|
||||
return ['mail'];
|
||||
|
@@ -98,8 +98,11 @@ class NewAccessToken extends Notification
|
||||
{
|
||||
/** @var User|null $user */
|
||||
$user = auth()->user();
|
||||
$slackUrl = null === $user ? '' : (string)app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;
|
||||
if (UrlValidator::isValidWebhookURL($slackUrl)) {
|
||||
$slackUrl = null === $user ? '' : app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;
|
||||
if (is_array($slackUrl)) {
|
||||
$slackUrl = '';
|
||||
}
|
||||
if (UrlValidator::isValidWebhookURL((string)$slackUrl)) {
|
||||
return ['mail', 'slack'];
|
||||
}
|
||||
return ['mail'];
|
||||
|
@@ -106,8 +106,11 @@ class RuleActionFailed extends Notification
|
||||
{
|
||||
/** @var User|null $user */
|
||||
$user = auth()->user();
|
||||
$slackUrl = null === $user ? '' : (string)app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;
|
||||
if (UrlValidator::isValidWebhookURL($slackUrl)) {
|
||||
$slackUrl = null === $user ? '' : app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;
|
||||
if (is_array($slackUrl)) {
|
||||
$slackUrl = '';
|
||||
}
|
||||
if (UrlValidator::isValidWebhookURL((string)$slackUrl)) {
|
||||
app('log')->debug('Will send ruleActionFailed through Slack!');
|
||||
return ['slack'];
|
||||
}
|
||||
|
@@ -125,8 +125,11 @@ class UserLogin extends Notification
|
||||
{
|
||||
/** @var User|null $user */
|
||||
$user = auth()->user();
|
||||
$slackUrl = null === $user ? '' : (string)app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;
|
||||
if (UrlValidator::isValidWebhookURL($slackUrl)) {
|
||||
$slackUrl = null === $user ? '' : app('preferences')->getForUser(auth()->user(), 'slack_webhook_url', '')->data;
|
||||
if (is_array($slackUrl)) {
|
||||
$slackUrl = '';
|
||||
}
|
||||
if (UrlValidator::isValidWebhookURL((string) $slackUrl)) {
|
||||
return ['mail', 'slack'];
|
||||
}
|
||||
return ['mail'];
|
||||
|
@@ -123,7 +123,7 @@ interface AccountRepositoryInterface
|
||||
public function getAccountsById(array $accountIds): Collection;
|
||||
|
||||
/**
|
||||
* @param array<int, string> $types
|
||||
* @param array<int, int|string> $types
|
||||
* @param array|null $sort
|
||||
*
|
||||
* @return Collection
|
||||
|
Reference in New Issue
Block a user