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

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

View File

@ -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;

View File

@ -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();

View File

@ -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(