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

@ -5,7 +5,11 @@
use App\Actions\Service\Manage;
use App\Enums\ServiceStatus;
use App\Exceptions\ServiceInstallationFailed;
use App\SSH\Services\Firewall\Firewall;
use App\SSH\Services\PHP\PHP;
use App\SSH\Services\ProcessManager\ProcessManager;
use App\SSH\Services\ServiceInterface;
use App\SSH\Services\Webserver\Webserver;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Str;
@ -13,7 +17,7 @@
/**
* @property int $server_id
* @property string $type
* @property array $type_data
* @property array<string, mixed> $type_data
* @property string $name
* @property string $version
* @property string $unit
@ -24,6 +28,7 @@
*/
class Service extends AbstractModel
{
/** @use HasFactory<\Database\Factories\ServiceFactory> */
use HasFactory;
protected $fillable = [
@ -48,13 +53,16 @@ public static function boot(): void
{
parent::boot();
static::creating(function (Service $service) {
static::creating(function (Service $service): void {
if (array_key_exists($service->name, config('core.service_units'))) {
$service->unit = config('core.service_units')[$service->name][$service->server->os][$service->version];
}
});
}
/**
* @var array<string, string>
*/
public static array $statusColors = [
ServiceStatus::READY => 'success',
ServiceStatus::INSTALLING => 'warning',
@ -70,22 +78,28 @@ public static function boot(): void
ServiceStatus::DISABLED => 'gray',
];
/**
* @return BelongsTo<Server, covariant $this>
*/
public function server(): BelongsTo
{
return $this->belongsTo(Server::class);
}
public function handler(): ServiceInterface
public function handler(): ServiceInterface|Webserver|PHP|Firewall|\App\SSH\Services\Database\Database|ProcessManager
{
$handler = config('core.service_handlers')[$this->name];
return new $handler($this);
/** @var ServiceInterface $service */
$service = new $handler($this);
return $service;
}
/**
* @throws ServiceInstallationFailed
*/
public function validateInstall($result): void
public function validateInstall(string $result): void
{
if (! Str::contains($result, 'Active: active')) {
throw new ServiceInstallationFailed;