Skip to content

Commit

Permalink
chore: improved phpstan level 6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
lewislarsen committed Jun 24, 2024
1 parent 283ded9 commit 73257fb
Show file tree
Hide file tree
Showing 28 changed files with 167 additions and 11 deletions.
8 changes: 8 additions & 0 deletions app/Actions/RemoteServer/CheckRemoteServerConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
class CheckRemoteServerConnection
{
/**
* @return array<string, mixed>
*
* @throws Exception
*/
public function byRemoteServerId(int $remoteServerId): array
Expand All @@ -29,6 +31,9 @@ public function byRemoteServerId(int $remoteServerId): array
}

/**
* @param array<string, mixed> $remoteServerConnectionDetails
* @return array<string, mixed>
*
* @throws Exception
*/
public function byRemoteServerConnectionDetails(array $remoteServerConnectionDetails): array
Expand All @@ -39,6 +44,9 @@ public function byRemoteServerConnectionDetails(array $remoteServerConnectionDet
}

/**
* @param array<string, mixed> $data
* @return array<string, mixed>
*
* @throws Exception
*/
private function checkServerConnection(array $data, ?RemoteServer $remoteServer = null): array
Expand Down
5 changes: 5 additions & 0 deletions app/Console/Commands/CheckVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ protected function getCurrentVersion(): ?string
return str_replace("\n", '', File::get($versionFile));
}

