Browse Source

Fix phpstan & pint issues

Bubka 1 year ago
parent
commit
f823f69dd2

+ 1 - 1
app/Api/v1/Controllers/TwoFAccountController.php

@@ -311,7 +311,7 @@ class TwoFAccountController extends Controller
     /**
      * Checks ids length
      *
-     * @param  string  $ids comma-separated ids
+     * @param  string  $ids  comma-separated ids
      * @return bool whether or not the number of ids is acceptable
      */
     private function tooManyIds(string $ids) : bool

+ 5 - 5
app/Api/v1/Controllers/UserManagerController.php

@@ -130,9 +130,9 @@ class UserManagerController extends Controller
         $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 @@ class UserManagerController extends Controller
     /**
      * 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 @@ class UserManagerController extends Controller
     /**
      * Get the user's authentication logs
      *
-     * @return \Illuminate\Http\JsonResponse
+     * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
      */
     public function authentications(Request $request, User $user)
     {
@@ -217,7 +217,7 @@ class UserManagerController extends Controller
 
         $validated = $this->validate($request, [
             'period' => 'sometimes|numeric',
-            'limit' => 'sometimes|numeric',
+            'limit'  => 'sometimes|numeric',
         ]);
 
         $authentications = $request->has('period') ? $user->authenticationsByPeriod($validated['period']) : $user->authentications;

+ 17 - 13
app/Api/v1/Resources/UserAuthentication.php

@@ -9,11 +9,15 @@ use Jenssegers\Agent\Agent;
 
 /**
  * @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
 {
@@ -47,16 +51,16 @@ class UserAuthentication extends JsonResource
     public function toArray($request)
     {
         return [
-            'id'               => $this->id,
-            'ip_address'       => $this->ip_address,
-            'user_agent'       => $this->user_agent,
-            'browser'          => $this->agent->browser(),
-            'platform'         => $this->agent->platform(),
-            'device'           => $this->agent->deviceType(),
-            'login_at'         => $this->login_at
+            'id'         => $this->id,
+            'ip_address' => $this->ip_address,
+            'user_agent' => $this->user_agent,
+            'browser'    => $this->agent->browser(),
+            'platform'   => $this->agent->platform(),
+            'device'     => $this->agent->deviceType(),
+            'login_at'   => $this->login_at
                                       ? Carbon::parse($this->login_at)->toDayDateTimeString()
                                       : null,
-            'logout_at'        => $this->logout_at
+            'logout_at' => $this->logout_at
                                       ? Carbon::parse($this->logout_at)->toDayDateTimeString()
                                       : null,
             'login_successful' => $this->login_successful,

+ 1 - 1
app/Api/v1/Resources/UserManagerResource.php

@@ -55,7 +55,7 @@ class UserManagerResource extends UserResource
         $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 = [

+ 1 - 1
app/Extensions/RemoteUserProvider.php

@@ -80,7 +80,7 @@ class RemoteUserProvider implements UserProvider
     /**
      * Set a fake email address
      *
-     * @param    $id mixed
+     * @param  $id  mixed
      * @return string
      */
     protected function fakeRemoteEmail(mixed $id)

+ 6 - 6
app/Factories/MigratorFactory.php

@@ -19,7 +19,7 @@ class MigratorFactory implements MigratorFactoryInterface
     /**
      * Infer the type of migrator needed from a payload and create the migrator
      *
-     * @param  string  $migrationPayload The migration payload used to infer the migrator type
+     * @param  string  $migrationPayload  The migration payload used to infer the migrator type
      */
     public function create(string $migrationPayload) : Migrator
     {
@@ -41,7 +41,7 @@ class MigratorFactory implements MigratorFactoryInterface
     /**
      * Determine if a payload comes from Google Authenticator
      *
-     * @param  string  $migrationPayload The payload to analyse
+     * @param  string  $migrationPayload  The payload to analyse
      */
     private function isGoogleAuth(string $migrationPayload) : bool
     {
@@ -59,7 +59,7 @@ class MigratorFactory implements MigratorFactoryInterface
     /**
      * Determine if a payload is a plain text content
      *
-     * @param  string  $migrationPayload The payload to analyse
+     * @param  string  $migrationPayload  The payload to analyse
      */
     private function isPlainText(string $migrationPayload) : bool
     {
@@ -77,7 +77,7 @@ class MigratorFactory implements MigratorFactoryInterface
     /**
      * Determine if a payload comes from 2FAuth in JSON format
      *
-     * @param  string  $migrationPayload The payload to analyse
+     * @param  string  $migrationPayload  The payload to analyse
      */
     private function isTwoFAuthJSON(string $migrationPayload) : bool
     {
@@ -105,7 +105,7 @@ class MigratorFactory implements MigratorFactoryInterface
     /**
      * Determine if a payload comes from Aegis Authenticator in JSON format
      *
-     * @param  string  $migrationPayload The payload to analyse
+     * @param  string  $migrationPayload  The payload to analyse
      * @return bool
      */
     private function isAegisJSON(string $migrationPayload) : mixed
@@ -150,7 +150,7 @@ class MigratorFactory implements MigratorFactoryInterface
     /**
      * Determine if a payload comes from 2FAS Authenticator
      *
-     * @param  string  $migrationPayload The payload to analyse
+     * @param  string  $migrationPayload  The payload to analyse
      * @return bool
      */
     private function is2FASv2(string $migrationPayload) : mixed

+ 1 - 1
app/Factories/MigratorFactoryInterface.php

@@ -9,7 +9,7 @@ interface MigratorFactoryInterface
     /**
      * Infer the type of migrator needed from a payload and create the migrator
      *
-     * @param  string  $migrationPayload The migration payload used to infer the migrator type
+     * @param  string  $migrationPayload  The migration payload used to infer the migrator type
      */
     public function create(string $migrationPayload) : Migrator;
 }

+ 2 - 2
app/Models/Group.php

@@ -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 = [];
 

+ 1 - 1
app/Models/Option.php

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

+ 4 - 4
app/Models/TwoFAccount.php

@@ -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 = [];
 
@@ -611,7 +611,7 @@ class TwoFAccount extends Model implements Sortable
      * Store and set the provided icon
      *
      * @param  \Psr\Http\Message\StreamInterface|\Illuminate\Http\File|\Illuminate\Http\UploadedFile|string|resource  $data
-     * @param  string|null  $extension The resource extension, without the dot
+     * @param  string|null  $extension  The resource extension, without the dot
      */
     public function setIcon($data, $extension = null) : void
     {
@@ -633,7 +633,7 @@ class TwoFAccount extends Model implements Sortable
      * Store img data as an icon file.
      *
      * @param  \Psr\Http\Message\StreamInterface|\Illuminate\Http\File|\Illuminate\Http\UploadedFile|string|resource  $content
-     * @param  string  $extension The file extension, without the dot
+     * @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

+ 5 - 13
app/Models/User.php

@@ -46,15 +46,9 @@ use Laravel\Passport\HasApiTokens;
  * @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 @@ class User extends Authenticatable implements HasLocalePreference, WebAuthnAuthe
     /**
      * 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;
     }
 
     /**

+ 3 - 6
app/Notifications/SignedInWithNewDevice.php

@@ -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 @@ class SignedInWithNewDevice extends Notification implements ShouldQueue
         $this->agent->setUserAgent($authenticationLog->user_agent);
     }
 
-    /**
-     * 
-     */
-    public function via($notifiable)
+    public function via(mixed $notifiable) : array|string
     {
         return $notifiable->notifyAuthenticationLogVia();
     }
@@ -43,7 +40,7 @@ class SignedInWithNewDevice extends Notification implements ShouldQueue
     /**
      * 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'))

+ 1 - 1
app/Providers/Socialite/OpenId.php

@@ -58,7 +58,7 @@ class OpenId extends AbstractProvider
      */
     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,

+ 2 - 2
app/Services/GroupService.php

@@ -14,8 +14,8 @@ class GroupService
     /**
      * Assign one or more accounts to a group
      *
-     * @param  array|int  $ids accounts ids to assign
-     * @param  \App\Models\Group|null  $group The group the accounts will be assigned to
+     * @param  array|int  $ids  accounts ids to assign
+     * @param  \App\Models\Group|null  $group  The group the accounts will be assigned to
      *
      * @throws \Illuminate\Auth\Access\AuthorizationException
      */

+ 3 - 3
app/Services/LogoService.php

@@ -33,7 +33,7 @@ class LogoService
     /**
      * Fetch a logo for the given service and save it as an icon
      *
-     * @param  string  $serviceName Name of the service to fetch a logo for
+     * @param  string  $serviceName  Name of the service to fetch a logo for
      * @return string|null The icon filename or null if no logo has been found
      */
     public function getIcon($serviceName)
@@ -52,7 +52,7 @@ class LogoService
     /**
      * Return the logo's filename for a given service
      *
-     * @param  string  $serviceName Name of the service to fetch a logo for
+     * @param  string  $serviceName  Name of the service to fetch a logo for
      * @return string|null The logo filename or null if no logo has been found
      */
     protected function getLogo($serviceName)
@@ -114,7 +114,7 @@ class LogoService
     /**
      * Fetch and cache a logo from 2fa.Directory repository
      *
-     * @param  string  $logoFile Logo filename to fetch
+     * @param  string  $logoFile  Logo filename to fetch
      */
     protected function fetchLogo(string $logoFile) : void
     {

+ 2 - 2
app/Services/Migrators/GoogleAuthMigrator.php

@@ -20,13 +20,13 @@ class GoogleAuthMigrator extends Migrator
     /**
      * Convert Google Authenticator migration URI to a set of TwoFAccount objects.
      *
-     * @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
      */
     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();

+ 1 - 8
app/Services/QrCodeService.php

@@ -15,7 +15,7 @@ class QrCodeService
     /**
      * Encode a string into a QR code image
      *
-     * @param  string  $data The string to encode
+     * @param  string  $data  The string to encode
      * @return mixed
      */
     public static function encode(string $data)
@@ -55,19 +55,12 @@ class QrCodeService
             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;
             }
         }
 

+ 5 - 5
app/Services/SettingService.php

@@ -46,7 +46,7 @@ class SettingService
     /**
      * Get a setting
      *
-     * @param  string  $setting A single setting name
+     * @param  string  $setting  A single setting name
      * @return mixed string|int|boolean|null
      */
     public function get($setting)
@@ -67,8 +67,8 @@ class SettingService
     /**
      * Set a setting
      *
-     * @param  string|array  $setting A single setting name or an associative array of name:value settings
-     * @param  string|int|bool|null  $value The value for single setting
+     * @param  string|array  $setting  A single setting name or an associative array of name:value settings
+     * @param  string|int|bool|null  $value  The value for single setting
      */
     public function set($setting, $value = null) : void
     {
@@ -93,7 +93,7 @@ class SettingService
     /**
      * Delete a setting
      *
-     * @param  string  $name The setting name
+     * @param  string  $name  The setting name
      */
     public function delete(string $name) : void
     {
@@ -200,7 +200,7 @@ class SettingService
     /**
      * Encrypt/Decrypt accounts in database
      *
-     * @param  bool  $encrypted Whether the record should be encrypted or not
+     * @param  bool  $encrypted  Whether the record should be encrypted or not
      * @return bool Whether the operation completed successfully
      */
     private function updateRecords(bool $encrypted) : bool

+ 4 - 4
app/Services/TwoFAccountService.php

@@ -28,7 +28,7 @@ class TwoFAccountService
     /**
      * Withdraw one or more twofaccounts from their group
      *
-     * @param  int|array|string  $ids twofaccount ids to free
+     * @param  int|array|string  $ids  twofaccount ids to free
      */
     public static function withdraw($ids) : void
     {
@@ -50,7 +50,7 @@ class TwoFAccountService
     /**
      * Convert a migration payload to a set of TwoFAccount objects
      *
-     * @param  string  $migrationPayload Migration payload from 2FA apps export feature
+     * @param  string  $migrationPayload  Migration payload from 2FA apps export feature
      * @return \Illuminate\Support\Collection<int|string, TwoFAccount> The converted accounts
      */
     public function migrate(string $migrationPayload) : Collection
@@ -64,7 +64,7 @@ class TwoFAccountService
     /**
      * Export one or more twofaccounts
      *
-     * @param  int|array|string  $ids twofaccount ids to delete
+     * @param  int|array|string  $ids  twofaccount ids to delete
      * @return \Illuminate\Support\Collection<int, TwoFAccount> The converted accounts
      */
     public static function export($ids) : Collection
@@ -80,7 +80,7 @@ class TwoFAccountService
     /**
      * Delete one or more twofaccounts
      *
-     * @param  int|array|string  $ids twofaccount ids to delete
+     * @param  int|array|string  $ids  twofaccount ids to delete
      * @return int The number of deleted
      */
     public static function delete($ids) : int

+ 43 - 44
tests/Api/v1/Controllers/UserManagerControllerTest.php

@@ -561,7 +561,7 @@ class UserManagerControllerTest extends FeatureTestCase
     public function test_authentications_returns_all_entries() : void
     {
         $created = $this->feedAuthenticationLog();
-        
+
         $this->actingAs($this->admin, 'api-guard')
             ->json('GET', '/api/v1/users/' . $this->user->id . '/authentications')
             ->assertOk()
@@ -574,7 +574,7 @@ class UserManagerControllerTest extends FeatureTestCase
     public function test_authentications_returns_expected_resource() : void
     {
         $this->user->authentications()->create(AuthenticationLogData::duringLastMonth());
-        
+
         $this->actingAs($this->admin, 'api-guard')
             ->json('GET', '/api/v1/users/' . $this->user->id . '/authentications')
             ->assertJsonStructure([
@@ -589,7 +589,7 @@ class UserManagerControllerTest extends FeatureTestCase
                     'logout_at',
                     'login_successful',
                     'duration',
-                ]
+                ],
             ]);
     }
 
@@ -599,12 +599,12 @@ class UserManagerControllerTest extends FeatureTestCase
     public function test_authentications_returns_no_login_entry() : void
     {
         $this->user->authentications()->create(AuthenticationLogData::noLogin());
-        
+
         $this->actingAs($this->admin, 'api-guard')
             ->json('GET', '/api/v1/users/' . $this->user->id . '/authentications?period=1')
             ->assertJsonCount(1)
             ->assertJsonFragment([
-                'login_at' => null
+                'login_at' => null,
             ]);
     }
 
@@ -614,12 +614,12 @@ class UserManagerControllerTest extends FeatureTestCase
     public function test_authentications_returns_no_logout_entry() : void
     {
         $this->user->authentications()->create(AuthenticationLogData::noLogout());
-        
+
         $this->actingAs($this->admin, 'api-guard')
             ->json('GET', '/api/v1/users/' . $this->user->id . '/authentications?period=1')
             ->assertJsonCount(1)
             ->assertJsonFragment([
-                'logout_at' => null
+                'logout_at' => null,
             ]);
     }
 
@@ -630,12 +630,12 @@ class UserManagerControllerTest extends FeatureTestCase
     {
         $this->user->authentications()->create(AuthenticationLogData::failedLogin());
         $expected = Carbon::parse(AuthenticationLogData::failedLogin()['login_at'])->toDayDateTimeString();
-        
+
         $this->actingAs($this->admin, 'api-guard')
             ->json('GET', '/api/v1/users/' . $this->user->id . '/authentications?period=1')
             ->assertJsonCount(1)
             ->assertJsonFragment([
-                'login_at' => $expected,
+                'login_at'         => $expected,
                 'login_successful' => false,
             ]);
     }
@@ -647,12 +647,12 @@ class UserManagerControllerTest extends FeatureTestCase
     {
         $this->feedAuthenticationLog();
         $expected = Carbon::parse(AuthenticationLogData::duringLastMonth()['login_at'])->toDayDateTimeString();
-        
+
         $this->actingAs($this->admin, 'api-guard')
             ->json('GET', '/api/v1/users/' . $this->user->id . '/authentications?period=1')
             ->assertJsonCount(3)
             ->assertJsonFragment([
-                'login_at' => $expected
+                'login_at' => $expected,
             ]);
     }
 
@@ -662,17 +662,17 @@ class UserManagerControllerTest extends FeatureTestCase
     public function test_authentications_returns_last_three_months_entries() : void
     {
         $this->feedAuthenticationLog();
-        $expectedOneMonth = Carbon::parse(AuthenticationLogData::duringLastMonth()['login_at'])->toDayDateTimeString();
+        $expectedOneMonth   = Carbon::parse(AuthenticationLogData::duringLastMonth()['login_at'])->toDayDateTimeString();
         $expectedThreeMonth = Carbon::parse(AuthenticationLogData::duringLastThreeMonth()['login_at'])->toDayDateTimeString();
-        
+
         $this->actingAs($this->admin, 'api-guard')
             ->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,
             ]);
     }
 
@@ -682,21 +682,21 @@ class UserManagerControllerTest extends FeatureTestCase
     public function test_authentications_returns_last_six_months_entries() : void
     {
         $this->feedAuthenticationLog();
-        $expectedOneMonth = Carbon::parse(AuthenticationLogData::duringLastMonth()['login_at'])->toDayDateTimeString();
+        $expectedOneMonth   = Carbon::parse(AuthenticationLogData::duringLastMonth()['login_at'])->toDayDateTimeString();
         $expectedThreeMonth = Carbon::parse(AuthenticationLogData::duringLastThreeMonth()['login_at'])->toDayDateTimeString();
-        $expectedSixMonth = Carbon::parse(AuthenticationLogData::duringLastSixMonth()['login_at'])->toDayDateTimeString();
-        
+        $expectedSixMonth   = Carbon::parse(AuthenticationLogData::duringLastSixMonth()['login_at'])->toDayDateTimeString();
+
         $this->actingAs($this->admin, 'api-guard')
             ->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,
             ]);
     }
 
@@ -706,25 +706,25 @@ class UserManagerControllerTest extends FeatureTestCase
     public function test_authentications_returns_last_year_entries() : void
     {
         $this->feedAuthenticationLog();
-        $expectedOneMonth = Carbon::parse(AuthenticationLogData::duringLastMonth()['login_at'])->toDayDateTimeString();
+        $expectedOneMonth   = Carbon::parse(AuthenticationLogData::duringLastMonth()['login_at'])->toDayDateTimeString();
         $expectedThreeMonth = Carbon::parse(AuthenticationLogData::duringLastThreeMonth()['login_at'])->toDayDateTimeString();
-        $expectedSixMonth = Carbon::parse(AuthenticationLogData::duringLastSixMonth()['login_at'])->toDayDateTimeString();
-        $expectedYear = Carbon::parse(AuthenticationLogData::duringLastYear()['login_at'])->toDayDateTimeString();
-        
+        $expectedSixMonth   = Carbon::parse(AuthenticationLogData::duringLastSixMonth()['login_at'])->toDayDateTimeString();
+        $expectedYear       = Carbon::parse(AuthenticationLogData::duringLastYear()['login_at'])->toDayDateTimeString();
+
         $this->actingAs($this->admin, 'api-guard')
             ->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,
             ]);
     }
 
