Apply Pint fixes

This commit is contained in:
Bubka 2023-12-20 16:55:58 +01:00
parent 71840b000a
commit ecd905c36c
36 changed files with 141 additions and 160 deletions

View File

@ -152,7 +152,7 @@ public function reorder(TwoFAccountReorderRequest $request)
return response()->json([
'message' => 'order saved',
'orderedIds' => $orderedIds
'orderedIds' => $orderedIds,
], 200);
}

View File

@ -1,6 +1,5 @@
<?php
/**
*
* The MIT License (MIT)
* Copyright (c) 2023 Bubka
* Copyright (c) 2018 Phan An (https://github.com/koel/koel/blob/master/app/Console/Commands/InitCommand.php)
@ -26,14 +25,10 @@
use Exception;
use Illuminate\Console\Command;
use Illuminate\Console\ConfirmableTrait;
use Illuminate\Database\Connection;
use Illuminate\Database\Migrations\Migrator;
use Illuminate\Database\SQLiteDatabaseDoesNotExistException;
use Illuminate\Encryption\Encrypter;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Jackiedo\DotenvEditor\DotenvEditor;
use PDOException;
use Throwable;
class Install extends Command
@ -64,13 +59,11 @@ class Install extends Command
/**
* Create a new command instance.
*
* @param \Jackiedo\DotenvEditor\DotenvEditor $dotenvEditor
* @return void
*/
public function __construct(
protected DotenvEditor $dotenvEditor,
)
{
) {
parent::__construct();
}
@ -201,7 +194,6 @@ protected function setMainEnvVars() : void
$this->dotenvEditor->setKey('APP_URL', $appUrl);
}
/**
* Prompt user for valid database credentials and set them to .env file.
*/

View File

