Complete phpDocs type-hints

This commit is contained in:
Bubka 2022-11-21 11:16:43 +01:00
parent 616a9348b2
commit d84dd6659e
16 changed files with 35 additions and 27 deletions

View File

@ -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,

View File

@ -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<int|string, TwoFAccountReadResource>
*/
public function toArray($request)
{

View File

@ -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 */
]);
}
}

View File

@ -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<TwoFAccount>
*/
public function twofaccounts()
{

View File

@ -14,7 +14,7 @@ class GroupService
/**
* Returns all existing groups
*
* @return Collection
* @return Collection<int, Group>
*/
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<int, TwoFAccount> The assigned accounts
*/
public static function getAccounts(Group $group) : Collection
{

View File

@ -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<string, string>
*/
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"]

View File

@ -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<int|string, \App\Models\TwoFAccount> The converted accounts
*/
public function migrate(mixed $migrationPayload) : Collection
{

View File

@ -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<int|string, \App\Models\TwoFAccount> The converted accounts
*/
public function migrate(mixed $migrationPayload) : Collection
{

View File

@ -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<int|string, \App\Models\TwoFAccount> The converted accounts
*/
abstract public function migrate(mixed $migrationPayload) : Collection;

View File

@ -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<int|string, \App\Models\TwoFAccount> The converted accounts
*/
public function migrate(mixed $migrationPayload) : Collection
{

View File

@ -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<int|string, \App\Models\TwoFAccount> The converted accounts
*/
public function migrate(mixed $migrationPayload) : Collection
{

View File

@ -19,7 +19,7 @@ class SettingService
/**
* All user settings
*
* @var Collection
* @var Collection<string, mixed>
*/
private Collection $settings;
@ -48,7 +48,7 @@ public function get($setting)
/**
* Get all settings
*
* @return Collection the Settings collection
* @return Collection<string, mixed> 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';

View File

@ -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<int|string, TwoFAccount> 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<int|string, TwoFAccount> $twofaccounts
* @return \Illuminate\Support\Collection<int|string, TwoFAccount>
*/
private static function markAsDuplicate(Collection $twofaccounts) : Collection
{

View File

@ -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
{
/**

View File

@ -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
{
/**

View File

@ -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()
{