@@ -735,7 +735,7 @@ class UserManagerControllerTest extends FeatureTestCase
     public function test_authentications_returns_limited_entries($limit) : void
     {
         $this->feedAuthenticationLog();
-        
+
         $this->actingAs($this->admin, 'api-guard')
             ->json('GET', '/api/v1/users/' . $this->user->id . '/authentications?limit=' . $limit)
             ->assertOk()
@@ -760,21 +760,21 @@ class UserManagerControllerTest extends FeatureTestCase
     public function test_authentications_returns_expected_ip_and_useragent_chunks() : void
     {
         $this->user->authentications()->create([
-            'ip_address' => '127.0.0.1',
-            'user_agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0',
-            'login_at' => now(),
+            'ip_address'       => '127.0.0.1',
+            'user_agent'       => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0',
+            'login_at'         => now(),
             'login_successful' => true,
-            'logout_at' => null,
-            'location' => null,
+            'logout_at'        => null,
+            'location'         => null,
         ]);
-        
+
         $this->actingAs($this->admin, 'api-guard')
             ->json('GET', '/api/v1/users/' . $this->user->id . '/authentications?period=1')
             ->assertJsonFragment([
                 'ip_address' => '127.0.0.1',
-                'browser' => 'Firefox',
-                'platform' => 'Windows',
-                'device' => 'desktop',
+                'browser'    => 'Firefox',
+                'platform'   => 'Windows',
+                'device'     => 'desktop',
             ]);
     }
 
@@ -806,12 +806,11 @@ class UserManagerControllerTest extends FeatureTestCase
     public static function invalidQueryParameterProvider()
     {
         return [
-            'empty' => [''],
-            'null' => ['null'],
+            'empty'   => [''],
+            'null'    => ['null'],
             'boolean' => ['true'],
-            'string' => ['string'],
-            'array' => ['[]'],
+            'string'  => ['string'],
+            'array'   => ['[]'],
         ];
     }
-    
 }

