mirror of
https://github.com/Bubka/2FAuth.git
synced 2024-11-22 16:23:18 +01:00
Fix phpstan & pint issues
This commit is contained in:
parent
e7f542816d
commit
f823f69dd2
@ -130,9 +130,9 @@ public function revokePATs(Request $request, User $user, TokenRepository $tokenR
|
||||
$tokens = $tokenRepository->forUser($user->getAuthIdentifier());
|
||||
|
||||
$tokens->load('client')->filter(function ($token) {
|
||||
return $token->client->personal_access_client && ! $token->revoked;
|
||||
return $token->client->personal_access_client && ! $token->revoked; /** @phpstan-ignore-line */
|
||||
})->each(function ($token) {
|
||||
$token->revoke();
|
||||
$token->revoke(); /** @phpstan-ignore-line */
|
||||
});
|
||||
|
||||
Log::info(sprintf('All personal access tokens for User ID #%s have been revoked', $user->id));
|
||||
@ -188,7 +188,7 @@ public function destroy(Request $request, User $user)
|
||||
/**
|
||||
* Promote (or demote) a user
|
||||
*
|
||||
* @return \App\Api\v1\Resources\UserManagerResource
|
||||
* @return \App\Api\v1\Resources\UserManagerResource|\Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function promote(UserManagerPromoteRequest $request, User $user)
|
||||
{
|
||||
@ -209,7 +209,7 @@ public function promote(UserManagerPromoteRequest $request, User $user)
|
||||
/**
|
||||
* Get the user's authentication logs
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
* @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
|
||||
*/
|
||||
public function authentications(Request $request, User $user)
|
||||
{
|
||||
|
@ -9,11 +9,15 @@
|
||||
|
||||
/**
|
||||
* @property mixed $id
|
||||
* @property string $name
|
||||
* @property string $email
|
||||
* @property string $oauth_provider
|
||||
* @property \Illuminate\Support\Collection<array-key, mixed> $preferences
|
||||
* @property string $is_admin
|
||||
* @property string $ip_address
|
||||
* @property string $user_agent
|
||||
* @property string $browser
|
||||
* @property string $platform
|
||||
* @property string $device
|
||||
* @property Carbon|null $login_at
|
||||
* @property Carbon|null $logout_at
|
||||
* @property bool $login_successful
|
||||
* @property string|null $duration
|
||||
*/
|
||||
class UserAuthentication extends JsonResource
|
||||
{
|
||||
|
@ -55,7 +55,7 @@ public function __construct($resource)
|
||||
$tokens = $tokenRepository->forUser($this->resource->getAuthIdentifier());
|
||||
|
||||
$PATs_count = $tokens->load('client')->filter(function ($token) {
|
||||
return $token->client->personal_access_client && ! $token->revoked;
|
||||
return $token->client->personal_access_client && ! $token->revoked; /** @phpstan-ignore-line */
|
||||
})->count();
|
||||
|
||||
$this->with = [
|
||||
|
@ -27,14 +27,14 @@ class Group extends Model
|
||||
/**
|
||||
* model's array form.
|
||||
*
|
||||
* @var string[]
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = ['name'];
|
||||
|
||||
/**
|
||||
* The accessors to append to the model's array form.
|
||||
*
|
||||
* @var array
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $appends = [];
|
||||
|
||||
|
@ -16,7 +16,7 @@ class Option extends Model
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'key',
|
||||
|
@ -95,7 +95,7 @@ class TwoFAccount extends Model implements Sortable
|
||||
/**
|
||||
* model's array form.
|
||||
*
|
||||
* @var string[]
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
// 'service',
|
||||
@ -119,7 +119,7 @@ class TwoFAccount extends Model implements Sortable
|
||||
/**
|
||||
* The accessors to append to the model's array form.
|
||||
*
|
||||
* @var array
|
||||
* @var array<int, string>
|
||||
*/
|
||||
public $appends = [];
|
||||
|
||||
|
@ -46,15 +46,9 @@
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \Bubka\LaravelAuthenticationLog\Models\AuthenticationLog> $authentications
|
||||
* @property-read int|null $authentications_count
|
||||
* @property-read \Bubka\LaravelAuthenticationLog\Models\AuthenticationLog|null $latestAuthentication
|
||||
*
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User admins()
|
||||
* @method \Illuminate\Support\Carbon|null latestAuthentication()
|
||||
* @method \Illuminate\Support\Carbon|null lastLoginAt()
|
||||
* @method \Illuminate\Support\Carbon|null lastSuccessfulLoginAt()
|
||||
* @method \Illuminate\Support\Carbon|null lastLoginIp()
|
||||
* @method \Illuminate\Support\Carbon|null lastSuccessfulLoginIp()
|
||||
* @method \Illuminate\Support\Carbon|null previousLoginAt()
|
||||
* @method \Illuminate\Support\Carbon|null previousLoginIp()
|
||||
* @method \Illuminate\Support\Collection<int, \Bubka\LaravelAuthenticationLog\Models\AuthenticationLog> authenticationsByPeriod()
|
||||
*
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class User extends Authenticatable implements HasLocalePreference, WebAuthnAuthenticatable
|
||||
@ -66,7 +60,7 @@ class User extends Authenticatable implements HasLocalePreference, WebAuthnAuthe
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var string[]
|
||||
* @var array<int,string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name', 'email', 'password', 'oauth_id', 'oauth_provider',
|
||||
@ -148,15 +142,13 @@ public function promoteToAdministrator(bool $promote = true) : bool
|
||||
/**
|
||||
* Say if the user is the only registered administrator
|
||||
*
|
||||
* @return void
|
||||
* @return bool
|
||||
*/
|
||||
public function isLastAdministrator()
|
||||
{
|
||||
$admins = User::admins()->get();
|
||||
|
||||
$toto = $admins->contains($this->id) && $admins->count() === 1;
|
||||
|
||||
return $toto;
|
||||
return $admins->contains($this->id) && $admins->count() === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,12 +2,12 @@
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use Bubka\LaravelAuthenticationLog\Models\AuthenticationLog;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Jenssegers\Agent\Agent;
|
||||
use Bubka\LaravelAuthenticationLog\Models\AuthenticationLog;
|
||||
|
||||
class SignedInWithNewDevice extends Notification implements ShouldQueue
|
||||
{
|
||||
@ -32,10 +32,7 @@ public function __construct(AuthenticationLog $authenticationLog)
|
||||
$this->agent->setUserAgent($authenticationLog->user_agent);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function via($notifiable)
|
||||
public function via(mixed $notifiable) : array|string
|
||||
{
|
||||
return $notifiable->notifyAuthenticationLogVia();
|
||||
}
|
||||
@ -43,7 +40,7 @@ public function via($notifiable)
|
||||
/**
|
||||
* Wrap the notification to a mail envelop
|
||||
*/
|
||||
public function toMail($notifiable)
|
||||
public function toMail(mixed $notifiable) : MailMessage
|
||||
{
|
||||
return (new MailMessage())
|
||||
->subject(__('notifications.new_device.subject'))
|
||||
|
@ -58,7 +58,7 @@ protected function getUserByToken($token)
|
||||
*/
|
||||
public function refreshToken($refreshToken)
|
||||
{
|
||||
return $this->getHttpClient()->post($this->getTokenUrl(), [
|
||||
return $this->getHttpClient()->post($this->getTokenUrl(), [/** @phpstan-ignore-line */
|
||||
RequestOptions::FORM_PARAMS => [
|
||||
'client_id' => $this->clientId,
|
||||
'client_secret' => $this->clientSecret,
|
||||
|
@ -26,7 +26,7 @@ class GoogleAuthMigrator extends Migrator
|
||||
public function migrate(mixed $migrationPayload) : Collection
|
||||
{
|
||||
try {
|
||||
$migrationData = base64_decode(urldecode(Str::replace('otpauth-migration://offline?data=', '', $migrationPayload)));
|
||||
$migrationData = base64_decode(urldecode(Str::replace('otpauth-migration://offline?data=', '', strval($migrationPayload))));
|
||||
$protobuf = new Payload();
|
||||
$protobuf->mergeFromString($migrationData);
|
||||
$otpParameters = $protobuf->getOtpParameters();
|
||||
|
@ -55,19 +55,12 @@ public static function decode(\Illuminate\Http\UploadedFile $file)
|
||||
switch (get_class($qrcode->getError())) {
|
||||
case NotFoundException::class:
|
||||
throw new \App\Exceptions\InvalidQrCodeException(__('errors.cannot_detect_qrcode_in_image'));
|
||||
break;
|
||||
|
||||
case FormatException::class:
|
||||
throw new \App\Exceptions\InvalidQrCodeException(__('errors.cannot_decode_detected_qrcode'));
|
||||
break;
|
||||
|
||||
case ChecksumException::class:
|
||||
throw new \App\Exceptions\InvalidQrCodeException(__('errors.qrcode_has_invalid_checksum'));
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new \App\Exceptions\InvalidQrCodeException(__('errors.no_readable_qrcode'));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -589,7 +589,7 @@ public function test_authentications_returns_expected_resource() : void
|
||||
'logout_at',
|
||||
'login_successful',
|
||||
'duration',
|
||||
]
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
@ -604,7 +604,7 @@ public function test_authentications_returns_no_login_entry() : void
|
||||
->json('GET', '/api/v1/users/' . $this->user->id . '/authentications?period=1')
|
||||
->assertJsonCount(1)
|
||||
->assertJsonFragment([
|
||||
'login_at' => null
|
||||
'login_at' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
@ -619,7 +619,7 @@ public function test_authentications_returns_no_logout_entry() : void
|
||||
->json('GET', '/api/v1/users/' . $this->user->id . '/authentications?period=1')
|
||||
->assertJsonCount(1)
|
||||
->assertJsonFragment([
|
||||
'logout_at' => null
|
||||
'logout_at' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
@ -652,7 +652,7 @@ public function test_authentications_returns_last_month_entries() : void
|
||||
->json('GET', '/api/v1/users/' . $this->user->id . '/authentications?period=1')
|
||||
->assertJsonCount(3)
|
||||
->assertJsonFragment([
|
||||
'login_at' => $expected
|
||||
'login_at' => $expected,
|
||||
]);
|
||||
}
|
||||
|
||||
@ -669,10 +669,10 @@ public function test_authentications_returns_last_three_months_entries() : void
|
||||
->json('GET', '/api/v1/users/' . $this->user->id . '/authentications?period=3')
|
||||
->assertJsonCount(4)
|
||||
->assertJsonFragment([
|
||||
'login_at' => $expectedOneMonth
|
||||
'login_at' => $expectedOneMonth,
|
||||
])
|
||||
->assertJsonFragment([
|
||||
'login_at' => $expectedThreeMonth
|
||||
'login_at' => $expectedThreeMonth,
|
||||
]);
|
||||
}
|
||||
|
||||
@ -690,13 +690,13 @@ public function test_authentications_returns_last_six_months_entries() : void
|
||||
->json('GET', '/api/v1/users/' . $this->user->id . '/authentications?period=6')
|
||||
->assertJsonCount(5)
|
||||
->assertJsonFragment([
|
||||
'login_at' => $expectedOneMonth
|
||||
'login_at' => $expectedOneMonth,
|
||||
])
|
||||
->assertJsonFragment([
|
||||
'login_at' => $expectedThreeMonth
|
||||
'login_at' => $expectedThreeMonth,
|
||||
])
|
||||
->assertJsonFragment([
|
||||
'login_at' => $expectedSixMonth
|
||||
'login_at' => $expectedSixMonth,
|
||||
]);
|
||||
}
|
||||
|
||||
@ -715,16 +715,16 @@ public function test_authentications_returns_last_year_entries() : void
|
||||
->json('GET', '/api/v1/users/' . $this->user->id . '/authentications?period=12')
|
||||
->assertJsonCount(6)
|
||||
->assertJsonFragment([
|
||||
'login_at' => $expectedOneMonth
|
||||
'login_at' => $expectedOneMonth,
|
||||
])
|
||||
->assertJsonFragment([
|
||||
'login_at' => $expectedThreeMonth
|
||||
'login_at' => $expectedThreeMonth,
|
||||
])
|
||||
->assertJsonFragment([
|
||||
'login_at' => $expectedSixMonth
|
||||
'login_at' => $expectedSixMonth,
|
||||
])
|
||||
->assertJsonFragment([
|
||||
'login_at' => $expectedYear
|
||||
'login_at' => $expectedYear,
|
||||
]);
|
||||
}
|
||||
|
||||
@ -813,5 +813,4 @@ public static function invalidQueryParameterProvider()
|
||||
'array' => ['[]'],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user