Quality of life things.
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Build and test / requirements (push) Failing after 3m48s
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Build and test / requirements (push) Failing after 3m48s
This commit is contained in:
10
src/App.php
10
src/App.php
@ -26,6 +26,7 @@ class App
|
||||
* Create a new instance providing a config file.
|
||||
*
|
||||
* @param string $configFile Relative or full path to YML config.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.StaticAccess)
|
||||
*/
|
||||
public function __construct(string $configFile)
|
||||
@ -60,7 +61,9 @@ class App
|
||||
]);
|
||||
|
||||
$parser = new Yaml();
|
||||
/** @var array<string, mixed> */
|
||||
/**
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
$parsedConfig = $parser->parseFile($configFile);
|
||||
|
||||
// Merge those values into the configuration schema:
|
||||
@ -80,11 +83,14 @@ class App
|
||||
* Get configuration from key
|
||||
*
|
||||
* @param non-empty-string $key Key to fetch
|
||||
*
|
||||
* @return mixed Configuration value
|
||||
*/
|
||||
public function getConfig(string $key): mixed
|
||||
{
|
||||
/** @var string|array<string, string> */
|
||||
/**
|
||||
* @var string|array<string, string>
|
||||
*/
|
||||
$ret = $this->config->get($key);
|
||||
$this->logger->debug("Fetching configuration key", [$key, $ret]);
|
||||
return $ret;
|
||||
|
@ -65,19 +65,25 @@ class CommandBackup extends Command
|
||||
$rclone = new Rclone($app->getLogger()->withName('rclone'), (string)$app->getConfig('rclone.path'));
|
||||
|
||||
$notification = new Notification();
|
||||
/** @var array<array-key,array<string,string>> */
|
||||
/**
|
||||
* @var array<array-key,array<string,string>>
|
||||
*/
|
||||
$notificationConfig = $app->getConfig('notification');
|
||||
$notification->loadMany($notificationConfig);
|
||||
|
||||
/** @var array<string,string> */
|
||||
/**
|
||||
* @var array<string,string>
|
||||
*/
|
||||
$templateConfig = $app->getConfig('templates');
|
||||
$render = new Twig($templateConfig);
|
||||
|
||||
/** @var array{title: string, source: string, destination: string}[] */
|
||||
/**
|
||||
* @var array{title: string, source: string, destination: string}[]
|
||||
*/
|
||||
$backupElements = $app->getConfig('backup');
|
||||
foreach ($sioProgressbar->progressIterate($backupElements) as $conf) {
|
||||
$title = $conf['title'];
|
||||
$template = array();
|
||||
$template = [];
|
||||
$template['config'] = $conf;
|
||||
try {
|
||||
$template['start'] = new DateTime();
|
||||
@ -85,7 +91,9 @@ class CommandBackup extends Command
|
||||
$template['rclone_version'] = $rclone->getVersion();
|
||||
$template['destination_size_before'] = $rclone->getSize($conf['destination']);
|
||||
|
||||
/** @var array<array-key, string> */
|
||||
/**
|
||||
* @var array<array-key, string>
|
||||
*/
|
||||
$rcloneOptions = $app->getConfig('rclone.options');
|
||||
$rclone->copy($conf['source'], $conf['destination'], $rcloneOptions);
|
||||
|
||||
|
@ -42,7 +42,9 @@ class CommandShow extends Command
|
||||
$sio->error('Configuration error: ' . $e->getMessage());
|
||||
return Command::FAILURE;
|
||||
}
|
||||
/** @var array{title: string, source: string, destination: string}[] */
|
||||
/**
|
||||
* @var array{title: string, source: string, destination: string}[]
|
||||
*/
|
||||
$backupElements = $app->getConfig('backup');
|
||||
$sio->table(
|
||||
['Description', 'Source', 'Destination'],
|
||||
|
@ -12,7 +12,7 @@ class Notification
|
||||
/**
|
||||
* @var NotificationInterface[] $notifiers
|
||||
*/
|
||||
private array $notifiers = array();
|
||||
private array $notifiers = [];
|
||||
|
||||
public function __construct(private NullLogger $logger = new NullLogger())
|
||||
{
|
||||
@ -35,6 +35,7 @@ class Notification
|
||||
*
|
||||
* @param string $key Notification class
|
||||
* @param string[] $config Implementation specific configuration
|
||||
*
|
||||
* @SuppressWarnings(PHPMD)
|
||||
*/
|
||||
public function loadSingle(string $key, array $config): void
|
||||
|
@ -35,9 +35,6 @@ class Ntfy implements NotificationInterface
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo The constructor should be private but static code analysis complains.
|
||||
*/
|
||||
public function __construct(private Client $client)
|
||||
{
|
||||
}
|
||||
@ -49,7 +46,7 @@ class Ntfy implements NotificationInterface
|
||||
*/
|
||||
public function setTopic(string $topic): void
|
||||
{
|
||||
if (!strlen($topic) || strlen($topic) > self::TOPIC_MAX_LENGTH) {
|
||||
if (! strlen($topic) || strlen($topic) > self::TOPIC_MAX_LENGTH) {
|
||||
throw new InvalidArgumentException("Invalid topic length");
|
||||
}
|
||||
|
||||
@ -69,11 +66,11 @@ class Ntfy implements NotificationInterface
|
||||
*/
|
||||
public function send(string $title, string $message): void
|
||||
{
|
||||
if (!strlen($title) || strlen($title) > self::TITLE_MAX_LENGTH) {
|
||||
if (! strlen($title) || strlen($title) > self::TITLE_MAX_LENGTH) {
|
||||
throw new InvalidArgumentException("Invalid title length");
|
||||
}
|
||||
|
||||
if (!strlen($message) || strlen($message) > self::MESSAGE_MAX_LENGTH) {
|
||||
if (! strlen($message) || strlen($message) > self::MESSAGE_MAX_LENGTH) {
|
||||
throw new InvalidArgumentException("Invalid message length");
|
||||
}
|
||||
|
||||
|
@ -34,13 +34,13 @@ class Rclone
|
||||
$this->rclonePath = $rclonePath;
|
||||
|
||||
$process = $this->exec('--version');
|
||||
if (!$process->isSuccessful()) {
|
||||
if (! $process->isSuccessful()) {
|
||||
throw new Exception("Check installation of rclone");
|
||||
}
|
||||
|
||||
$this->version = explode("\n", $process->getOutput())[0];
|
||||
|
||||
if (!\str_contains($this->version, 'rclone')) {
|
||||
if (! \str_contains($this->version, 'rclone')) {
|
||||
throw new Exception("rclone not recognized");
|
||||
}
|
||||
}
|
||||
@ -66,12 +66,14 @@ class Rclone
|
||||
{
|
||||
$process = $this->exec('size', ['--json', $path]);
|
||||
|
||||
if (!$process->isSuccessful()) {
|
||||
if (! $process->isSuccessful()) {
|
||||
throw new Exception($process->getErrorOutput());
|
||||
}
|
||||
|
||||
/** @var array{bytes: int} */
|
||||
$output = json_decode($process->getOutput(), true);
|
||||
/**
|
||||
* @var array{bytes: int}
|
||||
*/
|
||||
$output = json_decode($process->getOutput(), TRUE);
|
||||
return $output['bytes'];
|
||||
}
|
||||
|
||||
@ -82,9 +84,9 @@ class Rclone
|
||||
* @param $dest Destination mount and path
|
||||
* @param string[] $additionalOptions Additional options
|
||||
*/
|
||||
public function copy(string $src, string $dest, array $additionalOptions = array()): void
|
||||
public function copy(string $src, string $dest, array $additionalOptions = []): void
|
||||
{
|
||||
$options = array();
|
||||
$options = [];
|
||||
|
||||
$options[] = $src;
|
||||
$options[] = $dest;
|
||||
@ -95,7 +97,7 @@ class Rclone
|
||||
}
|
||||
|
||||
$process = $this->exec('copy', $options);
|
||||
if (!$process->isSuccessful()) {
|
||||
if (! $process->isSuccessful()) {
|
||||
throw new Exception($process->getErrorOutput());
|
||||
}
|
||||
}
|
||||
@ -108,7 +110,7 @@ class Rclone
|
||||
*
|
||||
* @return Process Instance.
|
||||
*/
|
||||
private function exec(string $command, array $options = array()): Process
|
||||
private function exec(string $command, array $options = []): Process
|
||||
{
|
||||
$process = new Process(
|
||||
array_merge(
|
||||
@ -124,7 +126,7 @@ class Rclone
|
||||
$process->run();
|
||||
|
||||
// executes after the command finishes
|
||||
if (!$process->isSuccessful()) {
|
||||
if (! $process->isSuccessful()) {
|
||||
$this->logger->error("Failed execution");
|
||||
}
|
||||
$this->logger->info("Return code", [$process->getExitCode()]);
|
||||
|
@ -22,9 +22,9 @@ class TwigExtension extends AbstractExtension
|
||||
*/
|
||||
public function getFilters(): array
|
||||
{
|
||||
return array(
|
||||
new TwigFilter('formatBytes', array($this, 'formatBytes')),
|
||||
);
|
||||
return [
|
||||
new TwigFilter('formatBytes', [$this, 'formatBytes']),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user