diff --git a/composer.json b/composer.json index 5a4e417..2a5132a 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,8 @@ "symfony/console": "^5.4", "symfony/yaml": "^5.4", "twig/twig": "^3.6", - "symfony/process": "^5.4" + "symfony/process": "^5.4", + "monolog/monolog": "^2.9" }, "autoload": { "psr-4": { @@ -11,6 +12,7 @@ } }, "require-dev": { - "squizlabs/php_codesniffer": "*" + "squizlabs/php_codesniffer": "*", + "phpstan/phpstan": "^1.10" } } diff --git a/composer.lock b/composer.lock index b9a32b6..b44f1cb 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,110 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d3057be657b112629e5a71cc9d06ebed", + "content-hash": "c0867492125ff49535b74116a2803d90", "packages": [ + { + "name": "monolog/monolog", + "version": "2.9.1", + "source": { + "type": "git", + "url": "https://github.com/Seldaek/monolog.git", + "reference": "f259e2b15fb95494c83f52d3caad003bbf5ffaa1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/f259e2b15fb95494c83f52d3caad003bbf5ffaa1", + "reference": "f259e2b15fb95494c83f52d3caad003bbf5ffaa1", + "shasum": "" + }, + "require": { + "php": ">=7.2", + "psr/log": "^1.0.1 || ^2.0 || ^3.0" + }, + "provide": { + "psr/log-implementation": "1.0.0 || 2.0.0 || 3.0.0" + }, + "require-dev": { + "aws/aws-sdk-php": "^2.4.9 || ^3.0", + "doctrine/couchdb": "~1.0@dev", + "elasticsearch/elasticsearch": "^7 || ^8", + "ext-json": "*", + "graylog2/gelf-php": "^1.4.2 || ^2@dev", + "guzzlehttp/guzzle": "^7.4", + "guzzlehttp/psr7": "^2.2", + "mongodb/mongodb": "^1.8", + "php-amqplib/php-amqplib": "~2.4 || ^3", + "phpspec/prophecy": "^1.15", + "phpstan/phpstan": "^0.12.91", + "phpunit/phpunit": "^8.5.14", + "predis/predis": "^1.1 || ^2.0", + "rollbar/rollbar": "^1.3 || ^2 || ^3", + "ruflin/elastica": "^7", + "swiftmailer/swiftmailer": "^5.3|^6.0", + "symfony/mailer": "^5.4 || ^6", + "symfony/mime": "^5.4 || ^6" + }, + "suggest": { + "aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB", + "doctrine/couchdb": "Allow sending log messages to a CouchDB server", + "elasticsearch/elasticsearch": "Allow sending log messages to an Elasticsearch server via official client", + "ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)", + "ext-curl": "Required to send log messages using the IFTTTHandler, the LogglyHandler, the SendGridHandler, the SlackWebhookHandler or the TelegramBotHandler", + "ext-mbstring": "Allow to work properly with unicode symbols", + "ext-mongodb": "Allow sending log messages to a MongoDB server (via driver)", + "ext-openssl": "Required to send log messages using SSL", + "ext-sockets": "Allow sending log messages to a Syslog server (via UDP driver)", + "graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server", + "mongodb/mongodb": "Allow sending log messages to a MongoDB server (via library)", + "php-amqplib/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib", + "rollbar/rollbar": "Allow sending log messages to Rollbar", + "ruflin/elastica": "Allow sending log messages to an Elastic Search server" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "2.x-dev" + } + }, + "autoload": { + "psr-4": { + "Monolog\\": "src/Monolog" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "https://seld.be" + } + ], + "description": "Sends your logs to files, sockets, inboxes, databases and various web services", + "homepage": "https://github.com/Seldaek/monolog", + "keywords": [ + "log", + "logging", + "psr-3" + ], + "support": { + "issues": "https://github.com/Seldaek/monolog/issues", + "source": "https://github.com/Seldaek/monolog/tree/2.9.1" + }, + "funding": [ + { + "url": "https://github.com/Seldaek", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/monolog/monolog", + "type": "tidelift" + } + ], + "time": "2023-02-06T13:44:46+00:00" + }, { "name": "psr/container", "version": "1.1.2", @@ -54,6 +156,56 @@ }, "time": "2021-11-05T16:50:12+00:00" }, + { + "name": "psr/log", + "version": "1.1.4", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "d49695b909c3b7628b6289db5479a1c204601f11" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/d49695b909c3b7628b6289db5479a1c204601f11", + "reference": "d49695b909c3b7628b6289db5479a1c204601f11", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "Psr/Log/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "support": { + "source": "https://github.com/php-fig/log/tree/1.1.4" + }, + "time": "2021-05-03T11:20:27+00:00" + }, { "name": "symfony/console", "version": "v5.4.23", @@ -1092,56 +1244,101 @@ ], "packages-dev": [ { - "name": "squizlabs/php_codesniffer", - "version": "2.2.0", + "name": "phpstan/phpstan", + "version": "1.10.15", "source": { "type": "git", - "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "b301c98f19414d836fdaa678648745fcca5aeb4f" + "url": "https://github.com/phpstan/phpstan.git", + "reference": "762c4dac4da6f8756eebb80e528c3a47855da9bd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/b301c98f19414d836fdaa678648745fcca5aeb4f", - "reference": "b301c98f19414d836fdaa678648745fcca5aeb4f", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/762c4dac4da6f8756eebb80e528c3a47855da9bd", + "reference": "762c4dac4da6f8756eebb80e528c3a47855da9bd", "shasum": "" }, "require": { - "ext-tokenizer": "*", - "php": ">=5.1.2" + "php": "^7.2|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" }, "bin": [ - "scripts/phpcs", - "scripts/phpcbf" + "phpstan", + "phpstan.phar" ], "type": "library", "autoload": { - "classmap": [ - "CodeSniffer.php", - "CodeSniffer/CLI.php", - "CodeSniffer/Exception.php", - "CodeSniffer/File.php", - "CodeSniffer/Fixer.php", - "CodeSniffer/Report.php", - "CodeSniffer/Reporting.php", - "CodeSniffer/Sniff.php", - "CodeSniffer/Tokens.php", - "CodeSniffer/Reports/", - "CodeSniffer/Tokenizers/", - "CodeSniffer/DocGenerators/", - "CodeSniffer/Standards/AbstractPatternSniff.php", - "CodeSniffer/Standards/AbstractScopeSniff.php", - "CodeSniffer/Standards/AbstractVariableSniff.php", - "CodeSniffer/Standards/IncorrectPatternException.php", - "CodeSniffer/Standards/Generic/Sniffs/", - "CodeSniffer/Standards/MySource/Sniffs/", - "CodeSniffer/Standards/PEAR/Sniffs/", - "CodeSniffer/Standards/PSR1/Sniffs/", - "CodeSniffer/Standards/PSR2/Sniffs/", - "CodeSniffer/Standards/Squiz/Sniffs/", - "CodeSniffer/Standards/Zend/Sniffs/" + "files": [ + "bootstrap.php" ] }, "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", + "issues": "https://github.com/phpstan/phpstan/issues", + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", + "type": "tidelift" + } + ], + "time": "2023-05-09T15:28:01+00:00" + }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.7.2", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "ed8e00df0a83aa96acf703f8c2979ff33341f879" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/ed8e00df0a83aa96acf703f8c2979ff33341f879", + "reference": "ed8e00df0a83aa96acf703f8c2979ff33341f879", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "bin": [ + "bin/phpcs", + "bin/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", "license": [ "BSD-3-Clause" ], @@ -1152,17 +1349,18 @@ } ], "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", - "homepage": "http://www.squizlabs.com/php-codesniffer", + "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", "keywords": [ "phpcs", - "standards" + "standards", + "static analysis" ], "support": { "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues", "source": "https://github.com/squizlabs/PHP_CodeSniffer", "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" }, - "time": "2015-01-21T22:44:05+00:00" + "time": "2023-02-22T23:07:41+00:00" } ], "aliases": [], diff --git a/config.example.yml b/config.example.yml index 682d401..ad6573c 100644 --- a/config.example.yml +++ b/config.example.yml @@ -3,7 +3,7 @@ notification: topic: backup backup: - title: Example - source: test/srcdasasda + source: test/src destination: test/dest templates: notify: | diff --git a/src/CommandBackup.php b/src/CommandBackup.php index 074690b..baf1dee 100644 --- a/src/CommandBackup.php +++ b/src/CommandBackup.php @@ -28,6 +28,7 @@ class CommandBackup extends Command $config = Yaml::parseFile($input->getArgument('config')); } catch (ParseException $e) { $output->writeln('Unable to parse the YAML string: '. $e->getMessage()); + return Command::FAILURE; } $rclone = new Rclone\Rclone(); diff --git a/src/CommandShow.php b/src/CommandShow.php index c9f780a..aacfe3e 100644 --- a/src/CommandShow.php +++ b/src/CommandShow.php @@ -27,6 +27,7 @@ class CommandShow extends Command $config = Yaml::parseFile($input->getArgument('config')); } catch (ParseException $e) { $output->writeln('Unable to parse the YAML string: '. $e->getMessage()); + return Command::FAILURE; } $table = new Table($output); $table diff --git a/src/Ntfy/Ntfy.php b/src/Ntfy/Ntfy.php index 8ed90b0..3d046ef 100644 --- a/src/Ntfy/Ntfy.php +++ b/src/Ntfy/Ntfy.php @@ -3,19 +3,18 @@ namespace App\Ntfy; class Ntfy { - protected $domain; - function __construct($domain) + protected string $domain; + function __construct(string $domain) { $this->domain = $domain; } - function send($topic,$title, $message) + function send(string $topic, string $title, string $message): void { file_get_contents( 'https://'.$this->domain.'/'.$topic, false, stream_context_create( ['http' => [ 'method' => 'POST', - 'header' => 'Content-Type: text/plain', 'header' => "Content-Type: text/plain\r\n" . "Title: $title\r\n", diff --git a/src/Rclone/Rclone.php b/src/Rclone/Rclone.php index 7745db8..5b663ca 100644 --- a/src/Rclone/Rclone.php +++ b/src/Rclone/Rclone.php @@ -6,27 +6,31 @@ use Symfony\Component\Process\Exception\ProcessFailedException; class Rclone { - protected $rclone_path; - protected $global_options = []; + protected string $rclone_path; + /** + * Global options + * + * @var array + */ + protected array $global_options = []; - function __construct($rclone_path = "rclone") + function __construct(string $rclone_path = "rclone") { $this->rclone_path = $rclone_path; } - function getVersion() + function getVersion(): string { return $this->exec('--version'); } - function getSize($path) + function getSize(string $path): int { $output = $this->exec('size', ['--json', $path]); - - return (int)json_decode($output[0])->bytes; + return (int)json_decode($output)->bytes; } - function copy($src, $dest, $bandwidth = null) + function copy(string $src, string $dest, string $bandwidth = null): string { $options = array(); @@ -40,7 +44,11 @@ class Rclone return $this->exec('copy', $options); } - protected function exec(string $command, array $options = array()) + /** + * @param $command Top level Rclone command + * @param array $options + */ + protected function exec(string $command, array $options = array()) : string { $process = new Process( array_merge( diff --git a/src/Twig/AppExtension.php b/src/Twig/AppExtension.php index 9e63863..6894b2e 100644 --- a/src/Twig/AppExtension.php +++ b/src/Twig/AppExtension.php @@ -24,7 +24,7 @@ class AppExtension extends AbstractExtension public function formatBytes($bytes, $precision = 2) { $size = ['B','kB','MB','GB','TB','PB','EB','ZB','YB']; - $fact = floor((strlen($bytes) - 1) / 3); + $fact = floor((strlen((string)$bytes) - 1) / 3); return sprintf("%.{$precision}f", $bytes / pow(1024, $fact)) . $size[$fact]; }