mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +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 Request $request
|
||||
* @param Closure $next
|
||||
* @param string[] ...$guards
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws AuthenticationException
|
||||
* @throws FireflyException
|
||||
* @return mixed
|
||||
*
|
||||
*/
|
||||
public function handle($request, Closure $next, ...$guards)
|
||||
{
|
||||
@@ -80,9 +81,9 @@ class Authenticate
|
||||
* @param $request
|
||||
* @param array $guards
|
||||
*
|
||||
* @return mixed
|
||||
* @throws AuthenticationException
|
||||
* @throws FireflyException
|
||||
* @return mixed
|
||||
*/
|
||||
protected function authenticate($request, array $guards)
|
||||
{
|
||||
|
@@ -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,10 +41,10 @@ class InstallationId
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param Closure $next
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws FireflyException
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
|
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -150,7 +149,9 @@ class Installer
|
||||
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
|
||||
)
|
||||
);
|
||||
|
||||
@@ -174,7 +175,9 @@ class Installer
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -39,7 +39,7 @@ class InterestingMessage
|
||||
* Flashes the user an interesting message if the URL parameters warrant it.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param \Closure $next
|
||||
* @param Closure $next
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
|
@@ -36,8 +36,8 @@ class IsAdmin
|
||||
/**
|
||||
* Handle an incoming request. Must be admin.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @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
|
||||
*/
|
||||
|
@@ -35,8 +35,8 @@ 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 Request $request
|
||||
* @param Closure $next
|
||||
* @param string|null $guard
|
||||
*
|
||||
* @return mixed
|
||||
|
@@ -36,7 +36,7 @@ class Range
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param Request $request
|
||||
* @param Closure $next
|
||||
*
|
||||
* @return mixed
|
||||
|
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
/**
|
||||
@@ -35,8 +36,8 @@ class RedirectIfAuthenticated
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param Request $request
|
||||
* @param Closure $next
|
||||
* @param string|null $guard
|
||||
*
|
||||
* @return mixed
|
||||
|
@@ -39,8 +39,8 @@ 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 Request $request
|
||||
* @param Closure $next
|
||||
* @param string|null $guard
|
||||
*
|
||||
* @return mixed
|
||||
|
@@ -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)
|
||||
{
|
||||
|
@@ -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
|
||||
{
|
||||
@@ -50,7 +51,8 @@ class StartFireflySession extends StartSession
|
||||
// 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);
|
||||
|
@@ -53,9 +53,9 @@ class RecurrenceFormRequest extends Request
|
||||
/**
|
||||
* Get the data required by the controller.
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAll(): array
|
||||
{
|
||||
@@ -136,9 +136,9 @@ class RecurrenceFormRequest extends Request
|
||||
/**
|
||||
* The rules for this request.
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
|
@@ -118,34 +118,6 @@ class ReportFormRequest extends Request
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate end date.
|
||||
*
|
||||
* @return Carbon
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function getEndDate(): Carbon
|
||||
{
|
||||
$date = new Carbon;
|
||||
$range = $this->get('daterange');
|
||||
$parts = explode(' - ', (string)$range);
|
||||
if (2 === count($parts)) {
|
||||
try {
|
||||
$date = new Carbon($parts[1]);
|
||||
// @codeCoverageIgnoreStart
|
||||
} catch (Exception $e) {
|
||||
$error = sprintf('"%s" is not a valid date range: %s', $range, $e->getMessage());
|
||||
Log::error($error);
|
||||
throw new FireflyException($error);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate list of accounts which exist twice in system.
|
||||
*
|
||||
@@ -170,11 +142,39 @@ class ReportFormRequest extends Request
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate start date.
|
||||
*
|
||||
* @return Carbon
|
||||
* Validate end date.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return Carbon
|
||||
*
|
||||
*/
|
||||
public function getEndDate(): Carbon
|
||||
{
|
||||
$date = new Carbon;
|
||||
$range = $this->get('daterange');
|
||||
$parts = explode(' - ', (string) $range);
|
||||
if (2 === count($parts)) {
|
||||
try {
|
||||
$date = new Carbon($parts[1]);
|
||||
// @codeCoverageIgnoreStart
|
||||
} catch (Exception $e) {
|
||||
$error = sprintf('"%s" is not a valid date range: %s', $range, $e->getMessage());
|
||||
Log::error($error);
|
||||
throw new FireflyException($error);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate start date.
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return Carbon
|
||||
*
|
||||
*/
|
||||
public function getStartDate(): Carbon
|
||||
{
|
||||
|
@@ -158,6 +158,36 @@ class Request extends FormRequest
|
||||
return (int) $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return string value, but keep newlines.
|
||||
*
|
||||
* @param string $field
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function nlString(string $field): string
|
||||
{
|
||||
return app('steam')->nlCleanString((string) ($this->get($field) ?? ''));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse and clean a string, but keep the newlines.
|
||||
*
|
||||
* @param string|null $string
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function nlStringFromValue(?string $string): ?string
|
||||
{
|
||||
if (null === $string) {
|
||||
return null;
|
||||
}
|
||||
$result = app('steam')->nlCleanString($string);
|
||||
|
||||
return '' === $result ? null : $result;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return integer value, or NULL when it's not set.
|
||||
*
|
||||
@@ -179,6 +209,22 @@ class Request extends FormRequest
|
||||
return (int) $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return string value, but keep newlines, or NULL if empty.
|
||||
*
|
||||
* @param string $field
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function nullableNlString(string $field): ?string
|
||||
{
|
||||
if (!$this->has($field)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return app('steam')->nlCleanString((string) ($this->get($field) ?? ''));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return string value, or NULL if empty.
|
||||
*
|
||||
@@ -211,34 +257,6 @@ class Request extends FormRequest
|
||||
return app('steam')->cleanString((string) ($this->get($field) ?? ''));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return string value, but keep newlines.
|
||||
*
|
||||
* @param string $field
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function nlString(string $field): string
|
||||
{
|
||||
return app('steam')->nlCleanString((string)($this->get($field) ?? ''));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return string value, but keep newlines, or NULL if empty.
|
||||
*
|
||||
* @param string $field
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function nullableNlString(string $field): ?string
|
||||
{
|
||||
if (!$this->has($field)) {
|
||||
return null;
|
||||
}
|
||||
return app('steam')->nlCleanString((string)($this->get($field) ?? ''));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse and clean a string.
|
||||
*
|
||||
@@ -257,80 +275,6 @@ class Request extends FormRequest
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse and clean a string, but keep the newlines.
|
||||
*
|
||||
* @param string|null $string
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function nlStringFromValue(?string $string): ?string
|
||||
{
|
||||
if (null === $string) {
|
||||
return null;
|
||||
}
|
||||
$result = app('steam')->nlCleanString($string);
|
||||
|
||||
return '' === $result ? null : $result;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return date or NULL.
|
||||
*
|
||||
* @param string $field
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
protected function date(string $field): ?Carbon
|
||||
{
|
||||
$result = null;
|
||||
try {
|
||||
$result = $this->get($field) ? new Carbon($this->get($field)) : null;
|
||||
} catch (Exception $e) {
|
||||
Log::debug(sprintf('Exception when parsing date. Not interesting: %s', $e->getMessage()));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return date time or NULL.
|
||||
*
|
||||
* @param string $field
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
protected function dateTime(string $field): ?Carbon
|
||||
{
|
||||
if (null === $this->get($field)) {
|
||||
return null;
|
||||
}
|
||||
$value = (string)$this->get($field);
|
||||
if (10 === strlen($value)) {
|
||||
// probably a date format.
|
||||
try {
|
||||
$result = Carbon::createFromFormat('Y-m-d', $value);
|
||||
} catch (InvalidDateException $e) {
|
||||
Log::error(sprintf('"%s" is not a valid date: %s', $value, $e->getMessage()));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
// is an atom string, I hope?
|
||||
try {
|
||||
$result = Carbon::parse($value);
|
||||
} catch (InvalidDateException $e) {
|
||||
Log::error(sprintf('"%s" is not a valid date or time: %s', $value, $e->getMessage()));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the submitted Request data and add new or updated Location data to the array.
|
||||
*
|
||||
@@ -389,6 +333,61 @@ class Request extends FormRequest
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return date or NULL.
|
||||
*
|
||||
* @param string $field
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
protected function date(string $field): ?Carbon
|
||||
{
|
||||
$result = null;
|
||||
try {
|
||||
$result = $this->get($field) ? new Carbon($this->get($field)) : null;
|
||||
} catch (Exception $e) {
|
||||
Log::debug(sprintf('Exception when parsing date. Not interesting: %s', $e->getMessage()));
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return date time or NULL.
|
||||
*
|
||||
* @param string $field
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
protected function dateTime(string $field): ?Carbon
|
||||
{
|
||||
if (null === $this->get($field)) {
|
||||
return null;
|
||||
}
|
||||
$value = (string) $this->get($field);
|
||||
if (10 === strlen($value)) {
|
||||
// probably a date format.
|
||||
try {
|
||||
$result = Carbon::createFromFormat('Y-m-d', $value);
|
||||
} catch (InvalidDateException $e) {
|
||||
Log::error(sprintf('"%s" is not a valid date: %s', $value, $e->getMessage()));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
// is an atom string, I hope?
|
||||
try {
|
||||
$result = Carbon::parse($value);
|
||||
} catch (InvalidDateException $e) {
|
||||
Log::error(sprintf('"%s" is not a valid date or time: %s', $value, $e->getMessage()));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Validator $validator
|
||||
|
@@ -53,6 +53,7 @@ class TagFormRequest extends Request
|
||||
'date' => $this->date('date'),
|
||||
'description' => $this->string('description'),
|
||||
];
|
||||
|
||||
return $this->appendLocationData($data, 'location');
|
||||
|
||||
}
|
||||
@@ -80,6 +81,7 @@ class TagFormRequest extends Request
|
||||
'description' => 'min:1|nullable',
|
||||
'date' => 'date|nullable',
|
||||
];
|
||||
|
||||
return Location::requestRules($rules);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user