+ 51 - 51
tests/Data/AuthenticationLogData.php

@@ -12,14 +12,14 @@ class AuthenticationLogData
     public static function failedLogin()
     {
         $loginDate = now()->subDays(15);
-    
+
         return [
-            'ip_address' => fake()->ipv4(),
-            'user_agent' => fake()->userAgent(),
-            'login_at' => $loginDate,
+            'ip_address'       => fake()->ipv4(),
+            'user_agent'       => fake()->userAgent(),
+            'login_at'         => $loginDate,
             'login_successful' => false,
-            'logout_at' => null,
-            'location' => null,
+            'logout_at'        => null,
+            'location'         => null,
         ];
     }
 
@@ -31,12 +31,12 @@ class AuthenticationLogData
     public static function noLogin()
     {
         return [
-            'ip_address' => fake()->ipv4(),
-            'user_agent' => fake()->userAgent(),
-            'login_at' => null,
+            'ip_address'       => fake()->ipv4(),
+            'user_agent'       => fake()->userAgent(),
+            'login_at'         => null,
             'login_successful' => false,
-            'logout_at' => now(),
-            'location' => null,
+            'logout_at'        => now(),
+            'location'         => null,
         ];
     }
 
@@ -48,12 +48,12 @@ class AuthenticationLogData
     public static function noLogout()
     {
         return [
-            'ip_address' => fake()->ipv4(),
-            'user_agent' => fake()->userAgent(),
-            'login_at' => now(),
+            'ip_address'       => fake()->ipv4(),
+            'user_agent'       => fake()->userAgent(),
+            'login_at'         => now(),
             'login_successful' => true,
-            'logout_at' => null,
-            'location' => null,
+            'logout_at'        => null,
+            'location'         => null,
         ];
     }
 
