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,10 +12,9 @@ class SSHFake extends SSH
{
use ReflectsClosures;
/** @var array<string> */
protected array $commands = [];
protected ?string $output;
protected bool $connectionWillFail = false;
protected string $uploadedLocalPath;
@ -24,10 +23,7 @@ class SSHFake extends SSH
protected string $uploadedContent;
public function __construct(?string $output = null)
{
$this->output = $output;
}
public function __construct(protected ?string $output = null) {}
public function init(Server $server, ?string $asUser = null): self
{
@ -36,7 +32,7 @@ public function init(Server $server, ?string $asUser = null): self
$this->asUser = null;
$this->server = $server->refresh();
$this->user = $server->getSshUser();
if ($asUser && $asUser != $server->getSshUser()) {
if ($asUser && $asUser !== $server->getSshUser()) {
$this->asUser = $asUser;
}
@ -57,13 +53,15 @@ public function connect(bool $sftp = false): void
public function exec(string $command, string $log = '', ?int $siteId = null, ?bool $stream = false, ?callable $streamCallback = null): string
{
if (! $this->log && $log) {
$this->log = $this->server->logs()->create([
if (! $this->log instanceof \App\Models\ServerLog && $log) {
/** @var \App\Models\ServerLog $log */
$log = $this->server->logs()->create([
'site_id' => $siteId,
'name' => $this->server->id.'-'.strtotime('now').'-'.$log.'.log',
'type' => $log,
'disk' => config('core.logs_disk'),
]);
$this->log = $log;
}
$this->commands[] = $command;
@ -71,7 +69,7 @@ public function exec(string $command, string $log = '', ?int $siteId = null, ?bo
$output = $this->output ?? 'fake output';
$this->log?->write($output);
if ($stream) {
if ($stream === true) {
echo $output;
ob_flush();
flush();
@ -86,13 +84,16 @@ public function upload(string $local, string $remote, ?string $owner = null): vo
{
$this->uploadedLocalPath = $local;
$this->uploadedRemotePath = $remote;
$this->uploadedContent = file_get_contents($local);
$this->uploadedContent = file_get_contents($local) ?: '';
$this->log = null;
}
/**
* @param array<string>|string $commands
*/
public function assertExecuted(array|string $commands): void
{
if (! $this->commands) {
if ($this->commands === []) {
Assert::fail('No commands are executed');
}
if (! is_array($commands)) {
@ -107,12 +108,11 @@ public function assertExecuted(array|string $commands): void
if (! $allExecuted) {
Assert::fail('The expected commands are not executed. executed commands: '.implode(', ', $this->commands));
}
Assert::assertTrue(true, $allExecuted);
}
public function assertExecutedContains(string $command): void
{
if (! $this->commands) {
if ($this->commands === []) {
Assert::fail('No commands are executed');
}
$executed = false;
@ -127,18 +127,17 @@ public function assertExecutedContains(string $command): void
'The expected command is not executed in the executed commands: '.implode(', ', $this->commands)
);
}
Assert::assertTrue(true, $executed);
}
public function assertFileUploaded(string $toPath, ?string $content = null): void
{
if (! $this->uploadedLocalPath || ! $this->uploadedRemotePath) {
if ($this->uploadedLocalPath === '' || $this->uploadedLocalPath === '0' || ($this->uploadedRemotePath === '' || $this->uploadedRemotePath === '0')) {
Assert::fail('File is not uploaded');
}
Assert::assertEquals($toPath, $this->uploadedRemotePath);
if ($content) {
if ($content !== null && $content !== '' && $content !== '0') {
Assert::assertEquals($content, $this->uploadedContent);
}
}