/**
* Get the latest version from the GitHub API.
*
* @return array<string, string|null>|null
*/
protected function getLatestVersion(): ?array
{
$url = 'https://api.github.com/repos/vanguardsh/vanguard/releases/latest';
Expand Down
5 changes: 5 additions & 0 deletions app/Events/BackupDestinationConnectionCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public function __construct(
$this->status = $status ?? $this->backupDestination->status;
}

/**
* Get the channels the event should broadcast on.
*
* @return array<Channel>
*/
public function broadcastOn(): array
{
return [
Expand Down
5 changes: 5 additions & 0 deletions app/Events/BackupTaskStatusChanged.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public function __construct(
$this->status = $status ?? $backupTask->status;
}

/**
* Get the channels the event should broadcast on.
*
* @return array<Channel>
*/
public function broadcastOn(): array
{
return [
Expand Down
10 changes: 10 additions & 0 deletions app/Events/CreatedBackupTaskLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,23 @@ public function __construct(BackupTaskLog $backupTaskLog)
$this->backupTask = $backupTaskLog->backupTask;
}

/**
* Get the channels the event should broadcast on.
*
* @return array<int, Channel>
*/
public function broadcastOn(): array
{
return [
new Channel("new-backup-task-log.{$this->backupTask->id}"),
];
}

/**
* Get the data to broadcast.
*
* @return array<string, int>
*/
public function broadcastWith(): array
{
return ['logId' => $this->backupTaskLog->id];
Expand Down
5 changes: 5 additions & 0 deletions app/Events/RemoteServerConnectivityStatusChanged.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public function __construct(
$this->connectivityStatus = $connectivityStatus ?? $remoteServer->connectivity_status;
}

/**
* Get the channels the event should broadcast on.
*
* @return array<Channel>
*/
public function broadcastOn(): array
{
return [
Expand Down
5 changes: 5 additions & 0 deletions app/Events/StreamBackupTaskLogEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public function __construct(BackupTaskLog $backupTaskLog, string $logOutput)

}

/**
* Get the channels the event should broadcast on.
*
* @return array<Channel>
*/
public function broadcastOn(): array
{
return [
Expand Down
5 changes: 5 additions & 0 deletions app/Livewire/BackupDestinations/CheckConnectionButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ class CheckConnectionButton extends Component
{
public BackupDestination $backupDestination;

/**
* Get the listeners array.
*
* @return array<string, string>
*/
public function getListeners(): array
{
return [
Expand Down
5 changes: 5 additions & 0 deletions app/Livewire/BackupDestinations/IndexItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ class IndexItem extends Component
{
public BackupDestination $backupDestination;

/**
* Get the listeners array.
*
* @return array<string, string>
*/
public function getListeners(): array
{
return [
Expand Down
5 changes: 5 additions & 0 deletions app/Livewire/BackupTasks/BackupTaskHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public function render(): View
]);
}

/**
* Get the listeners array.
*
* @return array<string, string>
*/
protected function getListeners(): array
{
return [
Expand Down
5 changes: 5 additions & 0 deletions app/Livewire/BackupTasks/ClearLogButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public function render(): View
return view('livewire.backup-tasks.clear-log-button');
}

/**
* Get the listeners array.
*
* @return array<string, string>
*/
protected function getListeners(): array
{
return [
Expand Down
4 changes: 4 additions & 0 deletions app/Livewire/BackupTasks/CreateBackupTaskForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ class CreateBackupTaskForm extends Component
* @var \Illuminate\Database\Eloquent\Collection<int, \App\Models\Tag>|null
*/
public ?Collection $availableTags;

/**
* @var array<string>|null
*/
public ?array $selectedTags;

public bool $useIsolatedCredentials = false;
Expand Down
6 changes: 6 additions & 0 deletions app/Livewire/BackupTasks/IndexItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class IndexItem extends Component
public BackupTask $backupTask;
public ?BackupTaskLog $backupTaskLog;

/**
* @return array<string, string>
*/
public function getListeners(): array
{
return [
Expand All @@ -26,6 +29,9 @@ public function getListeners(): array
];
}

/**
* @param array<string, mixed> $event
*/
public function echoBackupTaskLogCreatedEvent(array $event): void
{
Log::debug('Received the CreatedBackupTaskLog event. Fetching the log.', ['new_log_id' => $event['logId']]);
Expand Down
5 changes: 5 additions & 0 deletions app/Livewire/BackupTasks/IndexTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public function render(): View
return view('livewire.backup-tasks.index-table', ['backupTasks' => $backupTasks]);
}

/**
* Get the listeners array.
*
* @return array<string, string>
*/
protected function getListeners(): array
{
return [
Expand Down
10 changes: 10 additions & 0 deletions app/Livewire/BackupTasks/LogModal.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public function boot(): void
$this->resetLog();
}

/**
* Update the log output with the new data from the event.
*
* @param array<string, string> $event
*/
public function updateLogOutput(array $event): void
{
Log::debug('Received the StreamBackupTaskLogEvent event. Updating log output.', ['event' => $event]);
Expand Down Expand Up @@ -72,6 +77,11 @@ public function render(): View
return view('livewire.backup-tasks.log-modal');
}

/**
* Get the listeners array.
*
* @return array<string, string>
*/
protected function getListeners(): array
{
return [
Expand Down
5 changes: 5 additions & 0 deletions app/Livewire/BackupTasks/RunTaskButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ class RunTaskButton extends Component
{
public BackupTask $backupTask;

/**
* Get the listeners array.
*
* @return array<string, string>
*/
public function getListeners(): array
{
return [
Expand Down
5 changes: 5 additions & 0 deletions app/Livewire/BackupTasks/TogglePauseButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ class TogglePauseButton extends Component
{
public BackupTask $backupTask;

/**
* Get the listeners array.
*
* @return array<string, string>
*/
public function getListeners(): array
{
return [
Expand Down
4 changes: 4 additions & 0 deletions app/Livewire/BackupTasks/UpdateBackupTaskForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ class UpdateBackupTaskForm extends Component
* @var \Illuminate\Database\Eloquent\Collection<int, \App\Models\Tag>|null
*/
public ?Collection $availableTags;

/**
* @var array<string>|null
*/
public ?array $selectedTags;

public bool $useIsolatedCredentials = false;
Expand Down
5 changes: 5 additions & 0 deletions app/Livewire/RemoteServers/CheckConnectionButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ class CheckConnectionButton extends Component
{
public RemoteServer $remoteServer;

/**
* Get the listeners array.
*
* @return array<string, string>
*/
public function getListeners(): array
{
return [
Expand Down
5 changes: 5 additions & 0 deletions app/Livewire/RemoteServers/IndexItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ class IndexItem extends Component
{
public RemoteServer $remoteServer;

/**
* Get the listeners array.
*
* @return array<string, string>
*/
public function getListeners(): array
{
return [
Expand Down
10 changes: 10 additions & 0 deletions app/Models/BackupTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ class BackupTask extends Model
'last_scheduled_weekly_run_at' => 'datetime',
];

/**
* Get the count of logs per month for the last six months for a given user.
*
* @return array<string, int>
*/
public static function logsCountPerMonthForLastSixMonths(int $userId): array
{
$sixMonthsAgo = now()->subMonths(6);
Expand All @@ -54,6 +59,11 @@ public static function logsCountPerMonthForLastSixMonths(int $userId): array
->toArray();
}

/**
* Get the count of backup tasks by type for a given user.
*
* @return array<string, int>
*/
public static function backupTasksCountByType(int $userId): array
{
return self::query()
Expand Down
5 changes: 5 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ protected function lastName(): Attribute
);
}

/**
* Get the casts array.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
Expand Down
14 changes: 12 additions & 2 deletions app/Services/Backup/Backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,14 @@ protected function establishSFTPConnection(object $remoteServer, object $backupT
return $sftp;
}

/**
* Zip a remote directory, excluding specified directories.
*
* @param array<string> $excludeDirs
*
* @throws BackupTaskZipException
* @throws SFTPConnectionException
*/
protected function zipRemoteDirectory(SFTP $sftp, string $sourcePath, string $remoteZipPath, array $excludeDirs = []): void
{
$this->logInfo('Zipping remote directory.', ['source_path' => $sourcePath, 'remote_zip_path' => $remoteZipPath]);
Expand Down Expand Up @@ -341,9 +349,11 @@ protected function rotateOldBackups(
while (count($files) > $backupLimit) {
$oldestFile = array_pop($files);

$this->logDebug('Deleting old backup.', ['file' => $oldestFile['Key'] ?? $oldestFile['name']]);
$file = $oldestFile['Key'] ?? $oldestFile['name']; // @phpstan-ignore-line

$backupDestination->deleteFile($oldestFile['Key'] ?? $oldestFile['name']);
$this->logDebug('Deleting old backup.', ['file' => $file]);

$backupDestination->deleteFile($file);
}

$this->logInfo('Old backups rotation completed.', ['remaining_files' => count($files)]);
Expand Down
2 changes: 1 addition & 1 deletion app/Services/Backup/BackupDestinations/S3.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(S3Client $client, string $bucketName)

public function listFiles(string $pattern): array
{
/** @var array{Contents: array<int, array{Key: string, LastModified: string}>} $result */
/** @var array{Contents: array<int, array{Key: string, LastModified: string, name: ?string}>} $result */
$result = $this->client->listObjects([
'Bucket' => $this->bucketName,
]);
Expand Down
5 changes: 5 additions & 0 deletions app/Services/Backup/Contracts/BackupDestinationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

interface BackupDestinationInterface
{
/**
* List files matching the given pattern.
*
* @return array<string>
*/
public function listFiles(string $pattern): array;

public function deleteFile(string $filePath): void;
Expand Down
Loading

0 comments on commit 73257fb

Please sign in to comment.