@@ -64,16 +64,16 @@ class AuthenticationLogData
      */
     public static function duringLastMonth()
     {
-        $loginDate = now()->subDays(15);
+        $loginDate  = now()->subDays(15);
         $logoutDate = $loginDate->addHours(1);
-    
+
         return [
-            'ip_address' => '127.0.0.1',
-            'user_agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0',
-            'login_at' => $loginDate,
+            'ip_address'       => '127.0.0.1',
+            'user_agent'       => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0',
+            'login_at'         => $loginDate,
             'login_successful' => true,
-            'logout_at' => $logoutDate,
-            'location' => null,
+            'logout_at'        => $logoutDate,
+            'location'         => null,
         ];
     }
 
@@ -84,16 +84,16 @@ class AuthenticationLogData
      */
     public static function duringLastThreeMonth()
     {
-        $loginDate = now()->subMonths(2);
+        $loginDate  = now()->subMonths(2);
         $logoutDate = $loginDate->addHours(1);
-    
+
         return [
-            'ip_address' => fake()->ipv4(),
-            'user_agent' => fake()->userAgent(),
-            'login_at' => $loginDate,
+            'ip_address'       => fake()->ipv4(),
+            'user_agent'       => fake()->userAgent(),
+            'login_at'         => $loginDate,
             'login_successful' => true,
-            'logout_at' => $logoutDate,
-            'location' => null,
+            'logout_at'        => $logoutDate,
+            'location'         => null,
         ];
     }
 
