From 65c4bbc49602f68859639b5ca040863f21510017 Mon Sep 17 00:00:00 2001 From: Bubka <858858+Bubka@users.noreply.github.com> Date: Fri, 9 Dec 2022 10:55:11 +0100 Subject: [PATCH] Apply Laravel Pint fixes --- app/Extensions/WebauthnCredentialBroker.php | 6 +-- app/Helpers/Helpers.php | 4 +- .../Auth/WebAuthnConfirmController.php | 30 -------------- .../Auth/WebAuthnDeviceLostController.php | 12 ++---- .../Auth/WebAuthnLoginController.php | 2 +- .../Auth/WebAuthnRegisterController.php | 4 +- app/Models/TwoFAccount.php | 40 +++++++++---------- app/Services/LogoService.php | 25 ++++++------ app/Services/Migrators/GoogleAuthMigrator.php | 2 +- app/Services/Migrators/PlainTextMigrator.php | 2 +- app/Services/ReleaseRadarService.php | 8 ++-- 11 files changed, 50 insertions(+), 85 deletions(-) delete mode 100644 app/Http/Controllers/Auth/WebAuthnConfirmController.php diff --git a/app/Extensions/WebauthnCredentialBroker.php b/app/Extensions/WebauthnCredentialBroker.php index 4b1cc83d..029a4879 100644 --- a/app/Extensions/WebauthnCredentialBroker.php +++ b/app/Extensions/WebauthnCredentialBroker.php @@ -16,11 +16,11 @@ class WebauthnCredentialBroker extends PasswordBroker * @param \Closure|null $callback * @return string */ - public function sendResetLink(array $credentials, Closure $callback = null) : string + public function sendResetLink(array $credentials, Closure $callback = null): string { $user = $this->getUser($credentials); - if (! $user instanceof WebAuthnAuthenticatable) { + if (!$user instanceof WebAuthnAuthenticatable) { return static::INVALID_USER; } @@ -50,7 +50,7 @@ class WebauthnCredentialBroker extends PasswordBroker { $user = $this->validateReset($credentials); - if (! $user instanceof CanResetPasswordContract || ! $user instanceof WebAuthnAuthenticatable) { + if (!$user instanceof CanResetPasswordContract || !$user instanceof WebAuthnAuthenticatable) { return $user; } diff --git a/app/Helpers/Helpers.php b/app/Helpers/Helpers.php index ef5c502f..acd23fc8 100644 --- a/app/Helpers/Helpers.php +++ b/app/Helpers/Helpers.php @@ -12,7 +12,7 @@ class Helpers * @param string $extension * @return string The filename */ - public static function getUniqueFilename(string $extension) : string + public static function getUniqueFilename(string $extension): string { return Str::random(40) . '.' . $extension; } @@ -23,7 +23,7 @@ class Helpers * @param string|null $release * @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/) 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; diff --git a/app/Http/Controllers/Auth/WebAuthnConfirmController.php b/app/Http/Controllers/Auth/WebAuthnConfirmController.php deleted file mode 100644 index 190360ee..00000000 --- a/app/Http/Controllers/Auth/WebAuthnConfirmController.php +++ /dev/null @@ -1,30 +0,0 @@ -wantsJson()) { - throw ValidationException::withMessages(['email' => [trans($response)]]); - } - - return back() - ->withInput($request->only('email')) - ->withErrors(['email' => trans($response)]); + throw ValidationException::withMessages(['email' => [trans($response)]]); } /** @@ -59,7 +53,7 @@ class WebAuthnDeviceLostController extends Controller * * @param \Illuminate\Http\Request $request * @param string $response - * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse + * @return \Illuminate\Http\JsonResponse */ protected function sendRecoveryLinkResponse(Request $request, string $response) { diff --git a/app/Http/Controllers/Auth/WebAuthnLoginController.php b/app/Http/Controllers/Auth/WebAuthnLoginController.php index 9a59406f..72be2922 100644 --- a/app/Http/Controllers/Auth/WebAuthnLoginController.php +++ b/app/Http/Controllers/Auth/WebAuthnLoginController.php @@ -32,7 +32,7 @@ class WebAuthnLoginController extends Controller * @param \Laragear\WebAuthn\Http\Requests\AssertionRequest $request * @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')) { case WebAuthn::USER_VERIFICATION_DISCOURAGED: diff --git a/app/Http/Controllers/Auth/WebAuthnRegisterController.php b/app/Http/Controllers/Auth/WebAuthnRegisterController.php index 5c014ef8..712d6e80 100644 --- a/app/Http/Controllers/Auth/WebAuthnRegisterController.php +++ b/app/Http/Controllers/Auth/WebAuthnRegisterController.php @@ -17,7 +17,7 @@ class WebAuthnRegisterController extends Controller * @param \Laragear\WebAuthn\Http\Requests\AttestationRequest $request * @return \Illuminate\Contracts\Support\Responsable */ - public function options(AttestationRequest $request) : Responsable + public function options(AttestationRequest $request): Responsable { switch (config('webauthn.user_verification')) { case WebAuthn::USER_VERIFICATION_DISCOURAGED: @@ -40,7 +40,7 @@ class WebAuthnRegisterController extends Controller * @param \Laragear\WebAuthn\Http\Requests\AttestedRequest $request * @return \Illuminate\Http\Response */ - public function register(AttestedRequest $request) : Response + public function register(AttestedRequest $request): Response { $request->save(); diff --git a/app/Models/TwoFAccount.php b/app/Models/TwoFAccount.php index 90fcd0c8..7a12361a 100644 --- a/app/Models/TwoFAccount.php +++ b/app/Models/TwoFAccount.php @@ -142,13 +142,13 @@ class TwoFAccount extends Model implements Sortable parent::boot(); static::saving(function (TwoFAccount $twofaccount) { - if (! $twofaccount->legacy_uri) { + if (!$twofaccount->legacy_uri) { $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; } - if ($twofaccount->otp_type == TwoFAccount::HOTP && ! $twofaccount->counter) { + if ($twofaccount->otp_type == TwoFAccount::HOTP && !$twofaccount->counter) { $twofaccount->counter = TwoFAccount::DEFAULT_COUNTER; } }); @@ -253,7 +253,7 @@ class TwoFAccount extends Model implements Sortable */ 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) { - $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) { - $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->generated_at = time(); $OtpDto->password = $this->otp_type === self::TOTP - ? $this->generator->at($OtpDto->generated_at) - : SteamTotp::getAuthCode(base64_encode(Base32::decodeUpper($this->secret))); + ? $this->generator->at($OtpDto->generated_at) + : SteamTotp::getAuthCode(base64_encode(Base32::decodeUpper($this->secret))); $OtpDto->period = $this->period; } Log::info(sprintf('New OTP generated for TwoFAccount (%s)', $this->id ? 'id:' . $this->id : 'preview')); return $OtpDto; - } catch (\Exception|\Throwable $ex) { + } catch (\Exception | \Throwable $ex) { Log::error('An error occured, OTP generation aborted'); // 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. @@ -374,7 +374,7 @@ class TwoFAccount extends Model implements Sortable $this->enforceAsSteam(); } - if (! $this->icon && Settings::get('getOfficialIcons') && ! $skipIconFetching) { + if (!$this->icon && Settings::get('getOfficialIcons') && !$skipIconFetching) { $this->icon = $this->getDefaultIcon(); } @@ -393,7 +393,7 @@ class TwoFAccount extends Model implements Sortable // First we instanciate the OTP generator try { $this->generator = Factory::loadFromProvisioningUri($uri); - } catch (\Assert\AssertionFailedException|\Assert\InvalidArgumentException|\Exception|\Throwable $ex) { + } catch (\Assert\AssertionFailedException | \Assert\InvalidArgumentException | \Exception | \Throwable $ex) { throw ValidationException::withMessages([ '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 // that the account is set - if (! $this->generator->getLabel()) { + if (!$this->generator->getLabel()) { Log::error('URI passed to fillWithURI() must contain a label'); throw ValidationException::withMessages([ @@ -426,7 +426,7 @@ class TwoFAccount extends Model implements Sortable $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(); } @@ -454,7 +454,7 @@ class TwoFAccount extends Model implements Sortable /** * Sets model attributes to STEAM values */ - private function enforceAsSteam() : void + private function enforceAsSteam(): void { $this->otp_type = self::STEAM_TOTP; $this->digits = 5; @@ -477,7 +477,7 @@ class TwoFAccount extends Model implements Sortable /** * Returns an otpauth URI built with model attribute values */ - public function getURI() : string + public function getURI(): string { $this->initGenerator(); @@ -490,7 +490,7 @@ class TwoFAccount extends Model implements Sortable * @throws UnsupportedOtpTypeException The defined OTP type is not supported * @throws InvalidOtpParameterException One OTP parameter is invalid */ - private function initGenerator() : void + private function initGenerator(): void { try { switch ($this->otp_type) { @@ -529,7 +529,7 @@ class TwoFAccount extends Model implements Sortable } catch (UnsupportedOtpTypeException $exception) { Log::error(sprintf('%s is not an OTP type supported by the current generator', $this->otp_type)); throw $exception; - } catch (\Exception|\Throwable $exception) { + } catch (\Exception | \Throwable $exception) { throw new InvalidOtpParameterException($exception->getMessage()); } } @@ -573,7 +573,7 @@ class TwoFAccount extends Model implements Sortable return $newFilename; } // @codeCoverageIgnoreStart - catch (\Exception|\Throwable $ex) { + catch (\Exception | \Throwable $ex) { Log::error(sprintf('Icon storage failed: %s', $ex->getMessage())); return null; @@ -596,7 +596,7 @@ class TwoFAccount extends Model implements Sortable /** * Returns an acceptable value */ - private function decryptOrReturn(mixed $value) : mixed + private function decryptOrReturn(mixed $value): mixed { // Decipher when needed if (Settings::get('useEncryption') && $value) { @@ -613,7 +613,7 @@ class TwoFAccount extends Model implements Sortable /** * Encrypt a value */ - private function encryptOrReturn(mixed $value) : mixed + private function encryptOrReturn(mixed $value): mixed { // should be replaced by laravel 8 attribute encryption casting return Settings::get('useEncryption') ? Crypt::encryptString($value) : $value; diff --git a/app/Services/LogoService.php b/app/Services/LogoService.php index 8ba8a475..40f2ad44 100644 --- a/app/Services/LogoService.php +++ b/app/Services/LogoService.php @@ -60,7 +60,7 @@ class LogoService $domain = $this->tfas->get($this->cleanDomain(strval($serviceName))); $logoFilename = $domain . '.svg'; - if ($domain && ! Storage::disk('logos')->exists($logoFilename)) { + if ($domain && !Storage::disk('logos')->exists($logoFilename)) { $this->fetchLogo($logoFilename); } @@ -72,7 +72,7 @@ class LogoService * * @return void */ - protected function setTfaCollection() : void + protected function setTfaCollection(): void { // We fetch a fresh tfaDirectory if necessary to prevent too many API calls if (Storage::disk('logos')->exists(self::TFA_JSON)) { @@ -93,17 +93,18 @@ class LogoService * * @return void */ - protected function cacheTfaDirectorySource() : void + protected function cacheTfaDirectorySource(): void { try { $response = Http::retry(3, 100)->get(self::TFA_URL); - $coll = collect(json_decode(htmlspecialchars_decode($response->body()), true)) /** @phpstan-ignore-line */ - ->mapWithKeys(function ($item, $key) { - return [ - strtolower(head($item)) => $item[1]['domain'], - ]; - }); + $coll = collect(json_decode(htmlspecialchars_decode($response->body()), true)) + /** @phpstan-ignore-line */ + ->mapWithKeys(function ($item, $key) { + return [ + strtolower(head($item)) => $item[1]['domain'], + ]; + }); Storage::disk('logos')->put(self::TFA_JSON, $coll->toJson()) ? Log::info('Fresh tfa.json saved to logos dir') @@ -119,7 +120,7 @@ class LogoService * @param string $logoFile Logo filename to fetch * @return void */ - protected function fetchLogo(string $logoFile) : void + protected function fetchLogo(string $logoFile): void { try { $response = Http::retry(3, 100) @@ -141,7 +142,7 @@ class LogoService * @param string $domain * @return string Optimized domain name */ - protected function cleanDomain(string $domain) : string + protected function cleanDomain(string $domain): string { return strtolower(str_replace(['+'], ['plus'], $domain)); } @@ -153,7 +154,7 @@ class LogoService * @param string $iconFilename * @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)); } diff --git a/app/Services/Migrators/GoogleAuthMigrator.php b/app/Services/Migrators/GoogleAuthMigrator.php index bdb1f634..e0555dd4 100644 --- a/app/Services/Migrators/GoogleAuthMigrator.php +++ b/app/Services/Migrators/GoogleAuthMigrator.php @@ -23,7 +23,7 @@ class GoogleAuthMigrator extends Migrator * @param mixed $migrationPayload migration uri provided by Google Authenticator export feature * @return \Illuminate\Support\Collection The converted accounts */ - public function migrate(mixed $migrationPayload) : Collection + public function migrate(mixed $migrationPayload): Collection { try { $migrationData = base64_decode(urldecode(Str::replace('otpauth-migration://offline?data=', '', $migrationPayload))); diff --git a/app/Services/Migrators/PlainTextMigrator.php b/app/Services/Migrators/PlainTextMigrator.php index 9dc116f7..20c7b9c8 100644 --- a/app/Services/Migrators/PlainTextMigrator.php +++ b/app/Services/Migrators/PlainTextMigrator.php @@ -17,7 +17,7 @@ class PlainTextMigrator extends Migrator * @param mixed $migrationPayload * @return \Illuminate\Support\Collection The converted accounts */ - public function migrate(mixed $migrationPayload) : Collection + public function migrate(mixed $migrationPayload): Collection { $otpauthURIs = preg_split('~\R~', $migrationPayload); $otpauthURIs = Arr::where($otpauthURIs, function ($value, $key) { diff --git a/app/Services/ReleaseRadarService.php b/app/Services/ReleaseRadarService.php index 17004035..fc9eb9b5 100644 --- a/app/Services/ReleaseRadarService.php +++ b/app/Services/ReleaseRadarService.php @@ -14,7 +14,7 @@ class ReleaseRadarService * * @return void */ - public function scheduledScan() : void + public function scheduledScan(): void { if ((Settings::get('lastRadarScan') + (60 * 60 * 24 * 7)) < time()) { $this->newRelease(); @@ -26,7 +26,7 @@ class ReleaseRadarService * * @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(); } @@ -36,7 +36,7 @@ class ReleaseRadarService * * @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())) { @@ -62,7 +62,7 @@ class ReleaseRadarService * * @return string|null */ - protected function getLatestReleaseData() : string|null + protected function getLatestReleaseData(): string|null { try { $response = Http::retry(3, 100)