Bubka пре 8 месеци
родитељ
комит
fee7a684b2
32 измењених фајлова са 126 додато и 120 уклоњено
  1. 1 1
      app/Api/v1/Controllers/IconController.php
  2. 1 0
      app/Api/v1/Resources/TwoFAccountExportResource.php
  3. 1 1
      app/Api/v1/Resources/TwoFAccountReadResource.php
  4. 1 1
      app/Console/Commands/ResetTesting.php
  5. 1 1
      app/Listeners/CleanIconStorage.php
  6. 2 4
      app/Listeners/ToggleIconReplicationToDatabase.php
  7. 2 0
      app/Models/AuthLog.php
  8. 3 0
      app/Models/Group.php
  9. 4 4
      app/Models/Icon.php
  10. 2 0
      app/Models/Option.php
  11. 6 3
      app/Models/TwoFAccount.php
  12. 3 0
      app/Models/User.php
  13. 2 2
      app/Providers/EventServiceProvider.php
  14. 1 1
      app/Providers/TwoFAuthServiceProvider.php
  15. 6 6
      app/Services/IconService.php
  16. 7 8
      app/Services/IconStoreService.php
  17. 2 2
      app/Services/LogoService.php
  18. 2 2
      app/Services/Migrators/AegisMigrator.php
  19. 2 2
      app/Services/Migrators/TwoFAuthMigrator.php
  20. 3 3
      tests/Api/v1/Controllers/IconControllerTest.php
  21. 1 1
      tests/Api/v1/Controllers/TwoFAccountControllerTest.php
  22. 13 13
      tests/Api/v1/Requests/TwoFAccountExportRequestTest.php
  23. 2 2
      tests/Feature/Models/TwoFAccountModelTest.php
  24. 1 2
      tests/Feature/Models/UserModelTest.php
  25. 13 13
      tests/Feature/Services/IconServiceTest.php
  26. 35 35
      tests/Feature/Services/IconStoreServiceTest.php
  27. 2 2
      tests/Feature/Services/LogoServiceTest.php
  28. 1 3
      tests/Feature/Services/SettingServiceTest.php
  29. 1 1
      tests/Unit/Events/storeIconsInDatabaseSettingChangedTest.php
  30. 1 2
      tests/Unit/Listeners/CleanIconStorageTest.php
  31. 3 4
      tests/Unit/MigratorTest.php
  32. 1 1
      tests/Unit/TwoFAccountModelTest.php

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

@@ -34,8 +34,8 @@ class IconController extends Controller
                     $name     = Helpers::getRandomFilename($icon->extension());
                     $isStored = IconStore::store($name, $content);
                 }
+            } catch (Exception) {
             }
-            catch (Exception) { }
         }
 
         return $isStored

+ 1 - 0
app/Api/v1/Resources/TwoFAccountExportResource.php

@@ -17,6 +17,7 @@ use Illuminate\Http\Resources\Json\JsonResource;
  * @property int|null $period
  * @property int|null $counter
  * @property string $legacy_uri
+ *
  * @method string getURI()
  */
 class TwoFAccountExportResource extends JsonResource

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

@@ -5,7 +5,7 @@ namespace App\Api\v1\Resources;
 /**
  * @property mixed $id
  * @property mixed $group_id
- * 
+ *
  * @method App\Models\Dto\TotpDto|App\Models\Dto\HotpDto getOtp(int $time)
  */
 class TwoFAccountReadResource extends TwoFAccountStoreResource

+ 1 - 1
app/Console/Commands/ResetTesting.php