@@ -104,16 +104,16 @@ class AuthenticationLogData
      */
     public static function duringLastSixMonth()
     {
-        $loginDate = now()->subMonths(4);
+        $loginDate  = now()->subMonths(4);
         $logoutDate = $loginDate->addHours(1);
-    
+
         return [
-            'ip_address' => fake()->ipv4(),
-            'user_agent' => fake()->userAgent(),
-            'login_at' => $loginDate,
+            'ip_address'       => fake()->ipv4(),
+            'user_agent'       => fake()->userAgent(),
+            'login_at'         => $loginDate,
             'login_successful' => true,
-            'logout_at' => $logoutDate,
-            'location' => null,
+            'logout_at'        => $logoutDate,
+            'location'         => null,
         ];
     }
 
@@ -124,16 +124,16 @@ class AuthenticationLogData
      */
     public static function duringLastYear()
     {
-        $loginDate = now()->subMonths(10);
+        $loginDate  = now()->subMonths(10);
         $logoutDate = $loginDate->addHours(1);
-    
+
         return [
-            'ip_address' => fake()->ipv4(),
-            'user_agent' => fake()->userAgent(),
-            'login_at' => $loginDate,
+            'ip_address'       => fake()->ipv4(),
+            'user_agent'       => fake()->userAgent(),
+            'login_at'         => $loginDate,
             'login_successful' => true,
-            'logout_at' => $logoutDate,
-            'location' => null,
+            'logout_at'        => $logoutDate,
+            'location'         => null,
         ];
     }
 
@@ -144,16 +144,16 @@ class AuthenticationLogData
      */
     public static function beforeLastYear()
     {
-        $loginDate = now()->subYears(2);
+        $loginDate  = now()->subYears(2);
         $logoutDate = $loginDate->addHours(1);
-    
+
         return [
-            'ip_address' => fake()->ipv4(),
-            'user_agent' => fake()->userAgent(),
-            'login_at' => $loginDate,
+            'ip_address'       => fake()->ipv4(),
+            'user_agent'       => fake()->userAgent(),
+            'login_at'         => $loginDate,
             'login_successful' => true,
-            'logout_at' => $logoutDate,
-            'location' => null,
+            'logout_at'        => $logoutDate,
+            'location'         => null,
         ];
     }
 }