mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Code cleanup that (hopefully) matches style CI
This commit is contained in:
@@ -29,6 +29,7 @@ use FireflyIII\Exceptions\FireflyException;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use Illuminate\Contracts\Auth\Factory as Auth;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* Class Authenticate
|
||||
@@ -38,14 +39,14 @@ class Authenticate
|
||||
/**
|
||||
* The authentication factory instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Auth\Factory
|
||||
* @var Auth
|
||||
*/
|
||||
protected $auth;
|
||||
|
||||
/**
|
||||
* Create a new middleware instance.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Auth\Factory $auth
|
||||
* @param Auth $auth
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@@ -57,14 +58,14 @@ class Authenticate
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string[] ...$guards
|
||||
*
|
||||
* @return mixed
|
||||
* @param Request $request
|
||||
* @param Closure $next
|
||||
* @param string[] ...$guards
|
||||
*
|
||||
* @throws AuthenticationException
|
||||
* @throws FireflyException
|
||||
* @return mixed
|
||||
*
|
||||
*/
|
||||
public function handle($request, Closure $next, ...$guards)
|
||||
{
|
||||
@@ -78,11 +79,11 @@ class Authenticate
|
||||
* Determine if the user is logged in to any of the given guards.
|
||||
*
|
||||
* @param $request
|
||||
* @param array $guards
|
||||
* @param array $guards
|
||||
*
|
||||
* @return mixed
|
||||
* @throws AuthenticationException
|
||||
* @throws FireflyException
|
||||
* @return mixed
|
||||
*/
|
||||
protected function authenticate($request, array $guards)
|
||||
{
|
||||
@@ -96,10 +97,10 @@ class Authenticate
|
||||
// do an extra check on user object.
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
$user = $this->auth->authenticate();
|
||||
if (1 === (int)$user->blocked) {
|
||||
$message = (string)trans('firefly.block_account_logout');
|
||||
if (1 === (int) $user->blocked) {
|
||||
$message = (string) trans('firefly.block_account_logout');
|
||||
if ('email_changed' === $user->blocked_code) {
|
||||
$message = (string)trans('firefly.email_changed_logout');
|
||||
$message = (string) trans('firefly.email_changed_logout');
|
||||
}
|
||||
app('session')->flash('logoutMessage', $message);
|
||||
/** @noinspection PhpUndefinedMethodInspection */
|
||||
|
@@ -25,6 +25,7 @@ namespace FireflyIII\Http\Middleware;
|
||||
use Closure;
|
||||
use FireflyIII\Support\Domain;
|
||||
use Illuminate\Contracts\Auth\Factory as Auth;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Route;
|
||||
|
||||
/**
|
||||
@@ -35,7 +36,7 @@ class Binder
|
||||
/**
|
||||
* The authentication factory instance.
|
||||
*
|
||||
* @var \Illuminate\Contracts\Auth\Factory
|
||||
* @var Auth
|
||||
*/
|
||||
protected $auth;
|
||||
/**
|
||||
@@ -48,7 +49,7 @@ class Binder
|
||||
/**
|
||||
* Binder constructor.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Auth\Factory $auth
|
||||
* @param Auth $auth
|
||||
*/
|
||||
public function __construct(Auth $auth)
|
||||
{
|
||||
@@ -60,8 +61,8 @@ class Binder
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param Request $request
|
||||
* @param Closure $next
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
|
@@ -41,21 +41,21 @@ class InstallationId
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param Closure $next
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws FireflyException
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
$config = app('fireflyconfig')->get('installation_id', null);
|
||||
if (null === $config) {
|
||||
$uuid5 = Uuid::uuid5(Uuid::NAMESPACE_URL, 'firefly-iii.org');
|
||||
$uniqueId = (string)$uuid5;
|
||||
$uniqueId = (string) $uuid5;
|
||||
Log::info(sprintf('Created Firefly III installation ID %s', $uniqueId));
|
||||
app('fireflyconfig')->set('installation_id', $uniqueId);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -29,6 +29,7 @@ use DB;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Support\System\OAuthKeys;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Http\Request;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
@@ -42,13 +43,13 @@ class Installer
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
*
|
||||
* @return mixed
|
||||
* @param Request $request
|
||||
* @param Closure $next
|
||||
*
|
||||
* @throws FireflyException
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
@@ -107,8 +108,8 @@ class Installer
|
||||
/**
|
||||
* Check if the tables are created and accounted for.
|
||||
*
|
||||
* @return bool
|
||||
* @throws FireflyException
|
||||
* @return bool
|
||||
*/
|
||||
private function hasNoTables(): bool
|
||||
{
|
||||
@@ -127,14 +128,12 @@ class Installer
|
||||
Log::warning('There are no Firefly III tables present. Redirect to migrate routine.');
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
throw new FireflyException(sprintf('Could not access the database: %s', $message));
|
||||
}
|
||||
Log::debug('Everything seems OK with the tables.');
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,12 +144,14 @@ class Installer
|
||||
private function oldDBVersion(): bool
|
||||
{
|
||||
// older version in config than database?
|
||||
$configVersion = (int)config('firefly.db_version');
|
||||
$dbVersion = (int)app('fireflyconfig')->getFresh('db_version', 1)->data;
|
||||
$configVersion = (int) config('firefly.db_version');
|
||||
$dbVersion = (int) app('fireflyconfig')->getFresh('db_version', 1)->data;
|
||||
if ($configVersion > $dbVersion) {
|
||||
Log::warning(
|
||||
sprintf(
|
||||
'The current configured version (%d) is older than the required version (%d). Redirect to migrate routine.', $dbVersion, $configVersion
|
||||
'The current configured version (%d) is older than the required version (%d). Redirect to migrate routine.',
|
||||
$dbVersion,
|
||||
$configVersion
|
||||
)
|
||||
);
|
||||
|
||||
@@ -169,12 +170,14 @@ class Installer
|
||||
private function oldVersion(): bool
|
||||
{
|
||||
// version compare thing.
|
||||
$configVersion = (string)config('firefly.version');
|
||||
$dbVersion = (string)app('fireflyconfig')->getFresh('ff3_version', '1.0')->data;
|
||||
$configVersion = (string) config('firefly.version');
|
||||
$dbVersion = (string) app('fireflyconfig')->getFresh('ff3_version', '1.0')->data;
|
||||
if (1 === version_compare($configVersion, $dbVersion)) {
|
||||
Log::warning(
|
||||
sprintf(
|
||||
'The current configured Firefly III version (%s) is older than the required version (%s). Redirect to migrate routine.', $dbVersion, $configVersion
|
||||
'The current configured Firefly III version (%s) is older than the required version (%s). Redirect to migrate routine.',
|
||||
$dbVersion,
|
||||
$configVersion
|
||||
)
|
||||
);
|
||||
|
||||
@@ -184,5 +187,4 @@ class Installer
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -38,8 +38,8 @@ class InterestingMessage
|
||||
/**
|
||||
* Flashes the user an interesting message if the URL parameters warrant it.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param \Closure $next
|
||||
* @param Request $request
|
||||
* @param Closure $next
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
@@ -85,7 +85,7 @@ class InterestingMessage
|
||||
|
||||
// send message about newly created transaction group.
|
||||
/** @var TransactionGroup $group */
|
||||
$group = auth()->user()->transactionGroups()->with(['transactionJournals', 'transactionJournals.transactionType'])->find((int)$transactionGroupId);
|
||||
$group = auth()->user()->transactionGroups()->with(['transactionJournals', 'transactionJournals.transactionType'])->find((int) $transactionGroupId);
|
||||
|
||||
if (null === $group) {
|
||||
return;
|
||||
@@ -101,12 +101,12 @@ class InterestingMessage
|
||||
$title = $count > 1 ? $group->title : $journal->description;
|
||||
if ('created' === $message) {
|
||||
session()->flash('success_uri', route('transactions.show', [$transactionGroupId]));
|
||||
session()->flash('success', (string)trans('firefly.stored_journal', ['description' => $title]));
|
||||
session()->flash('success', (string) trans('firefly.stored_journal', ['description' => $title]));
|
||||
}
|
||||
if ('updated' === $message) {
|
||||
$type = strtolower($journal->transactionType->type);
|
||||
session()->flash('success_uri', route('transactions.show', [$transactionGroupId]));
|
||||
session()->flash('success', (string)trans(sprintf('firefly.updated_%s', $type), ['description' => $title]));
|
||||
session()->flash('success', (string) trans(sprintf('firefly.updated_%s', $type), ['description' => $title]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -36,9 +36,9 @@ class IsAdmin
|
||||
/**
|
||||
* Handle an incoming request. Must be admin.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
* @param Request $request
|
||||
* @param Closure $next
|
||||
* @param string|null $guard
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
|
@@ -36,8 +36,8 @@ class IsDemoUser
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param Request $request
|
||||
* @param Closure $next
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -53,7 +53,7 @@ class IsDemoUser
|
||||
$repository = app(UserRepositoryInterface::class);
|
||||
if ($repository->hasRole($user, 'demo')) {
|
||||
Log::info('User is a demo user.');
|
||||
$request->session()->flash('info', (string)trans('firefly.not_available_demo_user'));
|
||||
$request->session()->flash('info', (string) trans('firefly.not_available_demo_user'));
|
||||
$current = $request->url();
|
||||
$previous = $request->session()->previousUrl();
|
||||
if ($current !== $previous) {
|
||||
|
@@ -35,9 +35,9 @@ class IsSandStormUser
|
||||
/**
|
||||
* Handle an incoming request. May not be a limited user (ie. Sandstorm env. or demo user).
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
* @param Request $request
|
||||
* @param Closure $next
|
||||
* @param string|null $guard
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -48,8 +48,8 @@ class IsSandStormUser
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
if (1 === (int)getenv('SANDSTORM')) {
|
||||
app('session')->flash('warning', (string)trans('firefly.sandstorm_not_available'));
|
||||
if (1 === (int) getenv('SANDSTORM')) {
|
||||
app('session')->flash('warning', (string) trans('firefly.sandstorm_not_available'));
|
||||
|
||||
return response()->redirectTo(route('index'));
|
||||
}
|
||||
|
@@ -36,8 +36,8 @@ class Range
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param Closure $next
|
||||
* @param Request $request
|
||||
* @param Closure $next
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -77,7 +77,7 @@ class Range
|
||||
$lang = $pref->data;
|
||||
App::setLocale($lang);
|
||||
Carbon::setLocale(substr($lang, 0, 2));
|
||||
$locale = explode(',', (string)trans('config.locale'));
|
||||
$locale = explode(',', (string) trans('config.locale'));
|
||||
$locale = array_map('trim', $locale);
|
||||
|
||||
setlocale(LC_TIME, $locale);
|
||||
@@ -89,12 +89,12 @@ class Range
|
||||
}
|
||||
|
||||
// save some formats:
|
||||
$monthAndDayFormat = (string)trans('config.month_and_day');
|
||||
$dateTimeFormat = (string)trans('config.date_time');
|
||||
$monthAndDayFormat = (string) trans('config.month_and_day');
|
||||
$dateTimeFormat = (string) trans('config.date_time');
|
||||
$defaultCurrency = app('amount')->getDefaultCurrency();
|
||||
|
||||
// also format for moment JS:
|
||||
$madMomentJS = (string)trans('config.month_and_day_moment_js');
|
||||
$madMomentJS = (string) trans('config.month_and_day_moment_js');
|
||||
|
||||
app('view')->share('madMomentJS', $madMomentJS);
|
||||
app('view')->share('monthAndDayFormat', $monthAndDayFormat);
|
||||
|
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
/**
|
||||
@@ -35,9 +36,9 @@ class RedirectIfAuthenticated
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
* @param Request $request
|
||||
* @param Closure $next
|
||||
* @param string|null $guard
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
|
@@ -39,16 +39,16 @@ class Sandstorm
|
||||
* Detects if is using Sandstorm, and responds by logging the user
|
||||
* in and/or creating an account.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
* @param Request $request
|
||||
* @param Closure $next
|
||||
* @param string|null $guard
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, $guard = null)
|
||||
{
|
||||
// is in Sandstorm environment?
|
||||
$sandstorm = 1 === (int)getenv('SANDSTORM');
|
||||
$sandstorm = 1 === (int) getenv('SANDSTORM');
|
||||
app('view')->share('SANDSTORM', $sandstorm);
|
||||
if (!$sandstorm) {
|
||||
return $next($request);
|
||||
@@ -58,7 +58,7 @@ class Sandstorm
|
||||
if (Auth::guard($guard)->guest()) {
|
||||
/** @var UserRepositoryInterface $repository */
|
||||
$repository = app(UserRepositoryInterface::class);
|
||||
$userId = (string)$request->header('X-Sandstorm-User-Id');
|
||||
$userId = (string) $request->header('X-Sandstorm-User-Id');
|
||||
|
||||
// catch anonymous:
|
||||
$userId = '' === $userId ? 'anonymous' : $userId;
|
||||
|
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
@@ -35,11 +36,11 @@ class SecureHeaders
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param Request $request
|
||||
* @param Closure $next
|
||||
*
|
||||
* @throws Exception
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
@@ -105,8 +106,8 @@ class SecureHeaders
|
||||
*/
|
||||
private function getTrackingScriptSource(): string
|
||||
{
|
||||
if ('' !== (string)config('firefly.tracker_site_id') && '' !== (string)config('firefly.tracker_url')) {
|
||||
return (string)config('firefly.tracker_url');
|
||||
if ('' !== (string) config('firefly.tracker_site_id') && '' !== (string) config('firefly.tracker_url')) {
|
||||
return (string) config('firefly.tracker_url');
|
||||
}
|
||||
|
||||
return '';
|
||||
|
@@ -22,6 +22,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Middleware;
|
||||
|
||||
use Illuminate\Contracts\Session\Session;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Session\Middleware\StartSession;
|
||||
use Log;
|
||||
@@ -36,8 +37,8 @@ class StartFireflySession extends StartSession
|
||||
/**
|
||||
* Store the current URL for the request if necessary.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Illuminate\Contracts\Session\Session $session
|
||||
* @param Request $request
|
||||
* @param Session $session
|
||||
*/
|
||||
protected function storeCurrentUrl(Request $request, $session): void
|
||||
{
|
||||
@@ -45,12 +46,13 @@ class StartFireflySession extends StartSession
|
||||
$isScriptPage = strpos($uri, 'jscript');
|
||||
$isDeletePage = strpos($uri, 'delete');
|
||||
$isLoginPage = strpos($uri, '/login');
|
||||
$isJsonPage = strpos($uri, '/json');
|
||||
$isJsonPage = strpos($uri, '/json');
|
||||
|
||||
// also stop remembering "delete" URL's.
|
||||
|
||||
if (false === $isScriptPage && false === $isDeletePage
|
||||
&& false === $isLoginPage && false === $isJsonPage
|
||||
&& false === $isLoginPage
|
||||
&& false === $isJsonPage
|
||||
&& 'GET' === $request->method()
|
||||
&& !$request->ajax()) {
|
||||
$session->setPreviousUrl($uri);
|
||||
|
@@ -43,7 +43,7 @@ class TrustProxies extends Middleware
|
||||
*/
|
||||
public function __construct(Repository $config)
|
||||
{
|
||||
$trustedProxies = (string)config('firefly.trusted_proxies');
|
||||
$trustedProxies = (string) config('firefly.trusted_proxies');
|
||||
$this->proxies = explode(',', $trustedProxies);
|
||||
if ('**' === $trustedProxies) {
|
||||
$this->proxies = '**';
|
||||
|
Reference in New Issue
Block a user