More code standards
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Jens True 2023-06-05 09:40:04 +00:00
parent 668c375f4b
commit 9d0d188d01
6 changed files with 95 additions and 54 deletions

22
backup

@ -1,26 +1,6 @@
#!/usr/bin/env php
<?php
$autoload = null;
$autoloadFiles = [
__DIR__ . '/../vendor/autoload.php',
__DIR__ . '/../../../autoload.php',
__DIR__ . '/vendor/autoload.php'
];
foreach ($autoloadFiles as $autoloadFile) {
if (file_exists($autoloadFile)) {
$autoload = $autoloadFile;
break;
}
}
if (! $autoload) {
echo "Autoload file not found; try 'composer dump-autoload' first." . PHP_EOL;
exit(1);
}
require $autoload;
require __DIR__ . '/vendor/autoload.php';
use Symfony\Component\Console\Application;
use Composer\InstalledVersions;

45
composer.lock generated

@ -1666,25 +1666,29 @@
},
{
"name": "doctrine/deprecations",
"version": "v1.1.0",
"version": "v1.1.1",
"source": {
"type": "git",
"url": "https://github.com/doctrine/deprecations.git",
"reference": "8cffffb2218e01f3b370bf763e00e81697725259"
"reference": "612a3ee5ab0d5dd97b7cf3874a6efe24325efac3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/deprecations/zipball/8cffffb2218e01f3b370bf763e00e81697725259",
"reference": "8cffffb2218e01f3b370bf763e00e81697725259",
"url": "https://api.github.com/repos/doctrine/deprecations/zipball/612a3ee5ab0d5dd97b7cf3874a6efe24325efac3",
"reference": "612a3ee5ab0d5dd97b7cf3874a6efe24325efac3",
"shasum": ""
},
"require": {
"php": "^7.1|^8.0"
"php": "^7.1 || ^8.0"
},
"require-dev": {
"doctrine/coding-standard": "^9",
"phpunit/phpunit": "^7.5|^8.5|^9.5",
"psr/log": "^1|^2|^3"
"phpstan/phpstan": "1.4.10 || 1.10.15",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.5",
"psalm/plugin-phpunit": "0.18.4",
"psr/log": "^1 || ^2 || ^3",
"vimeo/psalm": "4.30.0 || 5.12.0"
},
"suggest": {
"psr/log": "Allows logging deprecations via PSR-3 logger implementation"
@ -1703,9 +1707,9 @@
"homepage": "https://www.doctrine-project.org/",
"support": {
"issues": "https://github.com/doctrine/deprecations/issues",
"source": "https://github.com/doctrine/deprecations/tree/v1.1.0"
"source": "https://github.com/doctrine/deprecations/tree/v1.1.1"
},
"time": "2023-05-29T18:55:17+00:00"
"time": "2023-06-03T09:27:29+00:00"
},
{
"name": "doctrine/instantiator",
@ -2532,22 +2536,23 @@
},
{
"name": "phpstan/phpdoc-parser",
"version": "1.21.3",
"version": "1.22.0",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpdoc-parser.git",
"reference": "b0c366dd2cea79407d635839d25423ba07c55dd6"
"reference": "ec58baf7b3c7f1c81b3b00617c953249fb8cf30c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/b0c366dd2cea79407d635839d25423ba07c55dd6",
"reference": "b0c366dd2cea79407d635839d25423ba07c55dd6",
"url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/ec58baf7b3c7f1c81b3b00617c953249fb8cf30c",
"reference": "ec58baf7b3c7f1c81b3b00617c953249fb8cf30c",
"shasum": ""
},
"require": {
"php": "^7.2 || ^8.0"
},
"require-dev": {
"doctrine/annotations": "^2.0",
"nikic/php-parser": "^4.15",
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpstan/extension-installer": "^1.0",
@ -2572,22 +2577,22 @@
"description": "PHPDoc parser with support for nullable, intersection and generic types",
"support": {
"issues": "https://github.com/phpstan/phpdoc-parser/issues",
"source": "https://github.com/phpstan/phpdoc-parser/tree/1.21.3"
"source": "https://github.com/phpstan/phpdoc-parser/tree/1.22.0"
},
"time": "2023-05-29T19:31:28+00:00"
"time": "2023-06-01T12:35:21+00:00"
},
{
"name": "phpstan/phpstan",
"version": "1.10.15",
"version": "1.10.16",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan.git",
"reference": "762c4dac4da6f8756eebb80e528c3a47855da9bd"
"reference": "352bdbb960bb523e3d71b834862589f910921c23"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/762c4dac4da6f8756eebb80e528c3a47855da9bd",
"reference": "762c4dac4da6f8756eebb80e528c3a47855da9bd",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/352bdbb960bb523e3d71b834862589f910921c23",
"reference": "352bdbb960bb523e3d71b834862589f910921c23",
"shasum": ""
},
"require": {
@ -2636,7 +2641,7 @@
"type": "tidelift"
}
],
"time": "2023-05-09T15:28:01+00:00"
"time": "2023-06-05T08:21:46+00:00"
},
{
"name": "phpunit/php-code-coverage",

@ -1,11 +0,0 @@
[2023-05-31T14:30:00.890085+00:00] app.INFO: Initialization complete [] []
[2023-05-31T14:30:00.946882+00:00] rclone.INFO: Execute command ["'rclone' 'size' '--json' 'temp/source'"] []
[2023-05-31T14:30:00.989664+00:00] rclone.INFO: Return code [0] []
[2023-05-31T14:30:00.989960+00:00] rclone.INFO: Execute command ["'rclone' 'size' '--json' 'temp/destination'"] []
[2023-05-31T14:30:01.047504+00:00] rclone.INFO: Return code [0] []
[2023-05-31T14:30:01.047810+00:00] rclone.INFO: Execute command ["'rclone' 'copy' 'temp/source' 'temp/destination' '--bwlimit' '6M'"] []
[2023-05-31T14:30:01.097485+00:00] rclone.INFO: Return code [0] []
[2023-05-31T14:30:01.097797+00:00] rclone.INFO: Execute command ["'rclone' 'size' '--json' 'temp/destination'"] []
[2023-05-31T14:30:01.142119+00:00] rclone.INFO: Return code [0] []
[2023-05-31T14:30:01.174134+00:00] notification.DEBUG: Sending ntfy notification {"topic":"backup","title":"Example","message":"Example\nFrom temp/source to temp/destination\nBackup started: May 31, 2023 14:30\nSource size: 8.00B\nDestination before: 8.00B\nDestination after: 8.00B\nDestination change : 0.00B\nBackup completed: May 31, 2023 14:30\n"} []
[2023-05-31T14:30:01.363282+00:00] notification.DEBUG: Result of ntfy notification ["{\"id\":\"iHfqUGi4dUsC\",\"time\":1685543401,\"expires\":1685586601,\"event\":\"message\",\"topic\":\"backup\",\"title\":\"Example\",\"message\":\"Example\\nFrom temp/source to temp/destination\\nBackup started: May 31, 2023 14:30\\nSource size: 8.00B\\nDestination before: 8.00B\\nDestination after: 8.00B\\nDestination change : 0.00B\\nBackup completed: May 31, 2023 14:30\"}\n"] []

@ -8,11 +8,25 @@ use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Psr\Log\NullLogger;
/**
* Application class
*
* Mostly working as a register pattern for the logging and configuration.
*
* @author Jens True <jens.chr.true@gmail.com>
* @license https://opensource.org/licenses/gpl-license.php GNU Public License
* @link https://jcktrue.dk
*/
class App
{
protected Logger $logger;
protected array $config;
/**
* Create a new instance providing a config file
*
* @param string $configFile Relative or full path to YML config.
*/
function __construct(string $configFile)
{
$this->config = Yaml::parseFile($configFile);
@ -26,12 +40,21 @@ class App
$this->logger = $logger;
}
/**
* Get the full configuration
*
* @return array Full configuration structure
*/
function getConfig() : array
{
return $this->config;
}
/**
* Get the logger instance.
*
* @return Logger Instance of logger
*/
function getLogger() : Logger
{
return $this->logger;

@ -9,7 +9,13 @@ use Symfony\Component\Process\Exception\ProcessFailedException;
use Exception;
/**
* Wrapper for the rclone command line utility
*
* Installation of rclone is required.
* Configuration of the mounts must be done before use.
* Tested using rclone v1.53.3-DEV
*/
class Rclone
{
use LoggerAwareTrait;
@ -24,6 +30,14 @@ class Rclone
protected string $version = "";
/**
* Create a new instance
*
* Default it looks for "rclone" on the path.
* But the path can be configured to be absolute.
*
* @param string $rclonePath Relative or absolute path
*/
function __construct(string $rclonePath = "rclone")
{
$this->rclonePath = $rclonePath;
@ -44,17 +58,35 @@ class Rclone
}
}
/**
* Get the rclone version
*
* @return string Version string
*/
function getVersion(): string
{
return $this->version;
}
/**
* Calculate the size of a mount/path
*
* @return int Size in bytes
*/
function getSize(string $path): int
{
$output = $this->exec('size', ['--json', $path]);
return (int)json_decode($output)->bytes;
}
/**
* Copy from src to dest
*
* @param $src Source mount and path
* @param $dest Destination mount and path
* @param $bandwidth Bandwidth limit provided as string
* @return string Stdout from command
*/
function copy(string $src, string $dest, string $bandwidth = null): string
{
$options = array();

@ -6,8 +6,20 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
/**
* Twig extension
*
* Additional formatters for templates
*
* @author Jens True <jens.chr.true@gmail.com>
* @license https://opensource.org/licenses/gpl-license.php GNU Public License
* @link https://jcktrue.dk
*/
class AppExtension extends AbstractExtension
{
/**
* Extend the filters
*/
public function getFilters()
{
return array(