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

@ -3,24 +3,37 @@
namespace App\Actions\PHP;
use App\Enums\ServiceStatus;
use App\Exceptions\SSHError;
use App\Models\Server;
use App\Models\Service;
use App\SSH\Services\PHP\PHP;
use Illuminate\Validation\ValidationException;
class ChangeDefaultCli
{
/**
* @param array<string, mixed> $input
*
* @throws SSHError
*/
public function change(Server $server, array $input): void
{
$this->validate($server, $input);
/** @var Service $service */
$service = $server->php($input['version']);
/** @var PHP $handler */
$handler = $service->handler();
$handler->setDefaultCli();
$server->defaultService('php')->update(['is_default' => 0]);
$server->defaultService('php')?->update(['is_default' => 0]);
$service->update(['is_default' => 1]);
$service->update(['status' => ServiceStatus::READY]);
}
/**
* @param array<string, mixed> $input
*
* @throws ValidationException
*/
public function validate(Server $server, array $input): void
{
if (! isset($input['version']) || ! in_array($input['version'], $server->installedPHPVersions())) {

View File

@ -4,17 +4,25 @@
use App\Enums\PHPIniType;
use App\Models\Server;
use App\Models\Service;
use App\SSH\Services\PHP\PHP;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
use Illuminate\Validation\ValidationException;
use Throwable;
class GetPHPIni
{
/**
* @param array<string, mixed> $input
*
* @throws ValidationException
*/
public function getIni(Server $server, array $input): string
{
$this->validate($server, $input);
/** @var Service $php */
$php = $server->php($input['version']);
try {
@ -22,13 +30,18 @@ public function getIni(Server $server, array $input): string
$handler = $php->handler();
return $handler->getPHPIni($input['type']);
} catch (\Throwable $e) {
} catch (Throwable $e) {
throw ValidationException::withMessages(
['ini' => $e->getMessage()]
);
}
}
/**
* @param array<string, mixed> $input
*
* @throws ValidationException
*/
public function validate(Server $server, array $input): void
{
Validator::make($input, [

View File

@ -10,6 +10,9 @@
class InstallNewPHP
{
/**
* @param array<string, mixed> $input
*/
public function install(Server $server, array $input): void
{
$php = new Service([
@ -26,15 +29,18 @@ public function install(Server $server, array $input): void
]);
$php->save();
dispatch(function () use ($php) {
dispatch(function () use ($php): void {
$php->handler()->install();
$php->status = ServiceStatus::READY;
$php->save();
})->catch(function () use ($php) {
})->catch(function () use ($php): void {
$php->delete();
})->onConnection('ssh');
}
/**
* @return array<string, array<string>>
*/
public static function rules(Server $server): array
{
return [

View File

@ -2,7 +2,6 @@
namespace App\Actions\PHP;
use App\Exceptions\SSHCommandError;
use App\Models\Server;
use App\Models\Service;
use App\SSH\Services\PHP\PHP;
@ -11,6 +10,11 @@
class InstallPHPExtension
{
/**
* @param array<string, mixed> $input
*
* @throws ValidationException
*/
public function install(Server $server, array $input): Service
{
/** @var Service $service */
@ -23,20 +27,17 @@ public function install(Server $server, array $input): Service
}
$typeData = $service->type_data;
$typeData['extensions'] = $typeData['extensions'] ?? [];
$typeData['extensions'] ??= [];
$typeData['extensions'][] = $input['extension'];
$service->type_data = $typeData;
$service->save();
dispatch(
/**
* @throws SSHCommandError
*/
function () use ($service, $input) {
function () use ($service, $input): void {
/** @var PHP $handler */
$handler = $service->handler();
$handler->installExtension($input['extension']);
})->catch(function () use ($service, $input) {
})->catch(function () use ($service, $input): void {
$service->refresh();
$typeData = $service->type_data;
$typeData['extensions'] = array_values(array_diff($typeData['extensions'], [$input['extension']]));
@ -47,6 +48,9 @@ function () use ($service, $input) {
return $service;
}
/**
* @return array<string, array<string>>
*/
public static function rules(Server $server): array
{
return [

View File

@ -10,6 +10,11 @@
class UninstallPHP
{
/**
* @param array<string, mixed> $input
*
* @throws ValidationException
*/
public function uninstall(Server $server, array $input): void
{
$this->validate($server, $input);
@ -19,16 +24,18 @@ public function uninstall(Server $server, array $input): void
$php->status = ServiceStatus::UNINSTALLING;
$php->save();
dispatch(function () use ($php) {
dispatch(function () use ($php): void {
$php->handler()->uninstall();
$php->delete();
})->catch(function () use ($php) {
})->catch(function () use ($php): void {
$php->status = ServiceStatus::FAILED;
$php->save();
})->onConnection('ssh');
}
/**
* @param array<string, mixed> $input
*
* @throws ValidationException
*/
private function validate(Server $server, array $input): void

View File

@ -4,6 +4,7 @@
use App\Enums\PHPIniType;
use App\Models\Server;
use App\Models\Service;
use Illuminate\Filesystem\FilesystemAdapter;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
@ -14,10 +15,13 @@
class UpdatePHPIni
{
/**
* @param array<string, mixed> $input
*
* @throws ValidationException
*/
public function update(Server $server, array $input): void
{
/** @var Service $service */
$service = $server->php($input['version']);
$tmpName = Str::random(10).strtotime('now');
@ -48,6 +52,9 @@ private function deleteTempFile(string $name): void
}
}
/**
* @return array<string, array<string>>
*/
public static function rules(Server $server): array
{
return [