Static analysis cleanup.
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Jens True 2023-06-13 08:15:29 +00:00
parent 0f3bbf1f47
commit 4ffac17b62
6 changed files with 47 additions and 22 deletions

@ -1,5 +1,5 @@
notification: notification:
Ntfy: - type: Ntfy
domain: https://ntfy.jcktrue.dk domain: https://ntfy.jcktrue.dk
topic: backup topic: backup
log: output.log log: output.log

@ -54,7 +54,6 @@ class CommandBackup extends Command
foreach ($sio->progressIterate($app->getConfig()['backup']) as $conf) { foreach ($sio->progressIterate($app->getConfig()['backup']) as $conf) {
$title = $conf['title']; $title = $conf['title'];
$message = "";
try { try {
$template = array(); $template = array();
$template['config'] = $conf; $template['config'] = $conf;
@ -63,7 +62,11 @@ class CommandBackup extends Command
$template['rclone_version'] = $rclone->getVersion(); $template['rclone_version'] = $rclone->getVersion();
$template['destination_size_before'] = $rclone->getSize($conf['destination']); $template['destination_size_before'] = $rclone->getSize($conf['destination']);
$template['stdout'] = $rclone->copy($conf['source'], $conf['destination'], $app->getConfig()['rclone']['options']); $template['stdout'] = $rclone->copy(
$conf['source'],
$conf['destination'],
$app->getConfig()['rclone']['options']
);
$template['destination_size_after'] = $rclone->getSize($conf['destination']); $template['destination_size_after'] = $rclone->getSize($conf['destination']);
$template['end'] = new DateTime(); $template['end'] = new DateTime();

@ -19,9 +19,8 @@ class CommandShow extends Command
{ {
$this->addArgument( $this->addArgument(
'config', 'config',
InputArgument::OPTIONAL, InputArgument::REQUIRED,
'Configuration file', 'Configuration file'
"config.yml"
); );
} }

@ -2,24 +2,44 @@
namespace App\Notification; namespace App\Notification;
use App\Notification\Ntfy;
class Notification class Notification
{ {
/** /**
* @type NotificationInterface[] $notifiers * @var NotificationInterface[] $notifiers
*/ */
public array $notifiers = array(); public array $notifiers = array();
/**
* Load multiple configurations
*
* @param array<array<string>> $config Array of notifier configurations.
*/
public function loadMany(array $config): void public function loadMany(array $config): void
{ {
foreach ($config as $key => $conf) { foreach ($config as $conf) {
$this->loadSingle($key, $conf); $this->loadSingle($conf['type'], $conf);
} }
} }
/**
* Load a single configuration
*
* @param string $key Notification class
* @param string[] $config Implementation specific configuration
*/
public function loadSingle(string $key, array $config): void public function loadSingle(string $key, array $config): void
{ {
$class = "\App\Notification\\" . $key; switch ($key) {
case 'ntfy':
$this->notifiers[$key] = new $class($config); case 'Ntfy':
case 'NTFY':
$this->notifiers[] = new Ntfy($config);
break;
default:
break;
}
} }
public function send(string $title, string $message): void public function send(string $title, string $message): void

@ -8,17 +8,21 @@ use Ntfy\Client;
class Ntfy implements NotificationInterface class Ntfy implements NotificationInterface
{ {
/** @var string[] $config */
private array $config; private array $config;
private \Ntfy\Server $server; private Client $client;
private \Ntfy\Client $client;
/**
* Initialize with configuration.
*
* @param string[] $config Configuration
*/
public function __construct(array $config) public function __construct(array $config)
{ {
$this->config = $config; $this->config = $config;
$this->server = new Server($config['domain']); $this->client = new Client(new Server($config['domain']));
$this->client = new Client($this->server);
} }
public function send(string $title, string $message): void public function send(string $title, string $message): void

@ -81,9 +81,9 @@ class Rclone
/** /**
* Copy from source to destination. * Copy from source to destination.
* *
* @param $src Source mount and path * @param $src Source mount and path
* @param $dest Destination mount and path * @param $dest Destination mount and path
* @param $additionalOptions strings[] Bandwidth limit provided as string * @param string[] $additionalOptions Additional options
* *
* @return string Stdout from command * @return string Stdout from command
*/ */
@ -93,6 +93,7 @@ class Rclone
$options[] = $src; $options[] = $src;
$options[] = $dest; $options[] = $dest;
foreach ($additionalOptions as $key => $value) { foreach ($additionalOptions as $key => $value) {
if (strlen($key) == 1) { if (strlen($key) == 1) {
$options[] = '-' . $key; $options[] = '-' . $key;
@ -100,8 +101,6 @@ class Rclone
} elseif (strlen($key) > 2) { } elseif (strlen($key) > 2) {
$options[] = '--' . $key; $options[] = '--' . $key;
$options[] = $value; $options[] = $value;
} else {
$options[] = $value;
} }
} }