From c1fb42c4ff5c6298054cb41dca3bfdb376459c01 Mon Sep 17 00:00:00 2001 From: Jens True Date: Wed, 5 Jul 2023 14:36:56 +0000 Subject: [PATCH] More type deconfusion --- composer.lock | 10 +++++----- src/App.php | 6 ++++-- src/CommandBackup.php | 15 +++++++++------ src/CommandShow.php | 5 +++-- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/composer.lock b/composer.lock index 0976451..22cf681 100644 --- a/composer.lock +++ b/composer.lock @@ -3228,16 +3228,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.22", + "version": "1.10.24", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "97d694dfd4ceb57bcce4e3b38548f13ea62e4287" + "reference": "360ecc90569e9a60c2954ee209ec04fa0d958e14" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/97d694dfd4ceb57bcce4e3b38548f13ea62e4287", - "reference": "97d694dfd4ceb57bcce4e3b38548f13ea62e4287", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/360ecc90569e9a60c2954ee209ec04fa0d958e14", + "reference": "360ecc90569e9a60c2954ee209ec04fa0d958e14", "shasum": "" }, "require": { @@ -3286,7 +3286,7 @@ "type": "tidelift" } ], - "time": "2023-06-30T20:04:11+00:00" + "time": "2023-07-05T12:32:13+00:00" }, { "name": "phpunit/php-code-coverage", diff --git a/src/App.php b/src/App.php index c21a538..75655f7 100644 --- a/src/App.php +++ b/src/App.php @@ -58,6 +58,7 @@ class App ]); $parser = new Yaml(); + /** @var array */ $parsedConfig = $parser->parseFile($configFile); @@ -66,7 +67,7 @@ class App $logger = new Logger('app'); if ($this->config->get('log')) { - $logger->pushHandler(new StreamHandler($this->config->get('log'))); + $logger->pushHandler(new StreamHandler((string)$this->config->get('log'))); $logger->info("Logging enabled"); } $logger->info("Initialization complete"); @@ -82,8 +83,9 @@ class App */ public function getConfig(string $key): mixed { + /** @var mixed */ $ret = $this->config->get($key); - $this->logger->debug("Fetching configuration key", [$key,$ret]); + $this->logger->debug("Fetching configuration key", [$key, $ret]); return $ret; } diff --git a/src/CommandBackup.php b/src/CommandBackup.php index ba275a7..95fcca5 100644 --- a/src/CommandBackup.php +++ b/src/CommandBackup.php @@ -40,7 +40,7 @@ class CommandBackup extends Command return Command::FAILURE; } - $rclone = new Rclone($app->getConfig('rclone.path')); + $rclone = new Rclone((string)$app->getConfig('rclone.path')); $rclone->setLogger($app->getLogger()->withName('rclone')); $notification = new Notification(); @@ -48,19 +48,22 @@ class CommandBackup extends Command $render = new Twig($app->getConfig('templates')); + /** @var array{title: string, source: string, destination: string} $conf */ foreach ($sio->progressIterate($app->getConfig('backup')) as $conf) { $title = $conf['title']; try { $template = array(); $template['config'] = $conf; $template['start'] = new DateTime(); - $template['source_size'] = $rclone->getSize((string)$conf['source']); + $template['source_size'] = $rclone->getSize($conf['source']); $template['rclone_version'] = $rclone->getVersion(); - $template['destination_size_before'] = $rclone->getSize((string)$conf['destination']); + $template['destination_size_before'] = $rclone->getSize($conf['destination']); - $rclone->copy((string)$conf['source'], (string)$conf['destination'], $app->getConfig('rclone.options')); + /** @var array */ + $rcloneOptions = $app->getConfig('rclone.options'); + $rclone->copy($conf['source'], $conf['destination'], $rcloneOptions); - $template['destination_size_after'] = $rclone->getSize((string)$conf['destination']); + $template['destination_size_after'] = $rclone->getSize($conf['destination']); $template['end'] = new DateTime(); $message = $render->render('notify', $template); @@ -68,7 +71,7 @@ class CommandBackup extends Command $message = $e->getMessage(); } - $notification->send((string)$title, $message); + $notification->send($title, $message); } $sio->success("Complete"); diff --git a/src/CommandShow.php b/src/CommandShow.php index b63f765..0bcedc1 100644 --- a/src/CommandShow.php +++ b/src/CommandShow.php @@ -35,10 +35,11 @@ class CommandShow extends Command $sio->error('Configuration error: ' . $e->getMessage()); return Command::FAILURE; } - + /** @var array{title: string, source: string, destination: string}[] */ + $backupElements = $app->getConfig('backup'); $sio->table( ['Description', 'Source', 'Destination'], - $app->getConfig('backup') + $backupElements ); $sio->success("Done");