Apply Laravel Pint fixes

This commit is contained in:
Bubka 2022-12-09 10:55:11 +01:00
parent 05a39b6501
commit 65c4bbc496
11 changed files with 50 additions and 85 deletions

View File

@ -16,11 +16,11 @@ class WebauthnCredentialBroker extends PasswordBroker
* @param \Closure|null $callback * @param \Closure|null $callback
* @return string * @return string
*/ */
public function sendResetLink(array $credentials, Closure $callback = null) : string public function sendResetLink(array $credentials, Closure $callback = null): string
{ {
$user = $this->getUser($credentials); $user = $this->getUser($credentials);
if (! $user instanceof WebAuthnAuthenticatable) { if (!$user instanceof WebAuthnAuthenticatable) {
return static::INVALID_USER; return static::INVALID_USER;
} }
@ -50,7 +50,7 @@ class WebauthnCredentialBroker extends PasswordBroker
{ {
$user = $this->validateReset($credentials); $user = $this->validateReset($credentials);
if (! $user instanceof CanResetPasswordContract || ! $user instanceof WebAuthnAuthenticatable) { if (!$user instanceof CanResetPasswordContract || !$user instanceof WebAuthnAuthenticatable) {
return $user; return $user;
} }

View File

@ -12,7 +12,7 @@ class Helpers
* @param string $extension * @param string $extension
* @return string The filename * @return string The filename
*/ */
public static function getUniqueFilename(string $extension) : string public static function getUniqueFilename(string $extension): string
{ {
return Str::random(40) . '.' . $extension; return Str::random(40) . '.' . $extension;
} }
@ -23,7 +23,7 @@ class Helpers
* @param string|null $release * @param string|null $release
* @return string|false * @return string|false
*/ */
public static function cleanVersionNumber(?string $release) : string|false public static function cleanVersionNumber(?string $release): string|false
{ {
// We use the regex for semver detection (see https://semver.org/) // We use the regex for semver detection (see https://semver.org/)
return preg_match('/(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?/', $release, $version) ? $version[0] : false; return preg_match('/(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?/', $release, $version) ? $version[0] : false;

View File

@ -1,30 +0,0 @@
<?php
// namespace App\Http\Controllers\Auth;
// use App\Http\Controllers\Controller;
// use App\Providers\RouteServiceProvider;
// // use DarkGhostHunter\Larapass\Http\ConfirmsWebAuthn;
// class WebAuthnConfirmController extends Controller
// {
// // use ConfirmsWebAuthn;
// /*
// |--------------------------------------------------------------------------
// | Confirm Device Controller
// |--------------------------------------------------------------------------
// |
// | This controller is responsible for handling WebAuthn confirmations and
// | uses a simple trait to include the behavior. You're free to explore
// | this trait and override any functions that require customization.
// |
// */
// /**
// * Where to redirect users when the intended url fails.
// *
// * @var string
// */
// protected $redirectTo = RouteServiceProvider::HOME;
// }

View File

@ -39,19 +39,13 @@ class WebAuthnDeviceLostController extends Controller
* *
* @param \Illuminate\Http\Request $request * @param \Illuminate\Http\Request $request
* @param string $response * @param string $response
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse * @return \Illuminate\Http\JsonResponse
* *
* @throws \Illuminate\Validation\ValidationException * @throws \Illuminate\Validation\ValidationException
*/ */
protected function sendRecoveryLinkFailedResponse(Request $request, string $response) protected function sendRecoveryLinkFailedResponse(Request $request, string $response)
{ {
if ($request->wantsJson()) { throw ValidationException::withMessages(['email' => [trans($response)]]);
throw ValidationException::withMessages(['email' => [trans($response)]]);
}
return back()
->withInput($request->only('email'))
->withErrors(['email' => trans($response)]);
} }
/** /**
@ -59,7 +53,7 @@ class WebAuthnDeviceLostController extends Controller
* *
* @param \Illuminate\Http\Request $request * @param \Illuminate\Http\Request $request
* @param string $response * @param string $response
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse * @return \Illuminate\Http\JsonResponse
*/ */
protected function sendRecoveryLinkResponse(Request $request, string $response) protected function sendRecoveryLinkResponse(Request $request, string $response)
{ {

View File

@ -32,7 +32,7 @@ class WebAuthnLoginController extends Controller
* @param \Laragear\WebAuthn\Http\Requests\AssertionRequest $request * @param \Laragear\WebAuthn\Http\Requests\AssertionRequest $request
* @return \Illuminate\Contracts\Support\Responsable|\Illuminate\Http\JsonResponse * @return \Illuminate\Contracts\Support\Responsable|\Illuminate\Http\JsonResponse
*/ */
public function options(AssertionRequest $request) : Responsable|JsonResponse public function options(AssertionRequest $request): Responsable|JsonResponse
{ {
switch (config('webauthn.user_verification')) { switch (config('webauthn.user_verification')) {
case WebAuthn::USER_VERIFICATION_DISCOURAGED: case WebAuthn::USER_VERIFICATION_DISCOURAGED:

View File

@ -17,7 +17,7 @@ class WebAuthnRegisterController extends Controller
* @param \Laragear\WebAuthn\Http\Requests\AttestationRequest $request * @param \Laragear\WebAuthn\Http\Requests\AttestationRequest $request
* @return \Illuminate\Contracts\Support\Responsable * @return \Illuminate\Contracts\Support\Responsable
*/ */
public function options(AttestationRequest $request) : Responsable public function options(AttestationRequest $request): Responsable
{ {
switch (config('webauthn.user_verification')) { switch (config('webauthn.user_verification')) {
case WebAuthn::USER_VERIFICATION_DISCOURAGED: case WebAuthn::USER_VERIFICATION_DISCOURAGED:
@ -40,7 +40,7 @@ class WebAuthnRegisterController extends Controller
* @param \Laragear\WebAuthn\Http\Requests\AttestedRequest $request * @param \Laragear\WebAuthn\Http\Requests\AttestedRequest $request
* @return \Illuminate\Http\Response * @return \Illuminate\Http\Response
*/ */
public function register(AttestedRequest $request) : Response public function register(AttestedRequest $request): Response
{ {
$request->save(); $request->save();

View File

@ -142,13 +142,13 @@ class TwoFAccount extends Model implements Sortable
parent::boot(); parent::boot();
static::saving(function (TwoFAccount $twofaccount) { static::saving(function (TwoFAccount $twofaccount) {
if (! $twofaccount->legacy_uri) { if (!$twofaccount->legacy_uri) {
$twofaccount->legacy_uri = $twofaccount->getURI(); $twofaccount->legacy_uri = $twofaccount->getURI();
} }
if ($twofaccount->otp_type == TwoFAccount::TOTP && ! $twofaccount->period) { if ($twofaccount->otp_type == TwoFAccount::TOTP && !$twofaccount->period) {
$twofaccount->period = TwoFAccount::DEFAULT_PERIOD; $twofaccount->period = TwoFAccount::DEFAULT_PERIOD;
} }
if ($twofaccount->otp_type == TwoFAccount::HOTP && ! $twofaccount->counter) { if ($twofaccount->otp_type == TwoFAccount::HOTP && !$twofaccount->counter) {
$twofaccount->counter = TwoFAccount::DEFAULT_COUNTER; $twofaccount->counter = TwoFAccount::DEFAULT_COUNTER;
} }
}); });
@ -253,7 +253,7 @@ class TwoFAccount extends Model implements Sortable
*/ */
public function setDigitsAttribute($value) public function setDigitsAttribute($value)
{ {
$this->attributes['digits'] = ! $value ? 6 : $value; $this->attributes['digits'] = !$value ? 6 : $value;
} }
/** /**
@ -264,7 +264,7 @@ class TwoFAccount extends Model implements Sortable
*/ */
public function setAlgorithmAttribute($value) public function setAlgorithmAttribute($value)
{ {
$this->attributes['algorithm'] = ! $value ? self::SHA1 : strtolower($value); $this->attributes['algorithm'] = !$value ? self::SHA1 : strtolower($value);
} }
/** /**
@ -275,7 +275,7 @@ class TwoFAccount extends Model implements Sortable
*/ */
public function setPeriodAttribute($value) public function setPeriodAttribute($value)
{ {
$this->attributes['period'] = ! $value && $this->otp_type === self::TOTP ? self::DEFAULT_PERIOD : $value; $this->attributes['period'] = !$value && $this->otp_type === self::TOTP ? self::DEFAULT_PERIOD : $value;
} }
/** /**
@ -329,15 +329,15 @@ class TwoFAccount extends Model implements Sortable
$OtpDto->otp_type = $this->otp_type; $OtpDto->otp_type = $this->otp_type;
$OtpDto->generated_at = time(); $OtpDto->generated_at = time();
$OtpDto->password = $this->otp_type === self::TOTP $OtpDto->password = $this->otp_type === self::TOTP
? $this->generator->at($OtpDto->generated_at) ? $this->generator->at($OtpDto->generated_at)
: SteamTotp::getAuthCode(base64_encode(Base32::decodeUpper($this->secret))); : SteamTotp::getAuthCode(base64_encode(Base32::decodeUpper($this->secret)));
$OtpDto->period = $this->period; $OtpDto->period = $this->period;
} }
Log::info(sprintf('New OTP generated for TwoFAccount (%s)', $this->id ? 'id:' . $this->id : 'preview')); Log::info(sprintf('New OTP generated for TwoFAccount (%s)', $this->id ? 'id:' . $this->id : 'preview'));
return $OtpDto; return $OtpDto;
} catch (\Exception|\Throwable $ex) { } catch (\Exception | \Throwable $ex) {
Log::error('An error occured, OTP generation aborted'); Log::error('An error occured, OTP generation aborted');
// Currently a secret issue is the only possible exception thrown by OTPHP for this stack // Currently a secret issue is the only possible exception thrown by OTPHP for this stack
// so it is Ok to send the corresponding 2FAuth exception. // so it is Ok to send the corresponding 2FAuth exception.
@ -374,7 +374,7 @@ class TwoFAccount extends Model implements Sortable
$this->enforceAsSteam(); $this->enforceAsSteam();
} }
if (! $this->icon && Settings::get('getOfficialIcons') && ! $skipIconFetching) { if (!$this->icon && Settings::get('getOfficialIcons') && !$skipIconFetching) {
$this->icon = $this->getDefaultIcon(); $this->icon = $this->getDefaultIcon();
} }
@ -393,7 +393,7 @@ class TwoFAccount extends Model implements Sortable
// First we instanciate the OTP generator // First we instanciate the OTP generator
try { try {
$this->generator = Factory::loadFromProvisioningUri($uri); $this->generator = Factory::loadFromProvisioningUri($uri);
} catch (\Assert\AssertionFailedException|\Assert\InvalidArgumentException|\Exception|\Throwable $ex) { } catch (\Assert\AssertionFailedException | \Assert\InvalidArgumentException | \Exception | \Throwable $ex) {
throw ValidationException::withMessages([ throw ValidationException::withMessages([
'uri' => __('validation.custom.uri.regex', ['attribute' => 'uri']), 'uri' => __('validation.custom.uri.regex', ['attribute' => 'uri']),
]); ]);
@ -401,7 +401,7 @@ class TwoFAccount extends Model implements Sortable
// As loadFromProvisioningUri() accept URI without label (nor account nor service) we check // As loadFromProvisioningUri() accept URI without label (nor account nor service) we check
// that the account is set // that the account is set
if (! $this->generator->getLabel()) { if (!$this->generator->getLabel()) {
Log::error('URI passed to fillWithURI() must contain a label'); Log::error('URI passed to fillWithURI() must contain a label');
throw ValidationException::withMessages([ throw ValidationException::withMessages([
@ -426,7 +426,7 @@ class TwoFAccount extends Model implements Sortable
$this->icon = $this->storeImageAsIcon($this->generator->getParameter('image')); $this->icon = $this->storeImageAsIcon($this->generator->getParameter('image'));
} }
if (! $this->icon && Settings::get('getOfficialIcons') && ! $skipIconFetching) { if (!$this->icon && Settings::get('getOfficialIcons') && !$skipIconFetching) {
$this->icon = $this->getDefaultIcon(); $this->icon = $this->getDefaultIcon();
} }
@ -454,7 +454,7 @@ class TwoFAccount extends Model implements Sortable
/** /**
* Sets model attributes to STEAM values * Sets model attributes to STEAM values
*/ */
private function enforceAsSteam() : void private function enforceAsSteam(): void
{ {
$this->otp_type = self::STEAM_TOTP; $this->otp_type = self::STEAM_TOTP;
$this->digits = 5; $this->digits = 5;
@ -477,7 +477,7 @@ class TwoFAccount extends Model implements Sortable
/** /**
* Returns an otpauth URI built with model attribute values * Returns an otpauth URI built with model attribute values
*/ */
public function getURI() : string public function getURI(): string
{ {
$this->initGenerator(); $this->initGenerator();
@ -490,7 +490,7 @@ class TwoFAccount extends Model implements Sortable
* @throws UnsupportedOtpTypeException The defined OTP type is not supported * @throws UnsupportedOtpTypeException The defined OTP type is not supported
* @throws InvalidOtpParameterException One OTP parameter is invalid * @throws InvalidOtpParameterException One OTP parameter is invalid
*/ */
private function initGenerator() : void private function initGenerator(): void
{ {
try { try {
switch ($this->otp_type) { switch ($this->otp_type) {
@ -529,7 +529,7 @@ class TwoFAccount extends Model implements Sortable
} catch (UnsupportedOtpTypeException $exception) { } catch (UnsupportedOtpTypeException $exception) {
Log::error(sprintf('%s is not an OTP type supported by the current generator', $this->otp_type)); Log::error(sprintf('%s is not an OTP type supported by the current generator', $this->otp_type));
throw $exception; throw $exception;
} catch (\Exception|\Throwable $exception) { } catch (\Exception | \Throwable $exception) {
throw new InvalidOtpParameterException($exception->getMessage()); throw new InvalidOtpParameterException($exception->getMessage());
} }
} }
@ -573,7 +573,7 @@ class TwoFAccount extends Model implements Sortable
return $newFilename; return $newFilename;
} }
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
catch (\Exception|\Throwable $ex) { catch (\Exception | \Throwable $ex) {
Log::error(sprintf('Icon storage failed: %s', $ex->getMessage())); Log::error(sprintf('Icon storage failed: %s', $ex->getMessage()));
return null; return null;
@ -596,7 +596,7 @@ class TwoFAccount extends Model implements Sortable
/** /**
* Returns an acceptable value * Returns an acceptable value
*/ */
private function decryptOrReturn(mixed $value) : mixed private function decryptOrReturn(mixed $value): mixed
{ {
// Decipher when needed // Decipher when needed
if (Settings::get('useEncryption') && $value) { if (Settings::get('useEncryption') && $value) {
@ -613,7 +613,7 @@ class TwoFAccount extends Model implements Sortable
/** /**
* Encrypt a value * Encrypt a value
*/ */
private function encryptOrReturn(mixed $value) : mixed private function encryptOrReturn(mixed $value): mixed
{ {
// should be replaced by laravel 8 attribute encryption casting // should be replaced by laravel 8 attribute encryption casting
return Settings::get('useEncryption') ? Crypt::encryptString($value) : $value; return Settings::get('useEncryption') ? Crypt::encryptString($value) : $value;

View File

@ -60,7 +60,7 @@ class LogoService
$domain = $this->tfas->get($this->cleanDomain(strval($serviceName))); $domain = $this->tfas->get($this->cleanDomain(strval($serviceName)));
$logoFilename = $domain . '.svg'; $logoFilename = $domain . '.svg';
if ($domain && ! Storage::disk('logos')->exists($logoFilename)) { if ($domain && !Storage::disk('logos')->exists($logoFilename)) {
$this->fetchLogo($logoFilename); $this->fetchLogo($logoFilename);
} }
@ -72,7 +72,7 @@ class LogoService
* *
* @return void * @return void
*/ */
protected function setTfaCollection() : void protected function setTfaCollection(): void
{ {
// We fetch a fresh tfaDirectory if necessary to prevent too many API calls // We fetch a fresh tfaDirectory if necessary to prevent too many API calls
if (Storage::disk('logos')->exists(self::TFA_JSON)) { if (Storage::disk('logos')->exists(self::TFA_JSON)) {
@ -93,17 +93,18 @@ class LogoService
* *
* @return void * @return void
*/ */
protected function cacheTfaDirectorySource() : void protected function cacheTfaDirectorySource(): void
{ {
try { try {
$response = Http::retry(3, 100)->get(self::TFA_URL); $response = Http::retry(3, 100)->get(self::TFA_URL);
$coll = collect(json_decode(htmlspecialchars_decode($response->body()), true)) /** @phpstan-ignore-line */ $coll = collect(json_decode(htmlspecialchars_decode($response->body()), true))
->mapWithKeys(function ($item, $key) { /** @phpstan-ignore-line */
return [ ->mapWithKeys(function ($item, $key) {
strtolower(head($item)) => $item[1]['domain'], return [
]; strtolower(head($item)) => $item[1]['domain'],
}); ];
});
Storage::disk('logos')->put(self::TFA_JSON, $coll->toJson()) Storage::disk('logos')->put(self::TFA_JSON, $coll->toJson())
? Log::info('Fresh tfa.json saved to logos dir') ? Log::info('Fresh tfa.json saved to logos dir')
@ -119,7 +120,7 @@ class LogoService
* @param string $logoFile Logo filename to fetch * @param string $logoFile Logo filename to fetch
* @return void * @return void
*/ */
protected function fetchLogo(string $logoFile) : void protected function fetchLogo(string $logoFile): void
{ {
try { try {
$response = Http::retry(3, 100) $response = Http::retry(3, 100)
@ -141,7 +142,7 @@ class LogoService
* @param string $domain * @param string $domain
* @return string Optimized domain name * @return string Optimized domain name
*/ */
protected function cleanDomain(string $domain) : string protected function cleanDomain(string $domain): string
{ {
return strtolower(str_replace(['+'], ['plus'], $domain)); return strtolower(str_replace(['+'], ['plus'], $domain));
} }
@ -153,7 +154,7 @@ class LogoService
* @param string $iconFilename * @param string $iconFilename
* @return bool Weither the copy succed or not * @return bool Weither the copy succed or not
*/ */
protected function copyToIcons($logoFilename, $iconFilename) : bool protected function copyToIcons($logoFilename, $iconFilename): bool
{ {
return Storage::disk('icons')->put($iconFilename, Storage::disk('logos')->get($logoFilename)); return Storage::disk('icons')->put($iconFilename, Storage::disk('logos')->get($logoFilename));
} }

View File

@ -23,7 +23,7 @@ class GoogleAuthMigrator extends Migrator
* @param mixed $migrationPayload migration uri provided by Google Authenticator export feature * @param mixed $migrationPayload migration uri provided by Google Authenticator export feature
* @return \Illuminate\Support\Collection<int|string, \App\Models\TwoFAccount> The converted accounts * @return \Illuminate\Support\Collection<int|string, \App\Models\TwoFAccount> The converted accounts
*/ */
public function migrate(mixed $migrationPayload) : Collection public function migrate(mixed $migrationPayload): Collection
{ {
try { try {
$migrationData = base64_decode(urldecode(Str::replace('otpauth-migration://offline?data=', '', $migrationPayload))); $migrationData = base64_decode(urldecode(Str::replace('otpauth-migration://offline?data=', '', $migrationPayload)));

View File

@ -17,7 +17,7 @@ class PlainTextMigrator extends Migrator
* @param mixed $migrationPayload * @param mixed $migrationPayload
* @return \Illuminate\Support\Collection<int|string, \App\Models\TwoFAccount> The converted accounts * @return \Illuminate\Support\Collection<int|string, \App\Models\TwoFAccount> The converted accounts
*/ */
public function migrate(mixed $migrationPayload) : Collection public function migrate(mixed $migrationPayload): Collection
{ {
$otpauthURIs = preg_split('~\R~', $migrationPayload); $otpauthURIs = preg_split('~\R~', $migrationPayload);
$otpauthURIs = Arr::where($otpauthURIs, function ($value, $key) { $otpauthURIs = Arr::where($otpauthURIs, function ($value, $key) {

View File

@ -14,7 +14,7 @@ class ReleaseRadarService
* *
* @return void * @return void
*/ */
public function scheduledScan() : void public function scheduledScan(): void
{ {
if ((Settings::get('lastRadarScan') + (60 * 60 * 24 * 7)) < time()) { if ((Settings::get('lastRadarScan') + (60 * 60 * 24 * 7)) < time()) {
$this->newRelease(); $this->newRelease();
@ -26,7 +26,7 @@ class ReleaseRadarService
* *
* @return false|string False if no new release, the new release number otherwise * @return false|string False if no new release, the new release number otherwise
*/ */
public function manualScan() : false|string public function manualScan(): false|string
{ {
return $this->newRelease(); return $this->newRelease();
} }
@ -36,7 +36,7 @@ class ReleaseRadarService
* *
* @return false|string False if no new release, the new release number otherwise * @return false|string False if no new release, the new release number otherwise
*/ */
protected function newRelease() : false|string protected function newRelease(): false|string
{ {
if ($latestReleaseData = json_decode($this->getLatestReleaseData())) { if ($latestReleaseData = json_decode($this->getLatestReleaseData())) {
@ -62,7 +62,7 @@ class ReleaseRadarService
* *
* @return string|null * @return string|null
*/ */
protected function getLatestReleaseData() : string|null protected function getLatestReleaseData(): string|null
{ {
try { try {
$response = Http::retry(3, 100) $response = Http::retry(3, 100)