PHPstan analysis.

This commit is contained in:
2023-05-26 13:04:15 +00:00
parent acd209b351
commit 4c8f71d9d8
8 changed files with 264 additions and 55 deletions

View File

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

View File

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

View File

@ -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",

View File

@ -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<string>
*/
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<String> $options
*/
protected function exec(string $command, array $options = array()) : string
{
$process = new Process(
array_merge(

View File

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