From d84dd6659ee887e28c145ee80d00bfdd3e740c89 Mon Sep 17 00:00:00 2001 From: Bubka <858858+Bubka@users.noreply.github.com> Date: Mon, 21 Nov 2022 11:16:43 +0100 Subject: [PATCH] Complete phpDocs type-hints --- app/Api/v1/Controllers/SettingController.php | 2 +- app/Api/v1/Resources/TwoFAccountCollection.php | 5 +++-- app/Http/Controllers/SinglePageController.php | 2 +- app/Models/Group.php | 2 +- app/Services/GroupService.php | 4 ++-- app/Services/LogoService.php | 9 +++++---- app/Services/Migrators/AegisMigrator.php | 2 +- app/Services/Migrators/GoogleAuthMigrator.php | 5 ++--- app/Services/Migrators/Migrator.php | 2 +- app/Services/Migrators/PlainTextMigrator.php | 2 +- app/Services/Migrators/TwoFASMigrator.php | 2 +- app/Services/SettingService.php | 6 +++--- app/Services/TwoFAccountService.php | 6 +++--- database/factories/GroupFactory.php | 4 +++- database/factories/TwoFAccountFactory.php | 4 +++- database/factories/UserFactory.php | 5 ++++- 16 files changed, 35 insertions(+), 27 deletions(-) diff --git a/app/Api/v1/Controllers/SettingController.php b/app/Api/v1/Controllers/SettingController.php index bc2e94e9..02f4e035 100644 --- a/app/Api/v1/Controllers/SettingController.php +++ b/app/Api/v1/Controllers/SettingController.php @@ -18,7 +18,7 @@ class SettingController extends Controller public function index() { $settings = Settings::all(); - $settingsResources = collect(); + $settingsResources = collect([]); $settings->each(function (mixed $item, string $key) use ($settingsResources) { $settingsResources->push([ 'key' => $key, diff --git a/app/Api/v1/Resources/TwoFAccountCollection.php b/app/Api/v1/Resources/TwoFAccountCollection.php index 4da5cf19..5c9a4353 100644 --- a/app/Api/v1/Resources/TwoFAccountCollection.php +++ b/app/Api/v1/Resources/TwoFAccountCollection.php @@ -3,6 +3,7 @@ namespace App\Api\v1\Resources; use Illuminate\Http\Resources\Json\ResourceCollection; +use App\Api\v1\Resources\TwoFAccountReadResource; class TwoFAccountCollection extends ResourceCollection { @@ -11,14 +12,14 @@ class TwoFAccountCollection extends ResourceCollection * * @var string */ - public $collects = 'App\Api\v1\Resources\TwoFAccountReadResource'; + public $collects = TwoFAccountReadResource::class; /** * Transform the resource collection into an array. * * @param \Illuminate\Http\Request $request - * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable + * @return \Illuminate\Support\Collection */ public function toArray($request) { diff --git a/app/Http/Controllers/SinglePageController.php b/app/Http/Controllers/SinglePageController.php index e85190fd..08412b02 100644 --- a/app/Http/Controllers/SinglePageController.php +++ b/app/Http/Controllers/SinglePageController.php @@ -27,7 +27,7 @@ public function index() 'lang' => App::currentLocale(), 'isDemoApp' => config("2fauth.config.isDemoApp") ? 'true' : 'false', 'isTestingApp' => config("2fauth.config.isTestingApp") ? 'true' : 'false', - 'locales' => collect(config("2fauth.locales"))->toJson() + 'locales' => collect(config("2fauth.locales"))->toJson() /** @phpstan-ignore-line */ ]); } } diff --git a/app/Models/Group.php b/app/Models/Group.php index c7b92fac..153e36c6 100644 --- a/app/Models/Group.php +++ b/app/Models/Group.php @@ -79,7 +79,7 @@ protected static function boot() /** * Get the TwoFAccounts of the group. * - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function twofaccounts() { diff --git a/app/Services/GroupService.php b/app/Services/GroupService.php index 46fe024c..d1f29776 100644 --- a/app/Services/GroupService.php +++ b/app/Services/GroupService.php @@ -14,7 +14,7 @@ class GroupService /** * Returns all existing groups * - * @return Collection + * @return Collection */ public static function getAll() : Collection { @@ -147,7 +147,7 @@ public static function assign($ids, Group $group = null) : void * Finds twofaccounts assigned to the group * * @param \App\Models\Group $group The group - * @return Collection The assigned accounts + * @return Collection The assigned accounts */ public static function getAccounts(Group $group) : Collection { diff --git a/app/Services/LogoService.php b/app/Services/LogoService.php index 88bbe37c..25ccfe11 100644 --- a/app/Services/LogoService.php +++ b/app/Services/LogoService.php @@ -2,6 +2,7 @@ namespace App\Services; +use Illuminate\Support\Collection; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Log; @@ -10,7 +11,7 @@ class LogoService { /** - * @var \Illuminate\Support\Collection + * @var \Illuminate\Support\Collection */ protected $tfas; @@ -85,8 +86,8 @@ protected function setTfaCollection() : void } $this->tfas = Storage::disk('logos')->exists(self::TFA_JSON) - ? collect(json_decode(Storage::disk('logos')->get(self::TFA_JSON))) - : collect(); + ? new Collection(json_decode(Storage::disk('logos')->get(self::TFA_JSON))) + : collect([]); } @@ -100,7 +101,7 @@ protected function cacheTfaDirectorySource() : void try { $response = Http::retry(3, 100)->get(self::TFA_URL); - $coll = collect(json_decode(htmlspecialchars_decode($response->body()), true)) + $coll = collect(json_decode(htmlspecialchars_decode($response->body()), true)) /** @phpstan-ignore-line */ ->mapWithKeys(function ($item, $key) { return [ strtolower(head($item)) => $item[1]["domain"] diff --git a/app/Services/Migrators/AegisMigrator.php b/app/Services/Migrators/AegisMigrator.php index 8e622758..76fb5346 100644 --- a/app/Services/Migrators/AegisMigrator.php +++ b/app/Services/Migrators/AegisMigrator.php @@ -38,7 +38,7 @@ class AegisMigrator extends Migrator * Convert migration data to a TwoFAccounts collection. * * @param mixed $migrationPayload - * @return \Illuminate\Support\Collection The converted accounts + * @return \Illuminate\Support\Collection The converted accounts */ public function migrate(mixed $migrationPayload) : Collection { diff --git a/app/Services/Migrators/GoogleAuthMigrator.php b/app/Services/Migrators/GoogleAuthMigrator.php index 3e6c38f5..2907afcf 100644 --- a/app/Services/Migrators/GoogleAuthMigrator.php +++ b/app/Services/Migrators/GoogleAuthMigrator.php @@ -21,10 +21,9 @@ 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 * - * @return \Illuminate\Support\Collection The converted accounts + * @param mixed $migrationPayload migration uri provided by Google Authenticator export feature + * @return \Illuminate\Support\Collection The converted accounts */ public function migrate(mixed $migrationPayload) : Collection { diff --git a/app/Services/Migrators/Migrator.php b/app/Services/Migrators/Migrator.php index a719eaae..c98feff6 100644 --- a/app/Services/Migrators/Migrator.php +++ b/app/Services/Migrators/Migrator.php @@ -10,7 +10,7 @@ abstract class Migrator * Convert migration data to a 2FAccounts collection. * * @param mixed $migrationPayload - * @return \Illuminate\Support\Collection The converted accounts + * @return \Illuminate\Support\Collection The converted accounts */ abstract public function migrate(mixed $migrationPayload) : Collection; diff --git a/app/Services/Migrators/PlainTextMigrator.php b/app/Services/Migrators/PlainTextMigrator.php index 2f100400..14bd627b 100644 --- a/app/Services/Migrators/PlainTextMigrator.php +++ b/app/Services/Migrators/PlainTextMigrator.php @@ -17,7 +17,7 @@ class PlainTextMigrator extends Migrator * Convert migration data to a TwoFAccounts collection. * * @param mixed $migrationPayload - * @return \Illuminate\Support\Collection The converted accounts + * @return \Illuminate\Support\Collection The converted accounts */ public function migrate(mixed $migrationPayload) : Collection { diff --git a/app/Services/Migrators/TwoFASMigrator.php b/app/Services/Migrators/TwoFASMigrator.php index bc10b070..526c0312 100644 --- a/app/Services/Migrators/TwoFASMigrator.php +++ b/app/Services/Migrators/TwoFASMigrator.php @@ -70,7 +70,7 @@ class TwoFASMigrator extends Migrator * Convert migration data to a TwoFAccounts collection. * * @param mixed $migrationPayload - * @return \Illuminate\Support\Collection The converted accounts + * @return \Illuminate\Support\Collection The converted accounts */ public function migrate(mixed $migrationPayload) : Collection { diff --git a/app/Services/SettingService.php b/app/Services/SettingService.php index d903b789..89e5dd72 100644 --- a/app/Services/SettingService.php +++ b/app/Services/SettingService.php @@ -19,7 +19,7 @@ class SettingService /** * All user settings * - * @var Collection + * @var Collection */ private Collection $settings; @@ -48,7 +48,7 @@ public function get($setting) /** * Get all settings * - * @return Collection the Settings collection + * @return Collection the Settings collection */ public function all() : Collection { @@ -122,7 +122,7 @@ private function build() }); // Merge 2fauth/app config values as fallback values - $settings = collect(config('2fauth.options'))->merge($userOptions); + $settings = collect(config('2fauth.options'))->merge($userOptions); /** @phpstan-ignore-line */ if(!Arr::has($settings, 'lang')) { $settings['lang'] = 'browser'; diff --git a/app/Services/TwoFAccountService.php b/app/Services/TwoFAccountService.php index b647b5dd..d711c296 100644 --- a/app/Services/TwoFAccountService.php +++ b/app/Services/TwoFAccountService.php @@ -51,7 +51,7 @@ public static function withdraw($ids) : void * Convert a migration payload to a set of TwoFAccount objects * * @param string $migrationPayload Migration payload from 2FA apps export feature - * @return \Illuminate\Support\Collection The converted accounts + * @return \Illuminate\Support\Collection The converted accounts */ public function migrate(string $migrationPayload) : Collection { @@ -83,8 +83,8 @@ public static function delete($ids) : int /** * Return the given collection with items marked as Duplicates (using id=-1) if a similar record exists in database * - * @param \Illuminate\Support\Collection $twofaccounts - * @return \Illuminate\Support\Collection + * @param \Illuminate\Support\Collection $twofaccounts + * @return \Illuminate\Support\Collection */ private static function markAsDuplicate(Collection $twofaccounts) : Collection { diff --git a/database/factories/GroupFactory.php b/database/factories/GroupFactory.php index c3061ead..69c20de0 100644 --- a/database/factories/GroupFactory.php +++ b/database/factories/GroupFactory.php @@ -3,8 +3,10 @@ namespace Database\Factories; use Illuminate\Database\Eloquent\Factories\Factory; -use Illuminate\Support\Str; +/** + * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Group> + */ class GroupFactory extends Factory { /** diff --git a/database/factories/TwoFAccountFactory.php b/database/factories/TwoFAccountFactory.php index 86082f6c..769071c0 100644 --- a/database/factories/TwoFAccountFactory.php +++ b/database/factories/TwoFAccountFactory.php @@ -4,8 +4,10 @@ use ParagonIE\ConstantTime\Base32; use Illuminate\Database\Eloquent\Factories\Factory; -use Illuminate\Support\Str; +/** + * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\TwoFAccount> + */ class TwoFAccountFactory extends Factory { /** diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 4ed95204..da538393 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -5,6 +5,9 @@ use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Str; +/** + * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User> + */ class UserFactory extends Factory { @@ -29,7 +32,7 @@ public function definition() /** * Indicate that the model's email address should be unverified. * - * @return \Illuminate\Database\Eloquent\Factories\Factory + * @return \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User> */ public function unverified() {