Fix phpstan & pint issues

This commit is contained in:
Bubka 2024-04-20 19:03:44 +02:00
parent e7f542816d
commit f823f69dd2
21 changed files with 159 additions and 174 deletions

View File

@ -130,9 +130,9 @@ public function revokePATs(Request $request, User $user, TokenRepository $tokenR
$tokens = $tokenRepository->forUser($user->getAuthIdentifier()); $tokens = $tokenRepository->forUser($user->getAuthIdentifier());
$tokens->load('client')->filter(function ($token) { $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) { })->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)); 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 * 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) public function promote(UserManagerPromoteRequest $request, User $user)
{ {
@ -209,7 +209,7 @@ public function promote(UserManagerPromoteRequest $request, User $user)
/** /**
* Get the user's authentication logs * Get the user's authentication logs
* *
* @return \Illuminate\Http\JsonResponse * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
*/ */
public function authentications(Request $request, User $user) public function authentications(Request $request, User $user)
{ {

View File

@ -9,11 +9,15 @@
/** /**
* @property mixed $id * @property mixed $id
* @property string $name * @property string $ip_address
* @property string $email * @property string $user_agent
* @property string $oauth_provider * @property string $browser
* @property \Illuminate\Support\Collection<array-key, mixed> $preferences * @property string $platform
* @property string $is_admin * @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 class UserAuthentication extends JsonResource
{ {

View File

@ -55,7 +55,7 @@ public function __construct($resource)
$tokens = $tokenRepository->forUser($this->resource->getAuthIdentifier()); $tokens = $tokenRepository->forUser($this->resource->getAuthIdentifier());
$PATs_count = $tokens->load('client')->filter(function ($token) { $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(); })->count();
$this->with = [ $this->with = [

View File

@ -27,14 +27,14 @@ class Group extends Model
/** /**
* model's array form. * model's array form.
* *
* @var string[] * @var array<int, string>
*/ */
protected $fillable = ['name']; protected $fillable = ['name'];
/** /**
* The accessors to append to the model's array form. * The accessors to append to the model's array form.
* *
* @var array * @var array<int, string>
*/ */
protected $appends = []; protected $appends = [];

View File

@ -16,7 +16,7 @@ class Option extends Model
/** /**
* The attributes that are mass assignable. * The attributes that are mass assignable.
* *
* @var string[] * @var array<int, string>
*/ */
protected $fillable = [ protected $fillable = [
'key', 'key',

View File

@ -95,7 +95,7 @@ class TwoFAccount extends Model implements Sortable
/** /**
* model's array form. * model's array form.
* *
* @var string[] * @var array<int, string>
*/ */
protected $fillable = [ protected $fillable = [
// 'service', // 'service',
@ -119,7 +119,7 @@ class TwoFAccount extends Model implements Sortable
/** /**
* The accessors to append to the model's array form. * The accessors to append to the model's array form.
* *
* @var array * @var array<int, string>
*/ */
public $appends = []; public $appends = [];

View File

@ -46,15 +46,9 @@
* @property-read \Illuminate\Database\Eloquent\Collection<int, \Bubka\LaravelAuthenticationLog\Models\AuthenticationLog> $authentications * @property-read \Illuminate\Database\Eloquent\Collection<int, \Bubka\LaravelAuthenticationLog\Models\AuthenticationLog> $authentications
* @property-read int|null $authentications_count * @property-read int|null $authentications_count
* @property-read \Bubka\LaravelAuthenticationLog\Models\AuthenticationLog|null $latestAuthentication * @property-read \Bubka\LaravelAuthenticationLog\Models\AuthenticationLog|null $latestAuthentication
*
* @method static \Illuminate\Database\Eloquent\Builder|User admins() * @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 * @mixin \Eloquent
*/ */
class User extends Authenticatable implements HasLocalePreference, WebAuthnAuthenticatable class User extends Authenticatable implements HasLocalePreference, WebAuthnAuthenticatable
@ -66,7 +60,7 @@ class User extends Authenticatable implements HasLocalePreference, WebAuthnAuthe
/** /**
* The attributes that are mass assignable. * The attributes that are mass assignable.
* *
* @var string[] * @var array<int,string>
*/ */
protected $fillable = [ protected $fillable = [
'name', 'email', 'password', 'oauth_id', 'oauth_provider', '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 * Say if the user is the only registered administrator
* *
* @return void * @return bool
*/ */
public function isLastAdministrator() public function isLastAdministrator()
{ {
$admins = User::admins()->get(); $admins = User::admins()->get();
$toto = $admins->contains($this->id) && $admins->count() === 1; return $admins->contains($this->id) && $admins->count() === 1;
return $toto;
} }
/** /**

View File

@ -2,12 +2,12 @@
namespace App\Notifications; namespace App\Notifications;
use Bubka\LaravelAuthenticationLog\Models\AuthenticationLog;
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification; use Illuminate\Notifications\Notification;
use Jenssegers\Agent\Agent; use Jenssegers\Agent\Agent;
use Bubka\LaravelAuthenticationLog\Models\AuthenticationLog;
class SignedInWithNewDevice extends Notification implements ShouldQueue class SignedInWithNewDevice extends Notification implements ShouldQueue
{ {
@ -32,10 +32,7 @@ public function __construct(AuthenticationLog $authenticationLog)
$this->agent->setUserAgent($authenticationLog->user_agent); $this->agent->setUserAgent($authenticationLog->user_agent);
} }
/** public function via(mixed $notifiable) : array|string
*
*/
public function via($notifiable)
{ {
return $notifiable->notifyAuthenticationLogVia(); return $notifiable->notifyAuthenticationLogVia();
} }
@ -43,7 +40,7 @@ public function via($notifiable)
/** /**
* Wrap the notification to a mail envelop * Wrap the notification to a mail envelop
*/ */
public function toMail($notifiable) public function toMail(mixed $notifiable) : MailMessage
{ {
return (new MailMessage()) return (new MailMessage())
->subject(__('notifications.new_device.subject')) ->subject(__('notifications.new_device.subject'))

View File

@ -58,7 +58,7 @@ protected function getUserByToken($token)
*/ */
public function refreshToken($refreshToken) public function refreshToken($refreshToken)
{ {
return $this->getHttpClient()->post($this->getTokenUrl(), [ return $this->getHttpClient()->post($this->getTokenUrl(), [/** @phpstan-ignore-line */
RequestOptions::FORM_PARAMS => [ RequestOptions::FORM_PARAMS => [
'client_id' => $this->clientId, 'client_id' => $this->clientId,
'client_secret' => $this->clientSecret, 'client_secret' => $this->clientSecret,

View File

@ -26,7 +26,7 @@ class GoogleAuthMigrator extends Migrator
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=', '', strval($migrationPayload))));
$protobuf = new Payload(); $protobuf = new Payload();
$protobuf->mergeFromString($migrationData); $protobuf->mergeFromString($migrationData);
$otpParameters = $protobuf->getOtpParameters(); $otpParameters = $protobuf->getOtpParameters();

View File

@ -55,19 +55,12 @@ public static function decode(\Illuminate\Http\UploadedFile $file)
switch (get_class($qrcode->getError())) { switch (get_class($qrcode->getError())) {
case NotFoundException::class: case NotFoundException::class:
throw new \App\Exceptions\InvalidQrCodeException(__('errors.cannot_detect_qrcode_in_image')); throw new \App\Exceptions\InvalidQrCodeException(__('errors.cannot_detect_qrcode_in_image'));
break;
case FormatException::class: case FormatException::class:
throw new \App\Exceptions\InvalidQrCodeException(__('errors.cannot_decode_detected_qrcode')); throw new \App\Exceptions\InvalidQrCodeException(__('errors.cannot_decode_detected_qrcode'));
break;
case ChecksumException::class: case ChecksumException::class:
throw new \App\Exceptions\InvalidQrCodeException(__('errors.qrcode_has_invalid_checksum')); throw new \App\Exceptions\InvalidQrCodeException(__('errors.qrcode_has_invalid_checksum'));
break;
default: default:
throw new \App\Exceptions\InvalidQrCodeException(__('errors.no_readable_qrcode')); throw new \App\Exceptions\InvalidQrCodeException(__('errors.no_readable_qrcode'));
break;
} }
} }

View File

@ -589,7 +589,7 @@ public function test_authentications_returns_expected_resource() : void
'logout_at', 'logout_at',
'login_successful', 'login_successful',
'duration', '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') ->json('GET', '/api/v1/users/' . $this->user->id . '/authentications?period=1')
->assertJsonCount(1) ->assertJsonCount(1)
->assertJsonFragment([ ->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') ->json('GET', '/api/v1/users/' . $this->user->id . '/authentications?period=1')
->assertJsonCount(1) ->assertJsonCount(1)
->assertJsonFragment([ ->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') ->json('GET', '/api/v1/users/' . $this->user->id . '/authentications?period=1')
->assertJsonCount(3) ->assertJsonCount(3)
->assertJsonFragment([ ->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') ->json('GET', '/api/v1/users/' . $this->user->id . '/authentications?period=3')
->assertJsonCount(4) ->assertJsonCount(4)
->assertJsonFragment([ ->assertJsonFragment([
'login_at' => $expectedOneMonth 'login_at' => $expectedOneMonth,
]) ])
->assertJsonFragment([ ->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') ->json('GET', '/api/v1/users/' . $this->user->id . '/authentications?period=6')
->assertJsonCount(5) ->assertJsonCount(5)
->assertJsonFragment([ ->assertJsonFragment([
'login_at' => $expectedOneMonth 'login_at' => $expectedOneMonth,
]) ])
->assertJsonFragment([ ->assertJsonFragment([
'login_at' => $expectedThreeMonth 'login_at' => $expectedThreeMonth,
]) ])
->assertJsonFragment([ ->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') ->json('GET', '/api/v1/users/' . $this->user->id . '/authentications?period=12')
->assertJsonCount(6) ->assertJsonCount(6)
->assertJsonFragment([ ->assertJsonFragment([
'login_at' => $expectedOneMonth 'login_at' => $expectedOneMonth,
]) ])
->assertJsonFragment([ ->assertJsonFragment([
'login_at' => $expectedThreeMonth 'login_at' => $expectedThreeMonth,
]) ])
->assertJsonFragment([ ->assertJsonFragment([
'login_at' => $expectedSixMonth 'login_at' => $expectedSixMonth,
]) ])
->assertJsonFragment([ ->assertJsonFragment([
'login_at' => $expectedYear 'login_at' => $expectedYear,
]); ]);
} }
@ -813,5 +813,4 @@ public static function invalidQueryParameterProvider()
'array' => ['[]'], 'array' => ['[]'],
]; ];
} }
} }