Static analysis cleanup.
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
notification:
|
||||
Ntfy:
|
||||
- type: Ntfy
|
||||
domain: https://ntfy.jcktrue.dk
|
||||
topic: backup
|
||||
log: output.log
|
||||
|
@ -54,7 +54,6 @@ class CommandBackup extends Command
|
||||
|
||||
foreach ($sio->progressIterate($app->getConfig()['backup']) as $conf) {
|
||||
$title = $conf['title'];
|
||||
$message = "";
|
||||
try {
|
||||
$template = array();
|
||||
$template['config'] = $conf;
|
||||
@ -63,7 +62,11 @@ class CommandBackup extends Command
|
||||
$template['rclone_version'] = $rclone->getVersion();
|
||||
$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['end'] = new DateTime();
|
||||
|
@ -19,9 +19,8 @@ class CommandShow extends Command
|
||||
{
|
||||
$this->addArgument(
|
||||
'config',
|
||||
InputArgument::OPTIONAL,
|
||||
'Configuration file',
|
||||
"config.yml"
|
||||
InputArgument::REQUIRED,
|
||||
'Configuration file'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -2,24 +2,44 @@
|
||||
|
||||
namespace App\Notification;
|
||||
|
||||
use App\Notification\Ntfy;
|
||||
|
||||
class Notification
|
||||
{
|
||||
/**
|
||||
* @type NotificationInterface[] $notifiers
|
||||
* @var NotificationInterface[] $notifiers
|
||||
*/
|
||||
public array $notifiers = array();
|
||||
|
||||
/**
|
||||
* Load multiple configurations
|
||||
*
|
||||
* @param array<array<string>> $config Array of notifier configurations.
|
||||
*/
|
||||
public function loadMany(array $config): void
|
||||
{
|
||||
foreach ($config as $key => $conf) {
|
||||
$this->loadSingle($key, $conf);
|
||||
foreach ($config as $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
|
||||
{
|
||||
$class = "\App\Notification\\" . $key;
|
||||
|
||||
$this->notifiers[$key] = new $class($config);
|
||||
switch ($key) {
|
||||
case 'ntfy':
|
||||
case 'Ntfy':
|
||||
case 'NTFY':
|
||||
$this->notifiers[] = new Ntfy($config);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function send(string $title, string $message): void
|
||||
|
@ -8,17 +8,21 @@ use Ntfy\Client;
|
||||
|
||||
class Ntfy implements NotificationInterface
|
||||
{
|
||||
/** @var string[] $config */
|
||||
private array $config;
|
||||
|
||||
private \Ntfy\Server $server;
|
||||
private \Ntfy\Client $client;
|
||||
|
||||
private Client $client;
|
||||
|
||||
/**
|
||||
* Initialize with configuration.
|
||||
*
|
||||
* @param string[] $config Configuration
|
||||
*/
|
||||
public function __construct(array $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
|
||||
$this->server = new Server($config['domain']);
|
||||
$this->client = new Client($this->server);
|
||||
$this->client = new Client(new Server($config['domain']));
|
||||
}
|
||||
|
||||
public function send(string $title, string $message): void
|
||||
|
@ -81,9 +81,9 @@ class Rclone
|
||||
/**
|
||||
* Copy from source to destination.
|
||||
*
|
||||
* @param $src Source mount and path
|
||||
* @param $dest Destination mount and path
|
||||
* @param $additionalOptions strings[] Bandwidth limit provided as string
|
||||
* @param $src Source mount and path
|
||||
* @param $dest Destination mount and path
|
||||
* @param string[] $additionalOptions Additional options
|
||||
*
|
||||
* @return string Stdout from command
|
||||
*/
|
||||
@ -93,6 +93,7 @@ class Rclone
|
||||
|
||||
$options[] = $src;
|
||||
$options[] = $dest;
|
||||
|
||||
foreach ($additionalOptions as $key => $value) {
|
||||
if (strlen($key) == 1) {
|
||||
$options[] = '-' . $key;
|
||||
@ -100,8 +101,6 @@ class Rclone
|
||||
} elseif (strlen($key) > 2) {
|
||||
$options[] = '--' . $key;
|
||||
$options[] = $value;
|
||||
} else {
|
||||
$options[] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user