mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Fix a lot of phpstan things
This commit is contained in:
@@ -152,6 +152,9 @@ class CreateController extends Controller
|
||||
|
||||
// update preferences if necessary:
|
||||
$frontPage = app('preferences')->get('frontPageAccounts', [])->data;
|
||||
if(!is_array($frontPage)) {
|
||||
$frontPage = [];
|
||||
}
|
||||
if (AccountType::ASSET === $account->accountType->type) {
|
||||
$frontPage[] = $account->id;
|
||||
app('preferences')->set('frontPageAccounts', $frontPage);
|
||||
|
@@ -195,7 +195,7 @@ class EditController extends Controller
|
||||
$request->session()->flash('success', (string)trans('firefly.updated_account', ['name' => $account->name]));
|
||||
|
||||
// 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($account, $files);
|
||||
|
@@ -207,14 +207,14 @@ class ReconcileController extends Controller
|
||||
* @param Carbon $end
|
||||
* @param string $difference
|
||||
*
|
||||
* @return RedirectResponse|Redirector|string
|
||||
* @return string
|
||||
* @throws DuplicateTransactionException
|
||||
* @throws JsonException
|
||||
*/
|
||||
private function createReconciliation(Account $account, Carbon $start, Carbon $end, string $difference)
|
||||
private function createReconciliation(Account $account, Carbon $start, Carbon $end, string $difference): string
|
||||
{
|
||||
if (!$this->isEditableAccount($account)) {
|
||||
return $this->redirectAccountToAccount($account);
|
||||
return 'not-editable';
|
||||
}
|
||||
|
||||
$reconciliation = $this->accountRepos->getReconciliation($account);
|
||||
|
@@ -170,6 +170,9 @@ class TwoFactorController extends Controller
|
||||
private function isBackupCode(string $mfaCode): bool
|
||||
{
|
||||
$list = app('preferences')->get('mfa_recovery', [])->data;
|
||||
if(!is_array($list)) {
|
||||
$list = [];
|
||||
}
|
||||
if (in_array($mfaCode, $list, true)) {
|
||||
return true;
|
||||
}
|
||||
@@ -185,6 +188,9 @@ class TwoFactorController extends Controller
|
||||
private function removeFromBackupCodes(string $mfaCode): void
|
||||
{
|
||||
$list = app('preferences')->get('mfa_recovery', [])->data;
|
||||
if(!is_array($list)) {
|
||||
$list = [];
|
||||
}
|
||||
$newList = array_values(array_diff($list, [$mfaCode]));
|
||||
app('preferences')->set('mfa_recovery', $newList);
|
||||
}
|
||||
|
@@ -138,6 +138,11 @@ class BudgetLimitController extends Controller
|
||||
}
|
||||
$start = Carbon::createFromFormat('Y-m-d', $request->get('start'));
|
||||
$end = Carbon::createFromFormat('Y-m-d', $request->get('end'));
|
||||
|
||||
if (false === $start || false === $end) {
|
||||
return response()->json([]);
|
||||
}
|
||||
|
||||
$amount = (string)$request->get('amount');
|
||||
$start->startOfDay();
|
||||
$end->startOfDay();
|
||||
|
@@ -125,6 +125,7 @@ class CreateController extends Controller
|
||||
app('preferences')->mark();
|
||||
|
||||
// store attachment(s):
|
||||
/** @var array|null $files */
|
||||
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
|
||||
if (null !== $files && !auth()->user()->hasRole('demo')) {
|
||||
$this->attachments->saveAttachmentsForModel($budget, $files);
|
||||
|
@@ -101,7 +101,11 @@ class EditController extends Controller
|
||||
'auto_budget_currency_id' => $hasOldInput ? (int)$request->old('auto_budget_currency_id') : $currency->id,
|
||||
];
|
||||
if (null !== $autoBudget) {
|
||||
$amount = $hasOldInput ? $request->old('auto_budget_amount') : $autoBudget->amount;
|
||||
$amount = $hasOldInput ? $request->old('auto_budget_amount') : $autoBudget->amount;
|
||||
if (is_array($amount)) {
|
||||
$amount = '0';
|
||||
}
|
||||
$amount = (string)$amount;
|
||||
$preFilled['auto_budget_amount'] = app('steam')->bcround($amount, $autoBudget->transactionCurrency->decimal_places);
|
||||
}
|
||||
|
||||
@@ -135,6 +139,7 @@ class EditController extends Controller
|
||||
$redirect = redirect($this->getPreviousUrl('budgets.edit.url'));
|
||||
|
||||
// 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($budget, $files);
|
||||
|
@@ -98,6 +98,7 @@ class CreateController extends Controller
|
||||
app('preferences')->mark();
|
||||
|
||||
// store attachment(s):
|
||||
/** @var array|null $files */
|
||||
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
|
||||
if (null !== $files && !auth()->user()->hasRole('demo')) {
|
||||
$this->attachments->saveAttachmentsForModel($category, $files);
|
||||
|
@@ -105,6 +105,7 @@ class EditController extends Controller
|
||||
app('preferences')->mark();
|
||||
|
||||
// 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($category, $files);
|
||||
|
@@ -335,13 +335,14 @@ class AccountController extends Controller
|
||||
$end = clone session('end', today(config('app.timezone'))->endOfMonth());
|
||||
$defaultSet = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray();
|
||||
app('log')->debug('Default set is ', $defaultSet);
|
||||
$frontPage = app('preferences')->get('frontPageAccounts', $defaultSet);
|
||||
app('log')->debug('Frontpage preference set is ', $frontPage->data);
|
||||
if (0 === count($frontPage->data)) {
|
||||
$frontPage = app('preferences')->get('frontPageAccounts', $defaultSet);
|
||||
$frontPageArray = !is_array($frontPage->data) ? [] : $frontPage->data;
|
||||
app('log')->debug('Frontpage preference set is ', $frontPageArray);
|
||||
if (0 === count($frontPageArray)) {
|
||||
app('preferences')->set('frontPageAccounts', $defaultSet);
|
||||
app('log')->debug('frontpage set is empty!');
|
||||
}
|
||||
$accounts = $repository->getAccountsById($frontPage->data);
|
||||
$accounts = $repository->getAccountsById($frontPageArray);
|
||||
|
||||
return response()->json($this->accountBalanceChart($accounts, $start, $end));
|
||||
}
|
||||
|
@@ -74,8 +74,8 @@ abstract class Controller extends BaseController
|
||||
app('view')->share('logoutUrl', $logoutUrl);
|
||||
|
||||
// upload size
|
||||
$maxFileSize = app('steam')->phpBytes(ini_get('upload_max_filesize'));
|
||||
$maxPostSize = app('steam')->phpBytes(ini_get('post_max_size'));
|
||||
$maxFileSize = app('steam')->phpBytes((string)ini_get('upload_max_filesize'));
|
||||
$maxPostSize = app('steam')->phpBytes((string)ini_get('post_max_size'));
|
||||
$uploadSize = min($maxFileSize, $maxPostSize);
|
||||
app('view')->share('uploadSize', $uploadSize);
|
||||
|
||||
|
@@ -141,7 +141,7 @@ class DebugController extends Controller
|
||||
}
|
||||
if ('' !== $logContent) {
|
||||
// last few lines
|
||||
$logContent = 'Truncated from this point <----|' . substr($logContent, -16384);
|
||||
$logContent = 'Truncated from this point <----|' . substr((string)$logContent, -16384);
|
||||
}
|
||||
|
||||
return view('debug', compact('table', 'now', 'logContent'));
|
||||
@@ -166,8 +166,8 @@ class DebugController extends Controller
|
||||
*/
|
||||
private function getSystemInformation(): array
|
||||
{
|
||||
$maxFileSize = app('steam')->phpBytes(ini_get('upload_max_filesize'));
|
||||
$maxPostSize = app('steam')->phpBytes(ini_get('post_max_size'));
|
||||
$maxFileSize = app('steam')->phpBytes((string)ini_get('upload_max_filesize'));
|
||||
$maxPostSize = app('steam')->phpBytes((string)ini_get('post_max_size'));
|
||||
$drivers = DB::availableDrivers();
|
||||
$currentDriver = DB::getDriverName();
|
||||
return [
|
||||
@@ -199,7 +199,7 @@ class DebugController extends Controller
|
||||
];
|
||||
try {
|
||||
if (file_exists('/var/www/counter-main.txt')) {
|
||||
$return['build'] = trim(file_get_contents('/var/www/counter-main.txt'));
|
||||
$return['build'] = trim((string)file_get_contents('/var/www/counter-main.txt'));
|
||||
}
|
||||
} catch (Exception $e) { // @phpstan-ignore-line
|
||||
app('log')->debug('Could not check build counter, but thats ok.');
|
||||
@@ -207,7 +207,7 @@ class DebugController extends Controller
|
||||
}
|
||||
try {
|
||||
if (file_exists('/var/www/build-date-main.txt')) {
|
||||
$return['build_date'] = trim(file_get_contents('/var/www/build-date-main.txt'));
|
||||
$return['build_date'] = trim((string)file_get_contents('/var/www/build-date-main.txt'));
|
||||
}
|
||||
} catch (Exception $e) { // @phpstan-ignore-line
|
||||
app('log')->debug('Could not check build date, but thats ok.');
|
||||
@@ -236,7 +236,7 @@ class DebugController extends Controller
|
||||
if ($lastTime > 0) {
|
||||
$carbon = Carbon::createFromTimestamp($lastTime);
|
||||
$lastCronjob = $carbon->format('Y-m-d H:i:s');
|
||||
$lastCronjobAgo = $carbon->locale('en')->diffForHumans();
|
||||
$lastCronjobAgo = $carbon->locale('en')->diffForHumans(); // @phpstan-ignore-line
|
||||
}
|
||||
|
||||
return [
|
||||
@@ -279,7 +279,7 @@ class DebugController extends Controller
|
||||
$result = setlocale(LC_ALL, $code);
|
||||
$localeAttempts[$code] = $result === $code;
|
||||
}
|
||||
setlocale(LC_ALL, $original);
|
||||
setlocale(LC_ALL, (string) $original);
|
||||
|
||||
return [
|
||||
'user_id' => auth()->user()->id,
|
||||
|
Reference in New Issue
Block a user