Fix phpstan issues

This commit is contained in:
Bubka 2024-09-26 23:17:00 +02:00
parent d4a06167e5
commit 18fe45778a
4 changed files with 34 additions and 17 deletions

View File

@ -24,13 +24,12 @@
namespace App\Models;
use Database\Factories\AuthLogFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphTo;
/**
*
*
* @property int $id
* @property string $authenticatable_type
* @property int $authenticatable_id
@ -49,6 +48,9 @@ use Illuminate\Database\Eloquent\Relations\MorphTo;
*/
class AuthLog extends Model
{
/**
* @use HasFactory<AuthLogFactory>
*/
use HasFactory;
/**

View File

@ -4,6 +4,7 @@ namespace App\Models;
use App\Events\GroupDeleted;
use App\Events\GroupDeleting;
use Database\Factories\GroupFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Log;
@ -34,6 +35,9 @@ use Illuminate\Support\Facades\Log;
*/
class Group extends Model
{
/**
* @use HasFactory<GroupFactory>
*/
use HasFactory;
/**
@ -127,5 +131,4 @@ class Group extends Model
{
return $query->where('user_id', null);
}
}

View File

@ -12,6 +12,7 @@ use App\Helpers\Helpers;
use App\Models\Dto\HotpDto;
use App\Models\Dto\TotpDto;
use App\Services\LogoService;
use Database\Factories\TwoFAccountFactory;
use Exception;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
@ -80,7 +81,12 @@ use SteamTotp\SteamTotp;
*/
class TwoFAccount extends Model implements Sortable
{
use HasFactory, SortableTrait;
/**
* @use HasFactory<TwoFAccountFactory>
*/
use HasFactory;
use SortableTrait;
const TOTP = 'totp';
@ -407,14 +413,14 @@ class TwoFAccount extends Model implements Sortable
if (strtolower($this->secret) === __('errors.indecipherable')) {
Log::error('Secret cannot be deciphered, OTP generation aborted');
throw new UndecipherableException();
throw new UndecipherableException;
}
$this->initGenerator();
try {
if ($this->otp_type === self::HOTP) {
$OtpDto = new HotpDto();
$OtpDto = new HotpDto;
$OtpDto->otp_type = $this->otp_type;
$counter = $this->generator->getParameter('counter');
$OtpDto->password = $this->generator->at($counter);
@ -425,7 +431,7 @@ class TwoFAccount extends Model implements Sortable
$this->save();
}
} else {
$OtpDto = new TotpDto();
$OtpDto = new TotpDto;
$OtpDto->otp_type = $this->otp_type;
$OtpDto->generated_at = $time ?: time();
$OtpDto->password = $this->otp_type === self::TOTP
@ -637,7 +643,7 @@ class TwoFAccount extends Model implements Sortable
break;
default:
throw new UnsupportedOtpTypeException();
throw new UnsupportedOtpTypeException;
}
if ($this->service) {
@ -799,6 +805,7 @@ class TwoFAccount extends Model implements Sortable
return Crypt::decryptString($value);
} catch (Exception $ex) {
Log::debug(sprintf('Service field of twofaccount with id #%s cannot be deciphered', $this->id));
return __('errors.indecipherable');
}
} else {

View File

@ -4,6 +4,7 @@ namespace App\Models;
use App\Models\Traits\HasAuthenticationLog;
use App\Models\Traits\WebAuthnManageCredentials;
use Database\Factories\UserFactory;
use Illuminate\Auth\Events\PasswordReset;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Contracts\Translation\HasLocalePreference;
@ -46,8 +47,8 @@ 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 \Illuminate\Database\Eloquent\Builder|User admins()
* @method static \Database\Factories\UserFactory factory(...$parameters)
* @method static \Illuminate\Database\Eloquent\Builder|User newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|User newQuery()
@ -68,8 +69,13 @@ use Laravel\Passport\HasApiTokens;
*/
class User extends Authenticatable implements HasLocalePreference, WebAuthnAuthenticatable
{
use HasApiTokens, HasFactory, Notifiable;
use HasApiTokens, Notifiable;
use HasAuthenticationLog;
/**
* @use HasFactory<UserFactory>
*/
use HasFactory;
use WebAuthnAuthentication, WebAuthnManageCredentials;
/**
@ -259,5 +265,4 @@ class User extends Authenticatable implements HasLocalePreference, WebAuthnAuthe
$this->oauth_id == $other->oauth_id &&
$this->oauth_provider == $other->oauth_provider;
}
}