Add phpstan level 7(#544)

This commit is contained in:
Saeed Vaziry
2025-03-12 13:31:10 +01:00
committed by GitHub
parent c22bb1fa80
commit 493cbb0849
437 changed files with 4505 additions and 2193 deletions

View File

@ -12,15 +12,16 @@
* @property int $user_id
* @property string $profile
* @property string $provider
* @property array $credentials
* @property array<string, string> $credentials
* @property bool $connected
* @property User $user
* @property ?int $project_id
* @property Server[] $servers
* @property Project $project
* @property ?Project $project
*/
class ServerProvider extends AbstractModel
{
/** @use HasFactory<\Database\Factories\ServerProviderFactory> */
use HasFactory;
protected $fillable = [
@ -39,16 +40,25 @@ class ServerProvider extends AbstractModel
'project_id' => 'integer',
];
/**
* @return BelongsTo<User, covariant $this>
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
/**
* @return array<string, string>
*/
public function getCredentials(): array
{
return $this->credentials;
}
/**
* @return HasMany<Server, covariant $this>
*/
public function servers(): HasMany
{
return $this->hasMany(Server::class, 'provider_id');
@ -58,25 +68,40 @@ public function provider(): \App\ServerProviders\ServerProvider
{
$providerClass = config('core.server_providers_class')[$this->provider];
return new $providerClass($this);
/** @var \App\ServerProviders\ServerProvider $provider */
$provider = new $providerClass($this, new Server);
return $provider;
}
/**
* @return BelongsTo<Project, covariant $this>
*/
public function project(): BelongsTo
{
return $this->belongsTo(Project::class);
}
/**
* @return Builder<ServerProvider>
*/
public static function getByProjectId(int $projectId): Builder
{
return self::query()
->where(function (Builder $query) use ($projectId) {
/** @var Builder<ServerProvider> $query */
$query = static::query();
return $query
->where(function (Builder $query) use ($projectId): void {
$query->where('project_id', $projectId)->orWhereNull('project_id');
});
}
/**
* @return array<string>
*/
public static function regions(?int $id): array
{
if (! $id) {
if ($id === null || $id === 0) {
return [];
}
/** @var ?ServerProvider $profile */
@ -95,9 +120,12 @@ public static function regions(?int $id): array
return $regions;
}
/**
* @return array<string>
*/
public static function plans(?int $id, ?string $region): array
{
if (! $id) {
if ($id === null || $id === 0) {
return [];
}
$profile = self::find($id);