@ -4,7 +4,6 @@
use App\Models\TwoFAccount;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Schema;
/**
* @codeCoverageIgnore

View File

@ -13,7 +13,7 @@ class WebauthnCredentialBroker extends PasswordBroker
/**
* Send a password reset link to a user.
*/
public function sendResetLink(array $credentials, Closure $callback = null) : string
public function sendResetLink(array $credentials, ?Closure $callback = null) : string
{
/**
* @var \App\Models\User

View File

@ -16,7 +16,6 @@ public static function cleanVersionNumber(?string $release) : string|false
/**
* Format a string to comply with Base32 format
*
* @param string $str
* @return string The filename
*/
public static function PadToBase32Format(?string $str) : string

View File

@ -55,11 +55,9 @@ public function callback(Request $request, string $driver)
if (! $user->exists) {
if (User::where('email', $socialiteEmail)->exists()) {
return redirect('/error?err=sso_email_already_used');
}
else if (User::count() === 0) {
} elseif (User::count() === 0) {
$user->is_admin = true;
}
else if (Settings::get('disableRegistration')) {
} elseif (Settings::get('disableRegistration')) {
return redirect('/error?err=sso_no_register');
}
$user->password = bcrypt(Str::random());

View File

@ -56,7 +56,7 @@
*/
class TwoFAccount extends Model implements Sortable
{
use SortableTrait, HasFactory;
use HasFactory, SortableTrait;
const TOTP = 'totp';
@ -634,7 +634,7 @@ public function setIcon($data, $extension = null) : void
* @param string $extension The file extension, without the dot
* @return string|null The filename of the stored icon or null if the operation fails
*/
private function storeFileDataAsIcon($content, $extension) : string|null
private function storeFileDataAsIcon($content, $extension) : ?string
{
$filename = self::getUniqueFilename($extension);
@ -684,7 +684,7 @@ private function isValidIcon($filename, $disk) : bool
*
* @return string|null The filename of the stored icon or null if the operation fails
*/
private function storeRemoteImageAsIcon(string $url) : string|null
private function storeRemoteImageAsIcon(string $url) : ?string
{
try {
$path_parts = pathinfo($url);

View File

@ -40,8 +40,8 @@
*/
class User extends Authenticatable implements WebAuthnAuthenticatable
{
use WebAuthnAuthentication, WebAuthnManageCredentials;
use HasApiTokens, HasFactory, Notifiable;
use WebAuthnAuthentication, WebAuthnManageCredentials;
/**
* The attributes that are mass assignable.
@ -49,7 +49,7 @@ class User extends Authenticatable implements WebAuthnAuthenticatable
* @var string[]
*/
protected $fillable = [
'name', 'email', 'password', 'oauth_id', 'oauth_provider'
'name', 'email', 'password', 'oauth_id', 'oauth_provider',
];
/**

View File

@ -8,9 +8,9 @@
use App\Events\TwoFAccountDeleted;
use App\Listeners\CleanIconStorage;
use App\Listeners\DissociateTwofaccountFromGroup;
use App\Listeners\RegisterOpenId;
use App\Listeners\ReleaseRadar;
use App\Listeners\ResetUsersPreference;
use App\Listeners\RegisterOpenId;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;

View File

@ -14,8 +14,6 @@ class MigrationServiceProvider extends ServiceProvider
{
/**
* Register services.
*
* @return void
*/
public function register() : void
{

View File

@ -3,10 +3,8 @@
namespace App\Providers\Socialite;
use GuzzleHttp\RequestOptions;
use InvalidArgumentException;
use SocialiteProviders\Manager\OAuth2\AbstractProvider;
use SocialiteProviders\Manager\OAuth2\User;
use SocialiteProviders\Manager\SocialiteWasCalled;
class OpenId extends AbstractProvider
{

View File

@ -19,7 +19,7 @@ class GroupService
*
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public static function assign($ids, User $user, Group $group = null) : void
public static function assign($ids, User $user, ?Group $group = null) : void
{
if (! $group) {
$group = self::defaultGroup($user);
@ -64,7 +64,6 @@ public static function prependTheAllGroup(Collection $groups, User $user) : Coll
* Set owner of given groups
*
* @param Collection<int, Group> $groups
* @param \App\Models\User $user
*/
public static function setUser(Collection $groups, User $user) : void
{

View File

@ -63,7 +63,7 @@ protected static function newRelease() : string|null|false
/**
* Fetch releases on Github
*/
protected static function getLatestReleaseData() : string|null
protected static function getLatestReleaseData() : ?string
{
$url = config('2fauth.latestReleaseUrl');

View File

@ -215,6 +215,7 @@ private function updateRecords(bool $encrypted) : bool
$item->secret = $encrypted ? Crypt::encryptString($item->secret) : Crypt::decryptString($item->secret);
} catch (Exception $ex) {
$success = false;
// Exit the each iteration
return false;
}

View File

@ -98,7 +98,6 @@ public static function delete($ids) : int
* Set owner of given twofaccounts
*
* @param \Illuminate\Support\Collection<int, TwoFAccount> $twofaccounts
* @param \App\Models\User $user
*/
public static function setUser(Collection $twofaccounts, User $user) : void
{

View File

@ -18,11 +18,11 @@
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\Classes\LocalFile;
use Tests\Data\MigrationTestData;
use Tests\Data\OtpTestData;
use Tests\FeatureTestCase;
use PHPUnit\Framework\Attributes\DataProvider;
/**
* TwoFAccountControllerTest test class

View File

@ -53,7 +53,6 @@ public function setUp() : void
'oauth_provider' => self::USER_OAUTH_PROVIDER,
]);
$this->socialiteUser = new \Laravel\Socialite\Two\User;
$this->socialiteUser->id = self::USER_OAUTH_ID;
$this->socialiteUser->name = self::USER_NAME;
@ -293,5 +292,4 @@ public function test_callback_skips_registration_when_registrations_are_closed()
'oauth_provider' => self::USER_OAUTH_PROVIDER,
]);
}
}

View File

@ -79,7 +79,7 @@ protected function runConfigurationAssertions(
* - `getForeignKey()`: any `HasOneOrMany` or `BelongsTo` relation, but key type differs (see documentaiton).
* - `getQualifiedParentKeyName()`: in case of `HasOneOrMany` relation, there is no `getLocalKey()` method, so this one should be asserted.
*/
protected function assertHasManyRelation($relation, Model $model, Model $related, $key = null, $parent = null, \Closure $queryCheck = null)
protected function assertHasManyRelation($relation, Model $model, Model $related, $key = null, $parent = null, ?\Closure $queryCheck = null)
{
$this->assertInstanceOf(HasMany::class, $relation);
@ -111,7 +111,7 @@ protected function assertHasManyRelation($relation, Model $model, Model $related
* - `getForeignKey()`: any `HasOneOrMany` or `BelongsTo` relation, but key type differs (see documentaiton).
* - `getOwnerKey()`: `BelongsTo` relation and its extendings.
*/
protected function assertBelongsToRelation($relation, Model $model, Model $related, $key, $owner = null, \Closure $queryCheck = null)
protected function assertBelongsToRelation($relation, Model $model, Model $related, $key, $owner = null, ?\Closure $queryCheck = null)
{
$this->assertInstanceOf(BelongsTo::class, $relation);