@@ -48,7 +48,7 @@ class ResetTesting extends Command
     public function handle()
     {
         $this->callSilently('config:clear');
-        
+
         if (! config('2fauth.config.isTestingApp') && ! $this->option('force')) {
             $this->comment('2fauth:reset-testing can only run when isTestingApp option is On');
 

+ 1 - 1
app/Listeners/CleanIconStorage.php

@@ -26,7 +26,7 @@ class CleanIconStorage
     public function handle(TwoFAccountDeleted $event)
     {
         IconStore::delete($event->twofaccount->icon ?? []);
-        
+
         Log::info(sprintf('Icon cleaned for deleted TwoFAccount #%d', $event->twofaccount->id));
     }
 }

+ 2 - 4
app/Listeners/ToggleIconReplicationToDatabase.php

@@ -10,14 +10,12 @@ class ToggleIconReplicationToDatabase
     /**
      * Create the event listener.
      */
-    public function __construct()
-    {
-    }
+    public function __construct() {}
 
     /**
      * Handle the event.
      */
-    public function handle(storeIconsInDatabaseSettingChanged $event): void
+    public function handle(storeIconsInDatabaseSettingChanged $event) : void
     {
         IconStore::setDatabaseReplication($event->newValue);
     }

+ 2 - 0
app/Models/AuthLog.php

@@ -43,7 +43,9 @@ use Illuminate\Database\Eloquent\Relations\MorphTo;
  * @property string|null $method
  * @property string|null $login_method
  * @property-read Model|\Eloquent $authenticatable
+ *
  * @mixin \Eloquent
+ *
  * @method static \Database\Factories\AuthLogFactory factory($count = null, $state = [])
  * @method static \Illuminate\Database\Eloquent\Builder|AuthLog newModelQuery()
  * @method static \Illuminate\Database\Eloquent\Builder|AuthLog newQuery()

+ 3 - 0
app/Models/Group.php

@@ -20,6 +20,7 @@ use Illuminate\Support\Facades\Log;
  * @property int|null $user_id
  * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\TwoFAccount[] $twofaccounts
  * @property-read \App\Models\User|null $user
+ *
  * @method static \Database\Factories\GroupFactory factory(...$parameters)
  * @method static \Illuminate\Database\Eloquent\Builder|Group newModelQuery()
  * @method static \Illuminate\Database\Eloquent\Builder|Group newQuery()
@@ -29,7 +30,9 @@ use Illuminate\Support\Facades\Log;
  * @method static \Illuminate\Database\Eloquent\Builder|Group whereName($value)
  * @method static \Illuminate\Database\Eloquent\Builder|Group whereUpdatedAt($value)
  * @method static \Illuminate\Database\Eloquent\Builder|Group whereUserId($value)
+ *
  * @mixin \Eloquent
+ *
  * @method static \Illuminate\Database\Eloquent\Builder|Group orphans()
  */
 class Group extends Model

+ 4 - 4
app/Models/Icon.php

@@ -17,6 +17,7 @@ use Illuminate\Support\Facades\App;
  * @property \Illuminate\Support\Carbon|null $created_at
  * @property \Illuminate\Support\Carbon|null $updated_at
  * @property-read \App\Models\TwoFAccount|null $twofaccount
+ *
  * @method static \Database\Factories\IconFactory factory($count = null, $state = [])
  * @method static \Illuminate\Database\Eloquent\Builder|Icon newModelQuery()
  * @method static \Illuminate\Database\Eloquent\Builder|Icon newQuery()
@@ -31,7 +32,7 @@ class Icon extends Model
     /**
      * @use HasFactory<IconFactory>
      */
-    use HasFactory, CanEncryptField;
+    use CanEncryptField, HasFactory;
 
     /**
      * The primary key for the model.
@@ -40,7 +41,6 @@ class Icon extends Model
      */
     protected $primaryKey = 'name';
 
-
     /**
      * The "type" of the primary key ID.
      *
@@ -57,7 +57,7 @@ class Icon extends Model
 
     /**
      * Get the twofaccount that owns the icon.
-     * 
+     *
      * @return BelongsTo<\App\Models\TwoFAccount, \App\Models\Icon>
      */
     public function twofaccount() : BelongsTo
@@ -71,7 +71,7 @@ class Icon extends Model
      * @var array
      */
     protected $attributes = [];
-    
+
     /**
      * The attributes that should be hidden for arrays.
      *

+ 2 - 0
app/Models/Option.php

@@ -10,12 +10,14 @@ use Illuminate\Database\Eloquent\Model;
  * @property int $id
  * @property string $key
  * @property string $value
+ *
  * @method static \Illuminate\Database\Eloquent\Builder|Option newModelQuery()
  * @method static \Illuminate\Database\Eloquent\Builder|Option newQuery()
  * @method static \Illuminate\Database\Eloquent\Builder|Option query()
  * @method static \Illuminate\Database\Eloquent\Builder|Option whereId($value)
  * @method static \Illuminate\Database\Eloquent\Builder|Option whereKey($value)
  * @method static \Illuminate\Database\Eloquent\Builder|Option whereValue($value)
+ *
  * @mixin \Eloquent
  */
 class Option extends Model

+ 6 - 3
app/Models/TwoFAccount.php

@@ -70,8 +70,11 @@ use SteamTotp\SteamTotp;
  * @method static \Illuminate\Database\Eloquent\Builder|TwoFAccount whereService($value)
  * @method static \Illuminate\Database\Eloquent\Builder|TwoFAccount whereUpdatedAt($value)
  * @method static \Illuminate\Database\Eloquent\Builder|TwoFAccount whereUserId($value)
+ *
  * @mixin \Eloquent
+ *
  * @property-read \App\Models\Icon|null $iconResource
+ *
  * @method static \Illuminate\Database\Eloquent\Builder|TwoFAccount orphans()
  */
 class TwoFAccount extends Model implements Sortable
@@ -79,7 +82,7 @@ class TwoFAccount extends Model implements Sortable
     /**
      * @use HasFactory<TwoFAccountFactory>
      */
-    use HasFactory, SortableTrait, CanEncryptField;
+    use CanEncryptField, HasFactory, SortableTrait;
 
     const TOTP = 'totp';
 
@@ -233,10 +236,10 @@ class TwoFAccount extends Model implements Sortable
 
     /**
      * Get the relation between the icon resource and the model.
-     * 
+     *
      * @return HasOne<\App\Models\Icon>
      */
-    public function iconResource(): HasOne
+    public function iconResource() : HasOne
     {
         return $this->hasOne(Icon::class, 'name', 'icon');
     }

+ 3 - 0
app/Models/User.php

@@ -47,6 +47,7 @@ use Laravel\Passport\HasApiTokens;
  * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\AuthLog> $authentications
  * @property-read int|null $authentications_count
  * @property-read \App\Models\AuthLog|null $latestAuthentication
+ *
  * @method static \Illuminate\Database\Eloquent\Builder|User admins()
  * @method static \Database\Factories\UserFactory factory(...$parameters)
  * @method static \Illuminate\Database\Eloquent\Builder|User newModelQuery()
@@ -63,7 +64,9 @@ use Laravel\Passport\HasApiTokens;
  * @method static \Illuminate\Database\Eloquent\Builder|User wherePreferences($value)
  * @method static \Illuminate\Database\Eloquent\Builder|User whereRememberToken($value)
  * @method static \Illuminate\Database\Eloquent\Builder|User whereUpdatedAt($value)
+ *
  * @mixin \Eloquent
+ *
  * @method static \Illuminate\Database\Eloquent\Builder|User whereOauthId($value)
  * @method static \Illuminate\Database\Eloquent\Builder|User whereOauthProvider($value)
  */

+ 2 - 2
app/Providers/EventServiceProvider.php

@@ -4,8 +4,8 @@ namespace App\Providers;
 
 use App\Events\GroupDeleted;
 use App\Events\GroupDeleting;
-use App\Events\storeIconsInDatabaseSettingChanged;
 use App\Events\ScanForNewReleaseCalled;
+use App\Events\storeIconsInDatabaseSettingChanged;
 use App\Events\TwoFAccountDeleted;
 use App\Events\VisitedByProxyUser;
 use App\Listeners\Authentication\FailedLoginListener;
@@ -15,10 +15,10 @@ use App\Listeners\Authentication\VisitedByProxyUserListener;
 use App\Listeners\CleanIconStorage;
 use App\Listeners\DissociateTwofaccountFromGroup;
 use App\Listeners\LogNotificationListener;
-use App\Listeners\ToggleIconReplicationToDatabase;
 use App\Listeners\RegisterOpenId;
 use App\Listeners\ReleaseRadar;
 use App\Listeners\ResetUsersPreference;
+use App\Listeners\ToggleIconReplicationToDatabase;
 use App\Models\User;
 use App\Observers\UserObserver;
 use Illuminate\Auth\Events\Failed;

+ 1 - 1
app/Providers/TwoFAuthServiceProvider.php

@@ -3,8 +3,8 @@
 namespace App\Providers;
 
 use App\Factories\MigratorFactoryInterface;
-use App\Services\IconStoreService;
 use App\Services\IconService;
+use App\Services\IconStoreService;
 use App\Services\LogoService;
 use App\Services\ReleaseRadarService;
 use App\Services\SettingService;

+ 6 - 6
app/Services/IconService.php

@@ -23,7 +23,7 @@ class IconService
 
     /**
      * Build an icon from an image resource
-     * 
+     *
      * @param  \Psr\Http\Message\StreamInterface|\Illuminate\Http\File|\Illuminate\Http\UploadedFile|string|resource  $resource
      * @param  string  $extension  The file extension, without the dot
      */
@@ -49,7 +49,7 @@ class IconService
     }
 
     /**
-     * Build an icon by fetching an image file on the internet 
+     * Build an icon by fetching an image file on the internet
      */
     public function buildFromRemoteImage(string $url) : ?string
     {
@@ -67,8 +67,8 @@ class IconService
     protected function storeRemoteImage(string $url) : ?string
     {
         try {
-            $path_parts  = pathinfo($url);
-            $filename = Helpers::getRandomFilename($path_parts['extension']);
+            $path_parts = pathinfo($url);
+            $filename   = Helpers::getRandomFilename($path_parts['extension']);
 
             try {
                 $response = Http::withOptions([
@@ -80,7 +80,7 @@ class IconService
                 }
             } catch (\Exception $exception) {
                 Log::error(sprintf('Cannot fetch imageLink at "%s"', $url));
-                
+
                 return null;
             }
 
@@ -129,7 +129,7 @@ class IconService
             'image/x-ms-bmp',
             'image/svg+xml',
         ];
-        
+
         $isValid = in_array($mimeType, $acceptedMimeTypes)
             && ($mimeType !== 'image/svg+xml' ? getimagesize(Storage::disk('temp')->path($filename)) : true)
             && Str::contains($mimeType, $extension, true);

+ 7 - 8
app/Services/IconStoreService.php

@@ -19,7 +19,7 @@ class IconStoreService
     /**
      * The storage disk to use
      */
-    protected string|null $disk;
+    protected ?string $disk;
 
     /**
      * Icon replication to database to ease backup
@@ -73,8 +73,7 @@ class IconStoreService
             if ($usesDatabase) {
                 $this->clearDatabase();
                 $this->mirrorDiskToDatabase();
-            }
-            else {
+            } else {
                 $this->mirrorDatabaseToDisk();
                 $this->clearDatabase();
             }
@@ -98,7 +97,7 @@ class IconStoreService
             DB::commit();
         } catch (\Exception $e) {
             DB::rollback();
-            
+
             throw new FailedIconStoreDatabaseTogglingException;
         }
     }
@@ -117,14 +116,14 @@ class IconStoreService
 
     /**
      * Get the list of all icon names registered in the TwoFAccount table
-     * 
+     *
      * @return Collection<array-key, mixed>
      */
     protected function registeredIcons()
     {
         return TwoFAccount::whereNotNull('icon')->pluck('icon');
     }
-    
+
     /**
      * Get the content of a given icon resource, prior to the database record
      */
@@ -189,7 +188,7 @@ class IconStoreService
         $names = is_array($names) ? $names : func_get_args();
 
         $deletedFromDisk = $this->disk()->delete($names);
-        
+
         if ($deletedFromDisk && $this->usesDatabase) {
             Icon::destroy($names);
 
@@ -206,7 +205,7 @@ class IconStoreService
     {
         $storedToDisk = $this->storeToDisk($name, $content);
 
-        if ($this->usesDatabase) {    
+        if ($this->usesDatabase) {
             return $this->storeToDatabase($name, $content);
         }
 

+ 2 - 2
app/Services/LogoService.php

@@ -9,7 +9,7 @@ use Illuminate\Support\Facades\Log;
 use Illuminate\Support\Facades\Storage;
 
 class LogoService
-{    
+{
     /**
      * @var \Illuminate\Support\Collection<string, string>
      */
@@ -157,7 +157,7 @@ class LogoService
      *
      * @param  string  $logoFilename
      * @param  string  $iconFilename
-     * @return bool  Whether the copy succeed or not
+     * @return bool Whether the copy succeed or not
      */
     protected function copyToIconStore($logoFilename, $iconFilename) : bool
     {

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

@@ -3,8 +3,8 @@
 namespace App\Services\Migrators;
 
 use App\Exceptions\InvalidMigrationDataException;
-use App\Services\IconService;
 use App\Models\TwoFAccount;
+use App\Services\IconService;
 use Illuminate\Support\Arr;
 use Illuminate\Support\Collection;
 use Illuminate\Support\Facades\App;
@@ -39,7 +39,7 @@ class AegisMigrator extends Migrator
     public function migrate(mixed $migrationPayload) : Collection
     {
         $iconService = App::make(IconService::class);
-        $json = json_decode(htmlspecialchars_decode($migrationPayload), true);
+        $json        = json_decode(htmlspecialchars_decode($migrationPayload), true);
 
         if (is_null($json) || Arr::has($json, 'db.entries') == false) {
             Log::error('Aegis JSON migration data cannot be read');

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

@@ -3,8 +3,8 @@
 namespace App\Services\Migrators;
 
 use App\Exceptions\InvalidMigrationDataException;
-use App\Services\IconService;
 use App\Models\TwoFAccount;
+use App\Services\IconService;
 use Illuminate\Support\Arr;
 use Illuminate\Support\Collection;
 use Illuminate\Support\Facades\App;
@@ -43,7 +43,7 @@ class TwoFAuthMigrator extends Migrator
     public function migrate(mixed $migrationPayload) : Collection
     {
         $iconService = App::make(IconService::class);
-        $json = json_decode(htmlspecialchars_decode($migrationPayload), true);
+        $json        = json_decode(htmlspecialchars_decode($migrationPayload), true);
 
         if (is_null($json)) {
             Log::error('2FAuth JSON migration data cannot be read');

+ 3 - 3
tests/Api/v1/Controllers/IconControllerTest.php

@@ -34,7 +34,7 @@ class IconControllerTest extends FeatureTestCase
 
         Storage::fake('icons');
         Storage::fake('logos');
-        
+
         Http::preventStrayRequests();
         Http::fake([
             LogoService::TFA_IMG_URL . '*' => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200),
@@ -51,7 +51,7 @@ class IconControllerTest extends FeatureTestCase
     public function test_upload_icon_returns_filename_using_the_iconStore()
     {
         $iconName = 'testIcon.jpg';
-        $file = UploadedFile::fake()->image($iconName);
+        $file     = UploadedFile::fake()->image($iconName);
 
         $response = $this->actingAs($this->user, 'api-guard')
             ->json('POST', '/api/v1/icons', [
@@ -111,7 +111,7 @@ class IconControllerTest extends FeatureTestCase
     public function test_delete_icon_returns_success_using_the_iconStore()
     {
         IconStore::spy();
-        
+
         $iconName = 'testIcon.jpg';
 
         $response = $this->actingAs($this->user, 'api-guard')

+ 1 - 1
tests/Api/v1/Controllers/TwoFAccountControllerTest.php

@@ -237,7 +237,7 @@ class TwoFAccountControllerTest extends FeatureTestCase
         Storage::fake('icons');
         Storage::fake('logos');
         Storage::fake('imagesLink');
-        
+
         Http::preventStrayRequests();
         Http::fake([
             LogoService::TFA_IMG_URL . '*' => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200),

+ 13 - 13
tests/Api/v1/Requests/TwoFAccountExportRequestTest.php

@@ -48,30 +48,30 @@ class TwoFAccountExportRequestTest extends TestCase
     {
         return [
             [[
-                'ids' => '1',
+                'ids'     => '1',
                 'otpauth' => '1',
             ]],
             [[
-                'ids' => '1',
+                'ids'     => '1',
                 'otpauth' => 1,
             ]],
             [[
-                'ids' => '1',
+                'ids'     => '1',
                 'otpauth' => true,
             ]],
             [[
                 'ids' => '1',
             ]],
             [[
-                'ids' => '1',
+                'ids'     => '1',
                 'otpauth' => '0',
             ]],
             [[
-                'ids' => '1',
+                'ids'     => '1',
                 'otpauth' => 0,
             ]],
             [[
-                'ids' => '1',
+                'ids'     => '1',
                 'otpauth' => false,
             ]],
         ];
@@ -94,31 +94,31 @@ class TwoFAccountExportRequestTest extends TestCase
     {
         return [
             [[
-                'ids' => '1',
+                'ids'     => '1',
                 'otpauth' => null,
             ]],
             [[
-                'ids' => '1',
+                'ids'     => '1',
                 'otpauth' => '',
             ]],
             [[
-                'ids' => '1',
+                'ids'     => '1',
                 'otpauth' => 2,
             ]],
             [[
-                'ids' => '1',
+                'ids'     => '1',
                 'otpauth' => 'string',
             ]],
             [[
-                'ids' => '1',
+                'ids'     => '1',
                 'otpauth' => 0.1,
             ]],
             [[
-                'ids' => '1',
+                'ids'     => '1',
                 'otpauth' => '01/01/2020',
             ]],
             [[
-                'ids' => '1',
+                'ids'     => '1',
                 'otpauth' => '01',
             ]],
         ];

+ 2 - 2
tests/Feature/Models/TwoFAccountModelTest.php

@@ -49,7 +49,7 @@ class TwoFAccountModelTest extends FeatureTestCase
 
         Storage::fake('imagesLink');
         Storage::fake('icons');
-        
+
         Http::preventStrayRequests();
 
         /** @var \Illuminate\Contracts\Auth\Authenticatable $user */
@@ -671,7 +671,7 @@ class TwoFAccountModelTest extends FeatureTestCase
         Http::fake([
             OtpTestData::EXTERNAL_IMAGE_URL_DECODED => Http::response(HttpRequestTestData::ICON_PNG, 200),
         ]);
-        
+
         $orphan = new TwoFAccount;
         $orphan->fillWithURI(OtpTestData::HOTP_FULL_CUSTOM_URI);
         $orphan->save();

+ 1 - 2
tests/Feature/Models/UserModelTest.php

@@ -4,7 +4,6 @@ namespace Tests\Feature\Models;
 
 use App\Facades\IconStore;
 use App\Models\AuthLog;
-use App\Models\Dto\IconDto;
 use App\Models\Group;
 use App\Models\TwoFAccount;
 use App\Models\User;
@@ -174,7 +173,7 @@ class UserModelTest extends FeatureTestCase
             'icon' => OtpTestData::ICON_PNG,
         ]);
         IconStore::store(OtpTestData::ICON_PNG, base64_decode(OtpTestData::ICON_PNG_DATA));
-        
+
         Storage::disk('icons')->assertExists($twofaccount->icon);
 
         $user->delete();

+ 13 - 13
tests/Feature/Services/IconServiceTest.php

@@ -34,11 +34,11 @@ class IconServiceTest extends FeatureTestCase
     public function setUp() : void
     {
         parent::setUp();
-        
+
         Storage::fake('icons');
         Storage::fake('logos');
         Storage::fake('imagesLink');
-        
+
         Http::preventStrayRequests();
         Http::fake([
             LogoService::TFA_IMG_URL . '*' => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200),
@@ -63,11 +63,11 @@ class IconServiceTest extends FeatureTestCase
     #[Test]
     public function test_buildFromResource_stores_icon_and_returns_name()
     {
-        $resource = base64_decode(OtpTestData::ICON_PNG_DATA);
+        $resource  = base64_decode(OtpTestData::ICON_PNG_DATA);
         $extension = 'png';
 
         $this->iconService = $this->app->make(IconService::class);
-        $iconName = $this->iconService->buildFromResource($resource, $extension);
+        $iconName          = $this->iconService->buildFromResource($resource, $extension);
 
         Storage::disk('icons')->assertExists($iconName);
         $this->assertEquals($resource, Storage::disk('icons')->get($iconName));
@@ -80,7 +80,7 @@ class IconServiceTest extends FeatureTestCase
             ->andReturn(false);
 
         $this->iconService = $this->app->make(IconService::class);
-        $iconName = $this->iconService->buildFromResource('lorem', 'ipsum');
+        $iconName          = $this->iconService->buildFromResource('lorem', 'ipsum');
 
         $this->assertNull($iconName);
     }
@@ -90,7 +90,7 @@ class IconServiceTest extends FeatureTestCase
     public function test_buildFromResource_with_bad_inputs_returns_null($resource, $extension)
     {
         $this->iconService = $this->app->make(IconService::class);
-        $iconName = $this->iconService->buildFromResource($resource, $extension);
+        $iconName          = $this->iconService->buildFromResource($resource, $extension);
 
         $this->assertNull($iconName);
     }
@@ -149,7 +149,7 @@ class IconServiceTest extends FeatureTestCase
         ]);
 
         $this->iconService = $this->app->make(IconService::class);
-        $iconName = $this->iconService->buildFromRemoteImage($imageUrl);
+        $iconName          = $this->iconService->buildFromRemoteImage($imageUrl);
 
         Storage::disk('icons')->assertExists($iconName);
         Storage::disk('imagesLink')->assertMissing($iconName);
@@ -174,7 +174,7 @@ class IconServiceTest extends FeatureTestCase
             ->andReturn(false);
 
         $this->iconService = $this->app->make(IconService::class);
-        $iconName = $this->iconService->buildFromRemoteImage($imageUrl);
+        $iconName          = $this->iconService->buildFromRemoteImage($imageUrl);
 
         $this->assertNull($iconName);
     }
@@ -203,11 +203,11 @@ class IconServiceTest extends FeatureTestCase
         Http::fake([
             'example.com/*' => Http::response(null, 400),
         ]);
-        
+
         $imageUrl = 'https://www.example.com/image.png';
 
         $this->iconService = $this->app->make(IconService::class);
-        $iconName = $this->iconService->buildFromRemoteImage($imageUrl);
+        $iconName          = $this->iconService->buildFromRemoteImage($imageUrl);
 
         $this->assertNull($iconName);
     }
@@ -223,7 +223,7 @@ class IconServiceTest extends FeatureTestCase
         ]);
 
         $this->iconService = $this->app->make(IconService::class);
-        $iconName = $this->iconService->buildFromRemoteImage($imageUrl);
+        $iconName          = $this->iconService->buildFromRemoteImage($imageUrl);
 
         $this->assertNull($iconName);
     }
@@ -240,8 +240,8 @@ class IconServiceTest extends FeatureTestCase
         ]);
 
         $this->iconService = $this->app->make(IconService::class);
-        $iconName = $this->iconService->buildFromRemoteImage($imageUrl);
+        $iconName          = $this->iconService->buildFromRemoteImage($imageUrl);
 
         $this->assertNull($iconName);
     }
-}
+}

+ 35 - 35
tests/Feature/Services/IconStoreServiceTest.php

@@ -40,7 +40,7 @@ class IconStoreServiceTest extends FeatureTestCase
         Storage::fake('icons');
         $this->iconStore = $this->app->make(IconStoreService::class);
     }
-    
+
     #[Test]
     public function test_get_returns_icon_content()
     {
@@ -90,7 +90,7 @@ class IconStoreServiceTest extends FeatureTestCase
 
         $this->assertStringContainsStringIgnoringCase($mimeType, $expected);
     }
-    
+
     /**
      * Provide data for index tests
      */
@@ -115,7 +115,7 @@ class IconStoreServiceTest extends FeatureTestCase
             'BPM' => [
                 OtpTestData::ICON_BMP,
                 OtpTestData::ICON_BMP_DATA,
-                'image/bmp|image/x-ms-bmp'
+                'image/bmp|image/x-ms-bmp',
             ],
             'SVG' => [
                 OtpTestData::ICON_SVG,
@@ -140,7 +140,7 @@ class IconStoreServiceTest extends FeatureTestCase
     {
         $this->assertFalse($this->iconStore->mimeType(OtpTestData::ICON_PNG));
     }
-    
+
     #[Test]
     public function test_mimeType_returns_null_when_nothing_is_requested()
     {
@@ -183,10 +183,10 @@ class IconStoreServiceTest extends FeatureTestCase
         Storage::disk('icons')->assertExists(OtpTestData::ICON_PNG);
         Storage::disk('icons')->assertExists(OtpTestData::ICON_JPEG);
         $this->assertDatabaseHas('icons', [
-            'name'    => OtpTestData::ICON_PNG,
+            'name' => OtpTestData::ICON_PNG,
         ]);
         $this->assertDatabaseHas('icons', [
-            'name'    => OtpTestData::ICON_JPEG,
+            'name' => OtpTestData::ICON_JPEG,
         ]);
 
         $result = $this->iconStore->clear();
@@ -218,10 +218,10 @@ class IconStoreServiceTest extends FeatureTestCase
         ]);
 
         $this->assertDatabaseHas('icons', [
-            'name'    => OtpTestData::ICON_PNG,
+            'name' => OtpTestData::ICON_PNG,
         ]);
         $this->assertDatabaseHas('icons', [
-            'name'    => OtpTestData::ICON_JPEG,
+            'name' => OtpTestData::ICON_JPEG,
         ]);
 
         $result = $this->iconStore->clear();
@@ -272,23 +272,23 @@ class IconStoreServiceTest extends FeatureTestCase
     public function test_delete_deletes_provided_icon_in_database_and_returns_true()
     {
         Settings::set('storeIconsInDatabase', true);
-    
+
         Storage::disk('icons')->put(OtpTestData::ICON_PNG, base64_decode(OtpTestData::ICON_PNG_DATA));
         DB::table('icons')->insert([
             'name'    => OtpTestData::ICON_PNG,
             'content' => OtpTestData::ICON_PNG_DATA,
         ]);
-        
+
         Storage::disk('icons')->assertExists(OtpTestData::ICON_PNG);
         $this->assertDatabaseHas('icons', [
-            'name'    => OtpTestData::ICON_PNG,
+            'name' => OtpTestData::ICON_PNG,
         ]);
 
         $this->iconStore->delete(OtpTestData::ICON_PNG);
 
         Storage::disk('icons')->assertMissing(OtpTestData::ICON_PNG);
         $this->assertDatabaseMissing('icons', [
-            'name'    => OtpTestData::ICON_PNG,
+            'name' => OtpTestData::ICON_PNG,
         ]);
     }
 
@@ -296,21 +296,21 @@ class IconStoreServiceTest extends FeatureTestCase
     public function test_delete_deletes_provided_icon_in_database_when_disk_is_empty()
     {
         Settings::set('storeIconsInDatabase', true);
-    
+
         DB::table('icons')->insert([
             'name'    => OtpTestData::ICON_PNG,
             'content' => OtpTestData::ICON_PNG_DATA,
         ]);
-        
+
         Storage::disk('icons')->assertMissing(OtpTestData::ICON_PNG);
         $this->assertDatabaseHas('icons', [
-            'name'    => OtpTestData::ICON_PNG,
+            'name' => OtpTestData::ICON_PNG,
         ]);
 
         $this->iconStore->delete(OtpTestData::ICON_PNG);
 
         $this->assertDatabaseMissing('icons', [
-            'name'    => OtpTestData::ICON_PNG,
+            'name' => OtpTestData::ICON_PNG,
         ]);
     }
 
@@ -336,7 +336,7 @@ class IconStoreServiceTest extends FeatureTestCase
     public function test_delete_deletes_provided_icons_in_database_and_returns_true()
     {
         Settings::set('storeIconsInDatabase', true);
-    
+
         Storage::disk('icons')->put(OtpTestData::ICON_PNG, base64_decode(OtpTestData::ICON_PNG_DATA));
         Storage::disk('icons')->put(OtpTestData::ICON_JPEG, base64_decode(OtpTestData::ICON_JPEG_DATA));
         DB::table('icons')->insert([
@@ -351,10 +351,10 @@ class IconStoreServiceTest extends FeatureTestCase
         Storage::disk('icons')->assertExists(OtpTestData::ICON_PNG);
         Storage::disk('icons')->assertExists(OtpTestData::ICON_JPEG);
         $this->assertDatabaseHas('icons', [
-            'name'    => OtpTestData::ICON_PNG,
+            'name' => OtpTestData::ICON_PNG,
         ]);
         $this->assertDatabaseHas('icons', [
-            'name'    => OtpTestData::ICON_JPEG,
+            'name' => OtpTestData::ICON_JPEG,
         ]);
 
         $this->iconStore->delete([
@@ -365,10 +365,10 @@ class IconStoreServiceTest extends FeatureTestCase
         Storage::disk('icons')->assertMissing(OtpTestData::ICON_PNG);
         Storage::disk('icons')->assertMissing(OtpTestData::ICON_JPEG);
         $this->assertDatabaseMissing('icons', [
-            'name'    => OtpTestData::ICON_PNG,
+            'name' => OtpTestData::ICON_PNG,
         ]);
         $this->assertDatabaseMissing('icons', [
-            'name'    => OtpTestData::ICON_JPEG,
+            'name' => OtpTestData::ICON_JPEG,
         ]);
     }
 
@@ -376,7 +376,7 @@ class IconStoreServiceTest extends FeatureTestCase
     public function test_delete_deletes_provided_icons_in_database_when_disk_is_empty()
     {
         Settings::set('storeIconsInDatabase', true);
-    
+
         DB::table('icons')->insert([
             'name'    => OtpTestData::ICON_PNG,
             'content' => OtpTestData::ICON_PNG_DATA,
@@ -389,10 +389,10 @@ class IconStoreServiceTest extends FeatureTestCase
         Storage::disk('icons')->assertMissing(OtpTestData::ICON_PNG);
         Storage::disk('icons')->assertMissing(OtpTestData::ICON_JPEG);
         $this->assertDatabaseHas('icons', [
-            'name'    => OtpTestData::ICON_PNG,
+            'name' => OtpTestData::ICON_PNG,
         ]);
         $this->assertDatabaseHas('icons', [
-            'name'    => OtpTestData::ICON_JPEG,
+            'name' => OtpTestData::ICON_JPEG,
         ]);
 
         $this->iconStore->delete([
@@ -401,10 +401,10 @@ class IconStoreServiceTest extends FeatureTestCase
         ]);
 
         $this->assertDatabaseMissing('icons', [
-            'name'    => OtpTestData::ICON_PNG,
+            'name' => OtpTestData::ICON_PNG,
         ]);
         $this->assertDatabaseMissing('icons', [
-            'name'    => OtpTestData::ICON_JPEG,
+            'name' => OtpTestData::ICON_JPEG,
         ]);
     }
 
@@ -458,7 +458,7 @@ class IconStoreServiceTest extends FeatureTestCase
 
         Storage::disk('icons')->assertMissing(OtpTestData::ICON_PNG);
         $this->assertDatabaseMissing('icons', [
-            'name'    => OtpTestData::ICON_PNG,
+            'name' => OtpTestData::ICON_PNG,
         ]);
 
         $result = $this->iconStore->store(OtpTestData::ICON_PNG, base64_decode(OtpTestData::ICON_PNG_DATA));
@@ -466,7 +466,7 @@ class IconStoreServiceTest extends FeatureTestCase
         $this->assertTrue($result);
         Storage::disk('icons')->assertExists(OtpTestData::ICON_PNG);
         $this->assertDatabaseHas('icons', [
-            'name'    => OtpTestData::ICON_PNG,
+            'name' => OtpTestData::ICON_PNG,
         ]);
     }
 
@@ -481,7 +481,7 @@ class IconStoreServiceTest extends FeatureTestCase
         Storage::shouldReceive('disk->put')
             ->with($iconName, $iconContent)
             ->andReturn(false);
-        
+
         $result = $this->iconStore->store($iconName, $iconContent);
 
         $this->assertFalse($result);
@@ -553,7 +553,7 @@ class IconStoreServiceTest extends FeatureTestCase
     #[Test]
     public function test_setDatabaseReplication_stores_only_registered_icon_to_database()
     {
-        $user  = User::factory()->create();
+        $user = User::factory()->create();
 
         TwoFAccount::factory()->for($user)->create([
             'icon' => OtpTestData::ICON_PNG,
@@ -594,7 +594,7 @@ class IconStoreServiceTest extends FeatureTestCase
     #[Test]
     public function test_setDatabaseReplication_skips_icon_when_file_is_missing()
     {
-        $user  = User::factory()->create();
+        $user = User::factory()->create();
 
         TwoFAccount::factory()->for($user)->create([
             'icon' => OtpTestData::ICON_PNG,
@@ -644,7 +644,7 @@ class IconStoreServiceTest extends FeatureTestCase
     {
         Settings::set('storeIconsInDatabase', true);
 
-        $user  = User::factory()->create();
+        $user = User::factory()->create();
 
         TwoFAccount::factory()->for($user)->create([
             'icon' => OtpTestData::ICON_PNG,
@@ -721,9 +721,9 @@ class IconStoreServiceTest extends FeatureTestCase
         ]);
 
         Storage::shouldReceive('disk->put')
-        ->once()
-        ->andThrow(new FailedIconStoreDatabaseTogglingException);
-        
+            ->once()
+            ->andThrow(new FailedIconStoreDatabaseTogglingException);
+
         $this->expectException(FailedIconStoreDatabaseTogglingException::class);
 
         Settings::set('storeIconsInDatabase', false);

+ 2 - 2
tests/Feature/Services/LogoServiceTest.php

@@ -52,7 +52,7 @@ class LogoServiceTest extends FeatureTestCase
         Http::preventStrayRequests();
         Http::fake([
             LogoService::TFA_IMG_URL . '*' => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200),
-            LogoService::TFA_URL => Http::response('not found', 404),
+            LogoService::TFA_URL           => Http::response('not found', 404),
         ]);
 
         $this->logoService = $this->app->make(LogoService::class);
@@ -97,7 +97,7 @@ class LogoServiceTest extends FeatureTestCase
         Http::preventStrayRequests();
         Http::fake([
             LogoService::TFA_IMG_URL . '*' => Http::response(HttpRequestTestData::SVG_LOGO_BODY, 200),
-            LogoService::TFA_URL => Http::response('not found', 404),
+            LogoService::TFA_URL           => Http::response('not found', 404),
         ]);
 
         $this->logoService = $this->app->make(LogoService::class);

+ 1 - 3
tests/Feature/Services/SettingServiceTest.php

@@ -8,13 +8,11 @@ use App\Facades\IconStore;
 use App\Facades\Settings;
 use App\Models\Icon;
 use App\Models\TwoFAccount;
-use App\Services\IconStoreService;
 use App\Services\SettingService;
 use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Facades\Crypt;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Event;
-use Mockery\MockInterface;
 use PHPUnit\Framework\Attributes\CoversClass;
 use PHPUnit\Framework\Attributes\DataProvider;
 use PHPUnit\Framework\Attributes\Test;
@@ -396,7 +394,7 @@ class SettingServiceTest extends FeatureTestCase
     public function test_set_storeIconsInDatabase_is_cancelled_if_database_toggling_failed()
     {
         $this->expectException(FailedIconStoreDatabaseTogglingException::class);
-        
+
         $newValue = true;
 
         IconStore::shouldReceive('setDatabaseReplication')

+ 1 - 1
tests/Unit/Events/storeIconsInDatabaseSettingChangedTest.php

@@ -17,7 +17,7 @@ class storeIconsInDatabaseSettingChangedTest extends TestCase
     public function test_event_constructor()
     {
         $newValue = true;
-        $event = new storeIconsInDatabaseSettingChanged($newValue);
+        $event    = new storeIconsInDatabaseSettingChanged($newValue);
 
         $this->assertSame($newValue, $event->newValue);
     }

+ 1 - 2
tests/Unit/Listeners/CleanIconStorageTest.php

@@ -3,7 +3,6 @@
 namespace Tests\Unit\Listeners;
 
 use App\Events\TwoFAccountDeleted;
-use App\Facades\Settings;
 use App\Listeners\CleanIconStorage;
 use App\Models\TwoFAccount;
 use App\Services\IconStoreService;
@@ -42,7 +41,7 @@ class CleanIconStorageTest extends TestCase
                 ->with($event->twofaccount->icon)
                 ->andReturn(true);
         });
-        
+
         /**
          * @disregard P1009 Undefined type
          */

+ 3 - 4
tests/Unit/MigratorTest.php

@@ -6,7 +6,6 @@ use App\Exceptions\EncryptedMigrationException;
 use App\Exceptions\InvalidMigrationDataException;
 use App\Exceptions\UnsupportedMigrationException;
 use App\Facades\Icons;
-use App\Facades\IconStore;
 use App\Factories\MigratorFactory;
 use App\Models\TwoFAccount;
 use App\Providers\MigrationServiceProvider;
@@ -416,13 +415,13 @@ class MigratorTest extends TestCase
     {
         Icons::spy();
         Storage::fake('icons');
-        
+
         $migrator = new TwoFAuthMigrator;
         $accounts = $migrator->migrate($migration);
-        
+
         $this->assertContainsOnlyInstancesOf(TwoFAccount::class, $accounts);
         $this->assertCount(1, $accounts);
-        
+
         Icons::shouldHaveReceived('buildFromResource')->once();
         Storage::disk('icons')->assertExists($accounts->first()->icon);
     }

+ 1 - 1
tests/Unit/TwoFAccountModelTest.php

@@ -149,7 +149,7 @@ class TwoFAccountModelTest extends ModelTestCase
     #[Test]
     public function test_twofaccount_relation()
     {
-        $model    = new Icon();
+        $model    = new Icon;
         $relation = $model->twofaccount();
 
         $this->assertInstanceOf(BelongsTo::class, $relation);