mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-07 17:02:34 +00:00
Add phpstan level 7(#544)
This commit is contained in:
@ -9,10 +9,14 @@ private function prepareS3Path(string $path, string $prefix = ''): string
|
||||
$path = trim($path);
|
||||
$path = ltrim($path, '/');
|
||||
$path = preg_replace('/[^a-zA-Z0-9\-_\.\/]/', '_', $path);
|
||||
$path = preg_replace('/\/+/', '/', $path);
|
||||
$path = preg_replace('/\/+/', '/', (string) $path);
|
||||
|
||||
if ($prefix) {
|
||||
$path = trim($prefix, '/').'/'.$path;
|
||||
if ($prefix !== '' && $prefix !== '0') {
|
||||
return trim($prefix, '/').'/'.$path;
|
||||
}
|
||||
|
||||
if ($path === null) {
|
||||
throw new \Exception('Invalid S3 path');
|
||||
}
|
||||
|
||||
return $path;
|
||||
|
@ -141,7 +141,7 @@ public function deleteSSHKey(string $key): void
|
||||
*/
|
||||
public function generateSSHKey(string $name, ?Site $site = null): void
|
||||
{
|
||||
$site->server->ssh($site->user)->exec(
|
||||
$this->server->ssh($site?->user)->exec(
|
||||
view('ssh.os.generate-ssh-key', [
|
||||
'name' => $name,
|
||||
]),
|
||||
@ -155,7 +155,7 @@ public function generateSSHKey(string $name, ?Site $site = null): void
|
||||
*/
|
||||
public function readSSHKey(string $name, ?Site $site = null): string
|
||||
{
|
||||
return $site->server->ssh($site->user)->exec(
|
||||
return $this->server->ssh($site?->user)->exec(
|
||||
view('ssh.os.read-ssh-key', [
|
||||
'name' => $name,
|
||||
]),
|
||||
@ -218,17 +218,21 @@ public function tail(string $path, int $lines): string
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $variables
|
||||
*
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function runScript(string $path, string $script, ?ServerLog $serverLog, ?string $user = null, ?array $variables = []): ServerLog
|
||||
{
|
||||
$ssh = $this->server->ssh($user);
|
||||
if ($serverLog) {
|
||||
if ($serverLog instanceof \App\Models\ServerLog) {
|
||||
$ssh->setLog($serverLog);
|
||||
}
|
||||
$command = '';
|
||||
foreach ($variables as $key => $variable) {
|
||||
$command .= "$key=$variable\n";
|
||||
if ($variables !== null && $variables !== []) {
|
||||
foreach ($variables as $key => $variable) {
|
||||
$command .= "$key=$variable\n";
|
||||
}
|
||||
}
|
||||
$command .= view('ssh.os.run-script', [
|
||||
'path' => $path,
|
||||
@ -236,9 +240,10 @@ public function runScript(string $path, string $script, ?ServerLog $serverLog, ?
|
||||
]);
|
||||
$ssh->exec($command, 'run-script');
|
||||
|
||||
info($command);
|
||||
/** @var ServerLog $log */
|
||||
$log = $ssh->log;
|
||||
|
||||
return $ssh->log;
|
||||
return $log;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -280,6 +285,8 @@ public function cleanup(): void
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function resourceInfo(): array
|
||||
|
@ -11,6 +11,9 @@
|
||||
|
||||
abstract class AbstractDatabase extends AbstractService implements Database
|
||||
{
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected array $systemDbs = [];
|
||||
|
||||
protected string $defaultCharset;
|
||||
@ -21,8 +24,12 @@ abstract class AbstractDatabase extends AbstractService implements Database
|
||||
|
||||
protected bool $removeLastRow = false;
|
||||
|
||||
/**
|
||||
* @phpstan-return view-string
|
||||
*/
|
||||
protected function getScriptView(string $script): string
|
||||
{
|
||||
/** @phpstan-ignore-next-line */
|
||||
return 'ssh.services.database.'.$this->service->name.'.'.$script;
|
||||
}
|
||||
|
||||
@ -31,7 +38,7 @@ public function creationRules(array $input): array
|
||||
return [
|
||||
'type' => [
|
||||
'required',
|
||||
function (string $attribute, mixed $value, Closure $fail) {
|
||||
function (string $attribute, mixed $value, Closure $fail): void {
|
||||
$databaseExists = $this->service->server->database();
|
||||
if ($databaseExists) {
|
||||
$fail('You already have a database service on the server.');
|
||||
@ -62,7 +69,7 @@ public function deletionRules(): array
|
||||
{
|
||||
return [
|
||||
'service' => [
|
||||
function (string $attribute, mixed $value, Closure $fail) {
|
||||
function (string $attribute, mixed $value, Closure $fail): void {
|
||||
$hasDatabase = $this->service->server->databases()->exists();
|
||||
if ($hasDatabase) {
|
||||
$fail('You have database(s) on the server.');
|
||||
@ -306,6 +313,7 @@ public function syncDatabases(bool $createNew = true): void
|
||||
continue;
|
||||
}
|
||||
|
||||
/** @var ?\App\Models\Database $db */
|
||||
$db = $this->service->server->databases()
|
||||
->where('name', $database[0])
|
||||
->first();
|
||||
@ -331,6 +339,9 @@ public function syncDatabases(bool $createNew = true): void
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<array<string>>
|
||||
*/
|
||||
protected function tableToArray(string $data, bool $keepHeader = false): array
|
||||
{
|
||||
$lines = explode("\n", trim($data));
|
||||
@ -347,7 +358,8 @@ protected function tableToArray(string $data, bool $keepHeader = false): array
|
||||
|
||||
$rows = [];
|
||||
foreach ($lines as $line) {
|
||||
$row = explode($this->separator, $line);
|
||||
$separator = $this->separator === '' || $this->separator === '0' ? "\t" : $this->separator;
|
||||
$row = explode($separator, $line);
|
||||
$row = array_map('trim', $row);
|
||||
$rows[] = $row;
|
||||
}
|
||||
|
@ -3,8 +3,9 @@
|
||||
namespace App\SSH\Services\Database;
|
||||
|
||||
use App\Models\BackupFile;
|
||||
use App\SSH\Services\ServiceInterface;
|
||||
|
||||
interface Database
|
||||
interface Database extends ServiceInterface
|
||||
{
|
||||
public function create(string $name, string $charset, string $collation): void;
|
||||
|
||||
@ -14,6 +15,9 @@ public function createUser(string $username, string $password, string $host): vo
|
||||
|
||||
public function deleteUser(string $username, string $host): void;
|
||||
|
||||
/**
|
||||
* @param array<string> $databases
|
||||
*/
|
||||
public function link(string $username, string $host, array $databases): void;
|
||||
|
||||
public function unlink(string $username, string $host): void;
|
||||
|
@ -2,7 +2,9 @@
|
||||
|
||||
namespace App\SSH\Services\Firewall;
|
||||
|
||||
interface Firewall
|
||||
use App\SSH\Services\ServiceInterface;
|
||||
|
||||
interface Firewall extends ServiceInterface
|
||||
{
|
||||
public function applyRules(): void;
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ public function applyRules(): void
|
||||
->get();
|
||||
|
||||
$this->service->server->ssh()->exec(
|
||||
view('ssh.services.firewall.ufw.apply-rules', compact('rules')),
|
||||
view('ssh.services.firewall.ufw.apply-rules', ['rules' => $rules]),
|
||||
'apply-rules'
|
||||
);
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ public function creationRules(array $input): array
|
||||
{
|
||||
return [
|
||||
'type' => [
|
||||
function (string $attribute, mixed $value, Closure $fail) {
|
||||
function (string $attribute, mixed $value, Closure $fail): void {
|
||||
$monitoringExists = $this->service->server->monitoring();
|
||||
if ($monitoringExists) {
|
||||
$fail('You already have a monitoring service on the server.');
|
||||
|
@ -21,7 +21,7 @@ public function creationRules(array $input): array
|
||||
{
|
||||
return [
|
||||
'type' => [
|
||||
function (string $attribute, mixed $value, Closure $fail) {
|
||||
function (string $attribute, mixed $value, Closure $fail): void {
|
||||
$monitoringExists = $this->service->server->monitoring();
|
||||
if ($monitoringExists) {
|
||||
$fail('You already have a monitoring service on the server.');
|
||||
|
@ -27,7 +27,7 @@ public function deletionRules(): array
|
||||
{
|
||||
return [
|
||||
'service' => [
|
||||
function (string $attribute, mixed $value, Closure $fail) {
|
||||
function (string $attribute, mixed $value, Closure $fail): void {
|
||||
$hasSite = $this->service->server->sites()
|
||||
->where('nodejs_version', $this->service->version)
|
||||
->exists();
|
||||
|
@ -29,7 +29,7 @@ public function deletionRules(): array
|
||||
{
|
||||
return [
|
||||
'service' => [
|
||||
function (string $attribute, mixed $value, Closure $fail) {
|
||||
function (string $attribute, mixed $value, Closure $fail): void {
|
||||
$hasSite = $this->service->server->sites()
|
||||
->where('php_version', $this->service->version)
|
||||
->exists();
|
||||
@ -88,7 +88,7 @@ public function setDefaultCli(): void
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function installExtension($name): void
|
||||
public function installExtension(string $name): void
|
||||
{
|
||||
$result = $this->service->server->ssh()->exec(
|
||||
view('ssh.services.php.install-php-extension', [
|
||||
@ -97,7 +97,11 @@ public function installExtension($name): void
|
||||
]),
|
||||
'install-php-extension-'.$name
|
||||
);
|
||||
$result = Str::substr($result, strpos($result, '[PHP Modules]'));
|
||||
$pos = strpos($result, '[PHP Modules]');
|
||||
if ($pos === false) {
|
||||
throw new SSHCommandError('Failed to install extension');
|
||||
}
|
||||
$result = Str::substr($result, $pos);
|
||||
if (! Str::contains($result, $name)) {
|
||||
throw new SSHCommandError('Failed to install extension');
|
||||
}
|
||||
@ -127,7 +131,7 @@ public function getPHPIni(string $type): string
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function createFpmPool(string $user, string $version, $site_id): void
|
||||
public function createFpmPool(string $user, string $version): void
|
||||
{
|
||||
$this->service->server->ssh()->write(
|
||||
"/etc/php/{$version}/fpm/pool.d/{$user}.conf",
|
||||
@ -144,7 +148,7 @@ public function createFpmPool(string $user, string $version, $site_id): void
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function removeFpmPool(string $user, string $version, $site_id): void
|
||||
public function removeFpmPool(string $user, string $version, ?int $siteId): void
|
||||
{
|
||||
$this->service->server->ssh()->exec(
|
||||
view('ssh.services.php.remove-fpm-pool', [
|
||||
@ -152,7 +156,7 @@ public function removeFpmPool(string $user, string $version, $site_id): void
|
||||
'version' => $version,
|
||||
]),
|
||||
"remove-{$version}fpm-pool-{$user}",
|
||||
$site_id
|
||||
$siteId
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ public function creationRules(array $input): array
|
||||
return [
|
||||
'type' => [
|
||||
'required',
|
||||
function (string $attribute, mixed $value, Closure $fail) {
|
||||
function (string $attribute, mixed $value, Closure $fail): void {
|
||||
$processManagerExists = $this->service->server->processManager();
|
||||
if ($processManagerExists) {
|
||||
$fail('You already have a process manager service on the server.');
|
||||
@ -26,7 +26,7 @@ public function deletionRules(): array
|
||||
{
|
||||
return [
|
||||
'service' => [
|
||||
function (string $attribute, mixed $value, Closure $fail) {
|
||||
function (string $attribute, mixed $value, Closure $fail): void {
|
||||
$hasQueue = $this->service->server->queues()->exists();
|
||||
if ($hasQueue) {
|
||||
$fail('You have queue(s) on the server.');
|
||||
|
@ -2,7 +2,9 @@
|
||||
|
||||
namespace App\SSH\Services\ProcessManager;
|
||||
|
||||
interface ProcessManager
|
||||
use App\SSH\Services\ServiceInterface;
|
||||
|
||||
interface ProcessManager extends ServiceInterface
|
||||
{
|
||||
public function create(
|
||||
int $id,
|
||||
|
@ -14,7 +14,7 @@ public function creationRules(array $input): array
|
||||
return [
|
||||
'type' => [
|
||||
'required',
|
||||
function (string $attribute, mixed $value, Closure $fail) {
|
||||
function (string $attribute, mixed $value, Closure $fail): void {
|
||||
$redisExists = $this->service->server->memoryDatabase();
|
||||
if ($redisExists) {
|
||||
$fail('You already have a Redis service on the server.');
|
||||
|
@ -4,12 +4,26 @@
|
||||
|
||||
interface ServiceInterface
|
||||
{
|
||||
/**
|
||||
* @param array<string, mixed> $input
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function creationRules(array $input): array;
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $input
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function creationData(array $input): array;
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function deletionRules(): array;
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function data(): array;
|
||||
|
||||
public function install(): void;
|
||||
|
@ -38,7 +38,7 @@ public function deletionRules(): array
|
||||
{
|
||||
return [
|
||||
'service' => [
|
||||
function (string $attribute, mixed $value, Closure $fail) {
|
||||
function (string $attribute, mixed $value, Closure $fail): void {
|
||||
$hasSite = $this->service->server->sites()
|
||||
->exists();
|
||||
if ($hasSite) {
|
||||
@ -145,7 +145,7 @@ public function deleteSite(Site $site): void
|
||||
/**
|
||||
* @throws SSHError
|
||||
*/
|
||||
public function changePHPVersion(Site $site, $version): void
|
||||
public function changePHPVersion(Site $site, string $version): void
|
||||
{
|
||||
$this->service->server->ssh()->exec(
|
||||
view('ssh.services.webserver.nginx.change-php-version', [
|
||||
|
@ -4,8 +4,9 @@
|
||||
|
||||
use App\Models\Site;
|
||||
use App\Models\Ssl;
|
||||
use App\SSH\Services\ServiceInterface;
|
||||
|
||||
interface Webserver
|
||||
interface Webserver extends ServiceInterface
|
||||
{
|
||||
public function createVHost(Site $site): void;
|
||||
|
||||
|
@ -4,6 +4,9 @@
|
||||
|
||||
interface Storage
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function upload(string $src, string $dest): array;
|
||||
|
||||
public function download(string $src, string $dest): void;
|
||||
|
Reference in New Issue
Block a user