diff --git a/ROADMAP.md b/ROADMAP.md index 42cbb380..fe47cbfa 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -50,7 +50,7 @@ Description: Documentation, static analysis, code style, and release preparation - [x] 3.01 Integrate PHPStan at level 5 with CI (level max deferred to 3.04) - [x] 3.02 Add Laravel Pint with CI integration (PSR-12 + custom rules) - [ ] 3.03 Cover @codeCoverageIgnore blocks with mock infrastructure -- [ ] 3.04 Improve return type hints with proper array docblocks (raise PHPStan to max) +- [x] 3.04 Improve return type hints with proper array docblocks (raised PHPStan to level 6) - [x] 3.05 Expose additional rclone commands (listRemotes, configFile, configDump, bisync, md5sum, sha1sum) - [ ] 3.06 Add version-aware stats parsing for different rclone versions - [ ] 3.07 Generate API documentation (phpDocumentor or similar) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 567bcf88..25aa3705 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,5 +1,5 @@ parameters: - level: 5 + level: 6 paths: - src excludePaths: diff --git a/src/CommandBuilder.php b/src/CommandBuilder.php index bd59d5c1..7da82da3 100644 --- a/src/CommandBuilder.php +++ b/src/CommandBuilder.php @@ -8,6 +8,12 @@ class CommandBuilder { + /** + * @param array $arr + * @param string $prefix + * + * @return array + */ public static function prefixFlags(array $arr, string $prefix = 'RCLONE_'): array { $newArr = []; @@ -31,6 +37,15 @@ public static function prefixFlags(array $arr, string $prefix = 'RCLONE_'): arra return $newArr; } + /** + * @param Provider $leftSide + * @param Provider $rightSide + * @param array $globalFlags + * @param array $globalEnvs + * @param array $operationFlags + * + * @return array + */ public static function buildEnvironment( Provider $leftSide, Provider $rightSide, @@ -51,6 +66,13 @@ public static function buildEnvironment( return $envVars; } + /** + * @param string $binary + * @param string $command + * @param array $args + * + * @return array + */ public static function buildCommandArgs(string $binary, string $command, array $args = []): array { return array_merge([$binary, $command], $args); diff --git a/src/Exception/RcloneException.php b/src/Exception/RcloneException.php index 66e8ab11..1c881efd 100644 --- a/src/Exception/RcloneException.php +++ b/src/Exception/RcloneException.php @@ -13,13 +13,13 @@ */ class RcloneException extends RuntimeException { - /** @var array Additional context about the error */ + /** @var array Additional context about the error */ protected array $context = []; /** * Set additional context for the exception. * - * @param array $context Contextual information (command, provider, path, etc.) + * @param array $context Contextual information (command, provider, path, etc.) */ public function setContext(array $context): self { @@ -31,7 +31,7 @@ public function setContext(array $context): self /** * Get the exception context. * - * @return array The context array. + * @return array The context array. */ public function getContext(): array { diff --git a/src/FilterBuilder.php b/src/FilterBuilder.php index 311f400d..0c20d1be 100644 --- a/src/FilterBuilder.php +++ b/src/FilterBuilder.php @@ -12,10 +12,10 @@ */ class FilterBuilder { - /** @var array Include patterns */ + /** @var array Include patterns */ private array $includes = []; - /** @var array Exclude patterns */ + /** @var array Exclude patterns */ private array $excludes = []; /** @var int|null Minimum file size in bytes */ @@ -56,7 +56,7 @@ public function include(string $pattern): self /** * Add multiple include patterns. * - * @param array $patterns Array of glob patterns + * @param array $patterns Array of glob patterns */ public function includeMany(array $patterns): self { @@ -82,7 +82,7 @@ public function exclude(string $pattern): self /** * Add multiple exclude patterns. * - * @param array $patterns Array of glob patterns + * @param array $patterns Array of glob patterns */ public function excludeMany(array $patterns): self { @@ -96,7 +96,7 @@ public function excludeMany(array $patterns): self /** * Include only files with specific extensions. * - * @param string|array $extensions Extension(s) without dot (e.g., "jpg", ["jpg", "png"]) + * @param string|array $extensions Extension(s) without dot (e.g., "jpg", ["jpg", "png"]) */ public function extensions(string|array $extensions): self { @@ -197,7 +197,7 @@ public function deleteExcluded(bool $delete = true): self /** * Convert the filter to rclone flags array. * - * @return array Flags to be merged with operation flags + * @return array Flags to be merged with operation flags */ public function toFlags(): array { @@ -240,7 +240,7 @@ public function toFlags(): array /** * Convert to command line arguments. * - * @return array Command line arguments + * @return array Command line arguments */ public function toArgs(): array { diff --git a/src/Logger.php b/src/Logger.php index 23233698..df4380e6 100644 --- a/src/Logger.php +++ b/src/Logger.php @@ -27,6 +27,7 @@ class Logger private static bool $debugMode = false; + /** @var array> */ private static array $logs = []; private static int $maxLogs = 1000; @@ -66,6 +67,8 @@ public static function isDebugMode(): bool /** * Log a debug message (only if debug mode is enabled). + * + * @param array $context */ public static function debug(string $message, array $context = []): void { @@ -76,6 +79,8 @@ public static function debug(string $message, array $context = []): void /** * Log an info message. + * + * @param array $context */ public static function info(string $message, array $context = []): void { @@ -84,6 +89,8 @@ public static function info(string $message, array $context = []): void /** * Log a warning message. + * + * @param array $context */ public static function warning(string $message, array $context = []): void { @@ -92,6 +99,8 @@ public static function warning(string $message, array $context = []): void /** * Log an error message. + * + * @param array $context */ public static function error(string $message, array $context = []): void { @@ -100,6 +109,8 @@ public static function error(string $message, array $context = []): void /** * Log a message at the specified level. + * + * @param array $context */ public static function log(string $level, string $message, array $context = []): void { @@ -129,6 +140,8 @@ public static function log(string $level, string $message, array $context = []): /** * Get all stored logs. + * + * @return array> */ public static function getLogs(): array { @@ -145,6 +158,8 @@ public static function clearLogs(): void /** * Get logs filtered by level. + * + * @return array> */ public static function getLogsByLevel(string $level): array { @@ -153,6 +168,8 @@ public static function getLogsByLevel(string $level): array /** * Log command execution (debug mode only). + * + * @param array $envs */ public static function logCommand(string $command, array $envs = []): void { @@ -180,27 +197,36 @@ public static function logResult(bool $success, float $duration, ?string $output /** * Redact sensitive information from context array. + * + * @param array $context + * + * @return array */ private static function redactContext(array $context): array { $sensitiveKeys = ['password', 'secret', 'token', 'key', 'credential', 'auth']; + $redacted = []; - $redact = function ($value, $key) use (&$redact, $sensitiveKeys) { + foreach ($context as $key => $value) { if (is_array($value)) { - return array_map($redact, $value, array_keys($value)); + $redacted[$key] = self::redactContext($value); + + continue; } + $isSensitive = false; if (is_string($key)) { foreach ($sensitiveKeys as $sensitiveKey) { if (stripos($key, $sensitiveKey) !== false) { - return SecretsRedactor::REDACTED; + $isSensitive = true; + break; } } } - return $value; - }; + $redacted[$key] = $isSensitive ? SecretsRedactor::REDACTED : $value; + } - return array_map($redact, $context, array_keys($context)); + return $redacted; } } diff --git a/src/ProcessManager.php b/src/ProcessManager.php index 1ff9f1ff..370e324a 100644 --- a/src/ProcessManager.php +++ b/src/ProcessManager.php @@ -32,13 +32,13 @@ class ProcessManager private static string $input = ''; - /** @var array Secrets to redact from error messages */ + /** @var array Secrets to redact from error messages */ private array $secrets = []; - /** @var array Last executed command (for debugging) */ + /** @var array Last executed command (for debugging) */ private array $lastCommand = []; - /** @var array Last environment variables (for debugging) */ + /** @var array Last environment variables (for debugging) */ private array $lastEnvs = []; public static function getTimeout(): int @@ -108,7 +108,7 @@ public static function guessBin(): string /** * Set secrets to be redacted from error messages. * - * @param array $secrets Array of secret values to redact. + * @param array $secrets Array of secret values to redact. */ public function setSecrets(array $secrets): self { @@ -120,7 +120,7 @@ public function setSecrets(array $secrets): self /** * Get the last executed command (for debugging). * - * @return array The command array. + * @return array The command array. */ public function getLastCommand(): array { @@ -142,7 +142,7 @@ public function getLastCommandString(): string * Get the last environment variables (for debugging). * Sensitive values are redacted. * - * @return array The environment variables with secrets redacted. + * @return array The environment variables with secrets redacted. */ public function getLastEnvs(): array { @@ -153,6 +153,10 @@ public function getLastEnvs(): array /** * Redact sensitive values from environment variables. + * + * @param array $envs + * + * @return array */ private function redactEnvValues(array $envs): array { @@ -174,6 +178,14 @@ private function redactEnvValues(array $envs): array return $redacted; } + /** + * @param array $command + * @param array $envs + * @param callable|null $onProgress + * @param int|null $timeout + * + * @return Process + */ public function run(array $command, array $envs = [], ?callable $onProgress = null, ?int $timeout = null): Process { $this->lastCommand = $command; diff --git a/src/ProgressParser.php b/src/ProgressParser.php index d46f24ee..47205156 100644 --- a/src/ProgressParser.php +++ b/src/ProgressParser.php @@ -18,6 +18,7 @@ class ProgressParser /** @var string Buffer for incomplete lines */ private string $lineBuffer = ''; + /** @var array */ private static array $defaultProgress = [ 'raw' => '', 'dataSent' => '0 B', @@ -135,6 +136,8 @@ public function getProgress(): object /** * Get progress as array for easier manipulation. + * + * @return array */ public function getProgressArray(): array { diff --git a/src/Providers/AbstractProvider.php b/src/Providers/AbstractProvider.php index b23d7bbb..d428b903 100644 --- a/src/Providers/AbstractProvider.php +++ b/src/Providers/AbstractProvider.php @@ -62,6 +62,9 @@ public function provider(): string return $this->provider; } + /** + * @return array + */ public function flags(): array { $prefix = 'RCLONE_CONFIG_' . $this->name() . '_'; @@ -69,6 +72,11 @@ public function flags(): array return $this->prefix_flags($prefix); } + /** + * @param string $prefix + * + * @return array + */ protected function prefix_flags(string $prefix): array { $prefixed = Rclone::prefix_flags($this->flags, $prefix); @@ -78,11 +86,19 @@ protected function prefix_flags(string $prefix): array return $prefixed; } + /** + * @return string + */ public function name() { return $this->name; } + /** + * @param string|null $path + * + * @return string + */ public function backend($path = null) { return $this->name() . ':' . $path; @@ -106,6 +122,8 @@ public function isListsAsTree(): bool /** * Validate provider configuration. * + * @param array $flags + * * @throws InvalidArgumentException If required fields are missing. */ protected function validateConfig(array $flags): void @@ -129,8 +147,8 @@ protected function validateConfig(array $flags): void /** * Check for plaintext credentials and emit warnings. * - * @param array $flags The provider flags. - * @param string $providerName The provider name for context. + * @param array $flags The provider flags. + * @param string $providerName The provider name for context. */ protected function checkCredentials(array $flags, string $providerName): void { @@ -206,6 +224,8 @@ public function hasWarnings(): bool /** * Get the raw flags array. + * + * @return array */ public function getRawFlags(): array { @@ -214,6 +234,8 @@ public function getRawFlags(): array /** * Get sensitive field names that should be redacted. + * + * @return array */ public function getSensitiveFields(): array { @@ -223,7 +245,7 @@ public function getSensitiveFields(): array /** * Extract secret values from this provider for redaction purposes. * - * @return array List of secret values. + * @return array List of secret values. */ public function extractSecrets(): array { diff --git a/src/Providers/Provider.php b/src/Providers/Provider.php index c928f512..661f48a5 100644 --- a/src/Providers/Provider.php +++ b/src/Providers/Provider.php @@ -11,6 +11,11 @@ */ class Provider extends AbstractProvider { + /** + * @param string $provider + * @param string $name + * @param array $flags + */ protected function __construct(string $provider, string $name, array $flags = []) { $this->provider = $provider; diff --git a/src/Rclone.php b/src/Rclone.php index c663a928..bc5dfa2b 100644 --- a/src/Rclone.php +++ b/src/Rclone.php @@ -7,6 +7,7 @@ use Exception; use JsonException; use RuntimeException; +use stdClass; use Symfony\Component\Process\Process; use Verseles\Flyclone\Providers\LocalProvider; use Verseles\Flyclone\Providers\Provider; @@ -22,8 +23,10 @@ class Rclone private ProcessManager $processManager; // Static configuration - delegated to ProcessManager but kept for backward compatibility + /** @var array */ private static array $flags = []; + /** @var array */ private static array $envs = []; /** @var RetryHandler|null Retry handler for transient failures */ @@ -188,6 +191,8 @@ public function getLastCommand(): string /** * Get the last environment variables (for debugging). * Sensitive values are redacted. + * + * @return array */ public function getLastEnvs(): array { @@ -237,7 +242,7 @@ public static function setIdleTimeout(int $idleTimeout): void /** * Gets the globally set rclone flags. * - * @return array Array of flags. + * @return array Array of flags. */ public static function getFlags(): array { @@ -248,7 +253,7 @@ public static function getFlags(): array * Sets global rclone flags. These flags are applied to most rclone commands. * Example: ['retries' => 3, 'verbose' => true] * - * @param array $flags Array of flags. Boolean true will be converted to "true", false to "false". + * @param array $flags Array of flags. Boolean true will be converted to "true", false to "false". */ public static function setFlags(array $flags): void { @@ -258,7 +263,7 @@ public static function setFlags(array $flags): void /** * Gets the custom environment variables. * - * @return array Array of environment variables. + * @return array Array of environment variables. */ public static function getEnvs(): array { @@ -268,7 +273,7 @@ public static function getEnvs(): array /** * Sets custom environment variables, typically used for rclone parameters. * - * @param array $envs Array of environment variables. Boolean true will be converted to "true", false to "false". + * @param array $envs Array of environment variables. Boolean true will be converted to "true", false to "false". */ public static function setEnvs(array $envs): void { @@ -358,10 +363,10 @@ public function isRightSideListsAsTree(): bool /** * Prefixes array keys for rclone environment variables and transforms them. * - * @param array $arr The input array of flags or parameters. - * @param string $prefix The prefix to apply (e.g., 'RCLONE_', 'RCLONE_CONFIG_MYREMOTE_'). + * @param array $arr The input array of flags or parameters. + * @param string $prefix The prefix to apply (e.g., 'RCLONE_', 'RCLONE_CONFIG_MYREMOTE_'). * - * @return array The processed array with prefixed keys and string-cast values. + * @return array The processed array with prefixed keys and string-cast values. */ public static function prefix_flags(array $arr, string $prefix = 'RCLONE_'): array { @@ -371,9 +376,9 @@ public static function prefix_flags(array $arr, string $prefix = 'RCLONE_'): arr /** * Consolidates all environment variables for the rclone process. * - * @param array $additional_operation_flags Flags specific to the current rclone operation. + * @param array $additional_operation_flags Flags specific to the current rclone operation. * - * @return array An array of environment variables to be passed to Symfony Process. + * @return array An array of environment variables to be passed to Symfony Process. */ private function allEnvs(array $additional_operation_flags = []): array { @@ -401,11 +406,11 @@ public static function obscure(string $secret): string /** * Centralized method to prepare and execute an rclone command. * - * @param string $command The rclone command (e.g., 'lsjson', 'copy'). - * @param array $args Arguments for the command. - * @param array $operation_flags Additional operation flags. - * @param callable|null $onProgress Optional progress callback. - * @param int|null $timeout Optional per-operation timeout in seconds. + * @param string $command The rclone command (e.g., 'lsjson', 'copy'). + * @param array $args Arguments for the command. + * @param array $operation_flags Additional operation flags. + * @param callable|null $onProgress Optional progress callback. + * @param int|null $timeout Optional per-operation timeout in seconds. * * @return Process The completed process instance. */ @@ -460,10 +465,10 @@ private function _run(string $command, array $args = [], array $operation_flags /** * Executes a simple rclone command that returns a string output. * - * @param string $command The rclone command (e.g., 'lsjson'). - * @param array $args Arguments for the command. - * @param array $operation_flags Additional operation flags. - * @param callable|null $onProgress Optional progress callback. + * @param string $command The rclone command (e.g., 'lsjson'). + * @param array $args Arguments for the command. + * @param array $operation_flags Additional operation flags. + * @param callable|null $onProgress Optional progress callback. * * @return string The trimmed standard output. */ @@ -477,10 +482,10 @@ private function simpleRun(string $command, array $args = [], array $operation_f /** * Executes an rclone command that performs a transfer and returns statistics. * - * @param string $command The rclone command (e.g., 'copy', 'sync'). - * @param array $args Arguments for the command (source, destination). - * @param array $operation_flags Additional operation flags. - * @param callable|null $onProgress Optional progress callback. + * @param string $command The rclone command (e.g., 'copy', 'sync'). + * @param array $args Arguments for the command (source, destination). + * @param array $operation_flags Additional operation flags. + * @param callable|null $onProgress Optional progress callback. * * @return object An object containing the success status and transfer statistics. */ @@ -503,6 +508,7 @@ private function runAndGetStats(string $command, array $args = [], array $operat $stats = StatsParser::parse($stderr); if (empty(trim($stderr)) && in_array($command, ['moveto', 'copyto'])) { + /** @var stdClass $stats */ $stats->files = 1; } @@ -516,10 +522,10 @@ private function runAndGetStats(string $command, array $args = [], array $operat /** * Executes an rclone command targeting a single provider path. * - * @param string $command The rclone command. - * @param string|null $path The path on the left-side provider. - * @param array $flags Additional flags for the operation. - * @param callable|null $onProgress Optional progress callback. + * @param string $command The rclone command. + * @param string|null $path The path on the left-side provider. + * @param array $flags Additional flags for the operation. + * @param callable|null $onProgress Optional progress callback. * * @return string The output of the command. */ @@ -533,11 +539,11 @@ private function directRun(string $command, $path = null, array $flags = [], ?ca /** * Executes an rclone command involving two provider paths (source and destination). * - * @param string $command The rclone command. - * @param string|null $left_path Path on the left-side provider. - * @param string|null $right_path Path on the right-side provider. - * @param array $flags Additional flags for the operation. - * @param callable|null $onProgress Optional progress callback. + * @param string $command The rclone command. + * @param string|null $left_path Path on the left-side provider. + * @param string|null $right_path Path on the right-side provider. + * @param array $flags Additional flags for the operation. + * @param callable|null $onProgress Optional progress callback. * * @return string The output of the command. */ @@ -617,10 +623,10 @@ public function getProgress(): object /** * Lists objects at the source path. (rclone lsjson) * - * @param string $path Path to list. - * @param array $flags Additional flags. + * @param string $path Path to list. + * @param array $flags Additional flags. * - * @return array Array of objects, each representing a file or directory. + * @return array Array of objects, each representing a file or directory. * @throws JsonException If JSON decoding fails. */ public function ls(string $path, array $flags = []): array @@ -713,9 +719,9 @@ public function exists(string $path, string $type): object * * @see https://rclone.org/commands/rclone_touch/ * - * @param string $path Path to touch. - * @param array $flags Additional flags. - * @param callable|null $onProgress Optional progress callback. + * @param string $path Path to touch. + * @param array $flags Additional flags. + * @param callable|null $onProgress Optional progress callback. * * @return bool True on success. */ @@ -731,9 +737,9 @@ public function touch(string $path, array $flags = [], ?callable $onProgress = n * * @see https://rclone.org/commands/rclone_mkdir/ * - * @param string $path Path to create. - * @param array $flags Additional flags. - * @param callable|null $onProgress Optional progress callback. + * @param string $path Path to create. + * @param array $flags Additional flags. + * @param callable|null $onProgress Optional progress callback. * * @return bool True on success. */ @@ -749,9 +755,9 @@ public function mkdir(string $path, array $flags = [], ?callable $onProgress = n * * @see https://rclone.org/commands/rclone_rmdir/ * - * @param string $path Path to remove. - * @param array $flags Additional flags. - * @param callable|null $onProgress Optional progress callback. + * @param string $path Path to remove. + * @param array $flags Additional flags. + * @param callable|null $onProgress Optional progress callback. * * @return bool True on success. */ @@ -767,9 +773,9 @@ public function rmdir(string $path, array $flags = [], ?callable $onProgress = n * * @see https://rclone.org/commands/rclone_rmdirs/ * - * @param string $path Root path to search for empty directories. - * @param array $flags Additional flags. - * @param callable|null $onProgress Optional progress callback. + * @param string $path Root path to search for empty directories. + * @param array $flags Additional flags. + * @param callable|null $onProgress Optional progress callback. * * @return bool True on success. */ @@ -785,9 +791,9 @@ public function rmdirs(string $path, array $flags = [], ?callable $onProgress = * * @see https://rclone.org/commands/rclone_purge/ * - * @param string $path Path to purge. - * @param array $flags Additional flags. - * @param callable|null $onProgress Optional progress callback. + * @param string $path Path to purge. + * @param array $flags Additional flags. + * @param callable|null $onProgress Optional progress callback. * * @return object Object with 'success' status and 'stats'. */ @@ -801,9 +807,9 @@ public function purge(string $path, array $flags = [], ?callable $onProgress = n * * @see https://rclone.org/commands/rclone_delete/ * - * @param string|null $path Path containing files to delete. - * @param array $flags Additional flags (e.g. --include, --exclude). - * @param callable|null $onProgress Optional progress callback. + * @param string|null $path Path containing files to delete. + * @param array $flags Additional flags (e.g. --include, --exclude). + * @param callable|null $onProgress Optional progress callback. * * @return object Object with 'success' status and 'stats'. */ @@ -817,9 +823,9 @@ public function delete(?string $path = null, array $flags = [], ?callable $onPro * * @see https://rclone.org/commands/rclone_deletefile/ * - * @param string $path Path to the file to delete. - * @param array $flags Additional flags. - * @param callable|null $onProgress Optional progress callback. + * @param string $path Path to the file to delete. + * @param array $flags Additional flags. + * @param callable|null $onProgress Optional progress callback. * * @return object Object with 'success' status and 'stats'. */ @@ -831,9 +837,9 @@ public function deletefile(string $path, array $flags = [], ?callable $onProgres /** * Prints the total size and number of objects in remote:path. (rclone size) * - * @param string|null $path Path to get size of. - * @param array $flags Additional flags. - * @param callable|null $onProgress Optional progress callback. + * @param string|null $path Path to get size of. + * @param array $flags Additional flags. + * @param callable|null $onProgress Optional progress callback. * * @return object Object with 'count' and 'bytes' properties. * @throws JsonException If JSON decoding fails. @@ -851,9 +857,9 @@ public function size(?string $path = null, array $flags = [], ?callable $onProgr * * @see https://rclone.org/commands/rclone_cat/ * - * @param string $path Path to the file. - * @param array $flags Additional flags. - * @param callable|null $onProgress Optional progress callback. + * @param string $path Path to the file. + * @param array $flags Additional flags. + * @param callable|null $onProgress Optional progress callback. * * @return string The file content. */ @@ -867,10 +873,10 @@ public function cat(string $path, array $flags = [], ?callable $onProgress = nul * * @see https://rclone.org/commands/rclone_rcat/ * - * @param string $path Destination path on remote. - * @param string $input Content to send. - * @param array $flags Additional flags. - * @param callable|null $onProgress Optional progress callback. + * @param string $path Destination path on remote. + * @param string $input Content to send. + * @param array $flags Additional flags. + * @param callable|null $onProgress Optional progress callback. * * @return object Object with 'success' status and 'stats'. */ @@ -884,10 +890,10 @@ public function rcat(string $path, string $input, array $flags = [], ?callable $ /** * Uploads a single local file to a remote path using the 'moveto' command for efficiency. * - * @param string $local_path Path to the local file. - * @param string $remote_path Destination path on the remote. - * @param array $flags Additional flags. - * @param callable|null $onProgress Optional progress callback. + * @param string $local_path Path to the local file. + * @param string $remote_path Destination path on the remote. + * @param array $flags Additional flags. + * @param callable|null $onProgress Optional progress callback. * * @return object Object with 'success' status and 'stats'. */ @@ -901,10 +907,10 @@ public function upload_file(string $local_path, string $remote_path, array $flag /** * Downloads a file from a remote path to local storage. * - * @param string $remote_path The path of the file on the remote server. - * @param ?string $local_destination_path The local path where the file should be saved. - * @param array $flags Additional flags for the download operation. - * @param ?callable $onProgress A callback function to track download progress. + * @param string $remote_path The path of the file on the remote server. + * @param ?string $local_destination_path The local path where the file should be saved. + * @param array $flags Additional flags for the download operation. + * @param ?callable $onProgress A callback function to track download progress. * * @return object The result object from the copy operation, with an added `local_path` property on success. */ @@ -950,10 +956,10 @@ public function download_to_local(string $remote_path, ?string $local_destinatio * * @see https://rclone.org/commands/rclone_copy/ * - * @param string $source_path Source path (file or directory). - * @param string $dest_DIR_path Destination directory path. - * @param array $flags Additional flags. - * @param callable|null $onProgress Optional progress callback. + * @param string $source_path Source path (file or directory). + * @param string $dest_DIR_path Destination directory path. + * @param array $flags Additional flags. + * @param callable|null $onProgress Optional progress callback. * * @return object Object with 'success' status and 'stats'. */ @@ -967,10 +973,10 @@ public function copy(string $source_path, string $dest_DIR_path, array $flags = * * @see https://rclone.org/commands/rclone_copyto/ * - * @param string $source_path Source file or directory path. - * @param string $dest_path Destination file or directory path. - * @param array $flags Additional flags. - * @param callable|null $onProgress Optional progress callback. + * @param string $source_path Source file or directory path. + * @param string $dest_path Destination file or directory path. + * @param array $flags Additional flags. + * @param callable|null $onProgress Optional progress callback. * * @return object Object with 'success' status and 'stats'. */ @@ -984,10 +990,10 @@ public function copyto(string $source_path, string $dest_path, array $flags = [] * * @see https://rclone.org/commands/rclone_move/ * - * @param string $source_path Source path (file or directory). - * @param string $dest_DIR_path Destination directory path. - * @param array $flags Additional flags. - * @param callable|null $onProgress Optional progress callback. + * @param string $source_path Source path (file or directory). + * @param string $dest_DIR_path Destination directory path. + * @param array $flags Additional flags. + * @param callable|null $onProgress Optional progress callback. * * @return object Object with 'success' status and 'stats'. */ @@ -1001,10 +1007,10 @@ public function move(string $source_path, string $dest_DIR_path, array $flags = * * @see https://rclone.org/commands/rclone_moveto/ * - * @param string $source_path Source file or directory path. - * @param string $dest_path Destination file or directory path. - * @param array $flags Additional flags. - * @param callable|null $onProgress Optional progress callback. + * @param string $source_path Source file or directory path. + * @param string $dest_path Destination file or directory path. + * @param array $flags Additional flags. + * @param callable|null $onProgress Optional progress callback. * * @return object Object with 'success' status and 'stats'. */ @@ -1018,10 +1024,10 @@ public function moveto(string $source_path, string $dest_path, array $flags = [] * * @see https://rclone.org/commands/rclone_sync/ * - * @param string $source_path Source directory path. - * @param string $dest_path Destination directory path. - * @param array $flags Additional flags. - * @param callable|null $onProgress Optional progress callback. + * @param string $source_path Source directory path. + * @param string $dest_path Destination directory path. + * @param array $flags Additional flags. + * @param callable|null $onProgress Optional progress callback. * * @return object Object with 'success' status and 'stats'. */ @@ -1035,10 +1041,10 @@ public function sync(string $source_path, string $dest_path, array $flags = [], * * @see https://rclone.org/commands/rclone_check/ * - * @param string $source_path Source directory path. - * @param string $dest_path Destination directory path. - * @param array $flags Additional flags. - * @param callable|null $onProgress Optional progress callback. + * @param string $source_path Source directory path. + * @param string $dest_path Destination directory path. + * @param array $flags Additional flags. + * @param callable|null $onProgress Optional progress callback. * * @return bool True if check succeeds. */ @@ -1054,8 +1060,8 @@ public function check(string $source_path, string $dest_path, array $flags = [], * * @see https://rclone.org/commands/rclone_about/ * - * @param string|null $path Path on the provider. - * @param array $flags Additional flags for the operation. + * @param string|null $path Path on the provider. + * @param array $flags Additional flags for the operation. * * @return object An object with quota details. * @throws JsonException @@ -1073,8 +1079,8 @@ public function about(?string $path = null, array $flags = []): object * * @see https://rclone.org/commands/rclone_tree/ * - * @param string|null $path The root path to list from. - * @param array $flags Additional rclone flags. + * @param string|null $path The root path to list from. + * @param array $flags Additional rclone flags. * * @return string The tree structure as a string. */ @@ -1088,9 +1094,9 @@ public function tree(?string $path = null, array $flags = []): string * * @see https://rclone.org/commands/rclone_dedupe/ * - * @param string $path The path to check for duplicates. - * @param string $mode Deduplication strategy. - * @param array $flags Additional flags. + * @param string $path The path to check for duplicates. + * @param string $mode Deduplication strategy. + * @param array $flags Additional flags. * * @return object Object with 'success' status and 'stats' from the operation. */ @@ -1106,8 +1112,8 @@ public function dedupe(string $path, string $mode = 'interactive', array $flags * * @see https://rclone.org/commands/rclone_cleanup/ * - * @param string|null $path The path to clean up. - * @param array $flags Additional flags. + * @param string|null $path The path to clean up. + * @param array $flags Additional flags. * * @return object Object with 'success' status and 'stats'. */ @@ -1121,10 +1127,10 @@ public function cleanup(?string $path = null, array $flags = []): object * * @see https://rclone.org/commands/rclone_backend/ * - * @param string $command The backend command to run. - * @param string|null $path The remote path for the command. - * @param array $options Associative array of options. - * @param array $arguments Positional arguments for the command. + * @param string $command The backend command to run. + * @param string|null $path The remote path for the command. + * @param array $options Associative array of options. + * @param array $arguments Positional arguments for the command. * * @return string The raw output from the command. */ @@ -1157,9 +1163,9 @@ public function backend(string $command, ?string $path = null, array $options = * * @see https://rclone.org/commands/rclone_listremotes/ * - * @param array $flags Additional flags. + * @param array $flags Additional flags. * - * @return array List of remote names (without the trailing colon). + * @return array List of remote names (without the trailing colon). */ public static function listRemotes(array $flags = []): array { @@ -1222,10 +1228,10 @@ public static function configDump(): object * * @see https://rclone.org/commands/rclone_bisync/ * - * @param string $path1 First path (source or destination). - * @param string $path2 Second path (source or destination). - * @param array $flags Additional flags (e.g., 'resync' => true for initial sync). - * @param callable|null $onProgress Optional progress callback. + * @param string $path1 First path (source or destination). + * @param string $path2 Second path (source or destination). + * @param array $flags Additional flags (e.g., 'resync' => true for initial sync). + * @param callable|null $onProgress Optional progress callback. * * @return object Object with 'success' status and 'stats'. */ @@ -1244,11 +1250,11 @@ public function bisync(string $path1, string $path2, array $flags = [], ?callabl * * @see https://rclone.org/commands/rclone_hashsum/ * - * @param string $hashAlgorithm The hash algorithm to use (e.g., 'md5', 'sha1', 'dropbox'). - * @param string|null $path Path to checksum. - * @param array $flags Additional flags. + * @param string $hashAlgorithm The hash algorithm to use (e.g., 'md5', 'sha1', 'dropbox'). + * @param string|null $path Path to checksum. + * @param array $flags Additional flags. * - * @return array Associative array of [path => hash]. + * @return array Associative array of [path => hash]. */ public function hashsum(string $hashAlgorithm, ?string $path = null, array $flags = []): array { @@ -1278,10 +1284,10 @@ public function hashsum(string $hashAlgorithm, ?string $path = null, array $flag * * @see https://rclone.org/commands/rclone_md5sum/ * - * @param string|null $path Path to checksum. - * @param array $flags Additional flags. + * @param string|null $path Path to checksum. + * @param array $flags Additional flags. * - * @return array Associative array of [path => md5hash]. + * @return array Associative array of [path => md5hash]. */ public function md5sum(?string $path = null, array $flags = []): array { @@ -1293,10 +1299,10 @@ public function md5sum(?string $path = null, array $flags = []): array * * @see https://rclone.org/commands/rclone_sha1sum/ * - * @param string|null $path Path to checksum. - * @param array $flags Additional flags. + * @param string|null $path Path to checksum. + * @param array $flags Additional flags. * - * @return array Associative array of [path => sha1hash]. + * @return array Associative array of [path => sha1hash]. */ public function sha1sum(?string $path = null, array $flags = []): array { diff --git a/src/RetryHandler.php b/src/RetryHandler.php index 43f35af4..5fe0d7c1 100644 --- a/src/RetryHandler.php +++ b/src/RetryHandler.php @@ -23,10 +23,10 @@ class RetryHandler private bool $enabled = true; - /** @var callable|null Custom retry condition */ + /** @var (callable(Exception): bool)|null Custom retry condition */ private $retryCondition = null; - /** @var callable|null Callback called before each retry */ + /** @var (callable(int, Exception, int): void)|null Callback called before each retry */ private $onRetry = null; /** @@ -90,7 +90,7 @@ public function enabled(bool $enabled): self /** * Set a custom condition for determining if an exception should trigger a retry. * - * @param callable $condition Function that receives the exception and returns bool. + * @param callable(Exception): bool $condition Function that receives the exception and returns bool. */ public function retryWhen(callable $condition): self { @@ -102,7 +102,7 @@ public function retryWhen(callable $condition): self /** * Set a callback to be called before each retry attempt. * - * @param callable $callback Function that receives (attempt number, exception, delay). + * @param callable(int, Exception, int): void $callback Function that receives (attempt number, exception, delay). */ public function onRetry(callable $callback): self { @@ -203,6 +203,8 @@ private function calculateDelay(int $attempt): int /** * Get current configuration as array. + * + * @return array */ public function getConfig(): array { diff --git a/src/SecretsRedactor.php b/src/SecretsRedactor.php index ee2479c7..f50ddf55 100644 --- a/src/SecretsRedactor.php +++ b/src/SecretsRedactor.php @@ -65,8 +65,8 @@ public static function isEnabled(): bool /** * Redact sensitive information from a message. * - * @param string $message The message that may contain secrets. - * @param array $knownSecrets Additional secrets to redact (values from provider config). + * @param string $message The message that may contain secrets. + * @param array $knownSecrets Additional secrets to redact (values from provider config). * * @return string The message with secrets replaced by [REDACTED]. */ @@ -90,6 +90,8 @@ public static function redact(string $message, array $knownSecrets = []): string /** * Redact known secret values from the message. + * + * @param array $secrets */ private static function redactKnownSecrets(string $message, array $secrets): string { @@ -141,9 +143,9 @@ private static function redactUrls(string $message): string /** * Extract secrets from provider configuration for targeted redaction. * - * @param array $providerFlags The flags array from a Provider. + * @param array $providerFlags The flags array from a Provider. * - * @return array List of secret values that should be redacted. + * @return array List of secret values that should be redacted. */ public static function extractSecretsFromFlags(array $providerFlags): array { diff --git a/src/StatsParser.php b/src/StatsParser.php index dc72e43a..fdaa7819 100644 --- a/src/StatsParser.php +++ b/src/StatsParser.php @@ -6,6 +6,17 @@ class StatsParser { + /** + * @return object{ + * errors: int, + * checks: int, + * files: int, + * bytes: int, + * elapsed_time: float, + * speed_human: string, + * speed_bytes_per_second: float + * } + */ public static function parse(string $output): object { $stats = [