Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 5
level: 6
paths:
- src
excludePaths:
Expand Down
14 changes: 14 additions & 0 deletions src/CommandBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

class CommandBuilder
{
/**
* @param array<string, mixed> $arr
* @return array<string, string>
*/
public static function prefixFlags(array $arr, string $prefix = 'RCLONE_'): array
{
$newArr = [];
Expand All @@ -31,6 +35,12 @@ public static function prefixFlags(array $arr, string $prefix = 'RCLONE_'): arra
return $newArr;
}

/**
* @param array<string, mixed> $globalFlags
* @param array<string, mixed> $globalEnvs
* @param array<string, mixed> $operationFlags
* @return array<string, string>
*/
public static function buildEnvironment(
Provider $leftSide,
Provider $rightSide,
Expand All @@ -51,6 +61,10 @@ public static function buildEnvironment(
return $envVars;
}

/**
* @param array<int, string> $args
* @return array<int, string>
*/
public static function buildCommandArgs(string $binary, string $command, array $args = []): array
{
return array_merge([$binary, $command], $args);
Expand Down
6 changes: 3 additions & 3 deletions src/Exception/RcloneException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
*/
class RcloneException extends RuntimeException
{
/** @var array Additional context about the error */
/** @var array<string, mixed> 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<string, mixed> $context Contextual information (command, provider, path, etc.)
*/
public function setContext(array $context): self
{
Expand All @@ -31,7 +31,7 @@ public function setContext(array $context): self
/**
* Get the exception context.
*
* @return array The context array.
* @return array<string, mixed> The context array.
*/
public function getContext(): array
{
Expand Down
14 changes: 7 additions & 7 deletions src/FilterBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
*/
class FilterBuilder
{
/** @var array Include patterns */
/** @var array<int, string> Include patterns */
private array $includes = [];

/** @var array Exclude patterns */
/** @var array<int, string> Exclude patterns */
private array $excludes = [];

/** @var int|null Minimum file size in bytes */
Expand Down Expand Up @@ -56,7 +56,7 @@ public function include(string $pattern): self
/**
* Add multiple include patterns.
*
* @param array $patterns Array of glob patterns
* @param array<int, string> $patterns Array of glob patterns
*/
public function includeMany(array $patterns): self
{
Expand All @@ -82,7 +82,7 @@ public function exclude(string $pattern): self
/**
* Add multiple exclude patterns.
*
* @param array $patterns Array of glob patterns
* @param array<int, string> $patterns Array of glob patterns
*/
public function excludeMany(array $patterns): self
{
Expand All @@ -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<int, string> $extensions Extension(s) without dot (e.g., "jpg", ["jpg", "png"])
*/
public function extensions(string|array $extensions): self
{
Expand Down Expand Up @@ -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<string, mixed> Flags to be merged with operation flags
*/
public function toFlags(): array
{
Expand Down Expand Up @@ -240,7 +240,7 @@ public function toFlags(): array
/**
* Convert to command line arguments.
*
* @return array Command line arguments
* @return array<int, string> Command line arguments
*/
public function toArgs(): array
{
Expand Down
35 changes: 29 additions & 6 deletions src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Logger

private static bool $debugMode = false;

/** @var array<int, array{time: float, level: string, message: string, context: array<string, mixed>}> */
private static array $logs = [];

private static int $maxLogs = 1000;
Expand Down Expand Up @@ -66,6 +67,8 @@ public static function isDebugMode(): bool

/**
* Log a debug message (only if debug mode is enabled).
*
* @param array<string, mixed> $context
*/
public static function debug(string $message, array $context = []): void
{
Expand All @@ -76,6 +79,8 @@ public static function debug(string $message, array $context = []): void

/**
* Log an info message.
*
* @param array<string, mixed> $context
*/
public static function info(string $message, array $context = []): void
{
Expand All @@ -84,6 +89,8 @@ public static function info(string $message, array $context = []): void

/**
* Log a warning message.
*
* @param array<string, mixed> $context
*/
public static function warning(string $message, array $context = []): void
{
Expand All @@ -92,6 +99,8 @@ public static function warning(string $message, array $context = []): void

/**
* Log an error message.
*
* @param array<string, mixed> $context
*/
public static function error(string $message, array $context = []): void
{
Expand All @@ -100,6 +109,8 @@ public static function error(string $message, array $context = []): void

/**
* Log a message at the specified level.
*
* @param array<string, mixed> $context
*/
public static function log(string $level, string $message, array $context = []): void
{
Expand Down Expand Up @@ -129,6 +140,8 @@ public static function log(string $level, string $message, array $context = []):

/**
* Get all stored logs.
*
* @return array<int, array{time: float, level: string, message: string, context: array<string, mixed>}>
*/
public static function getLogs(): array
{
Expand All @@ -145,6 +158,8 @@ public static function clearLogs(): void

/**
* Get logs filtered by level.
*
* @return array<int, array{time: float, level: string, message: string, context: array<string, mixed>}>
*/
public static function getLogsByLevel(string $level): array
{
Expand All @@ -153,6 +168,8 @@ public static function getLogsByLevel(string $level): array

/**
* Log command execution (debug mode only).
*
* @param array<string, string> $envs
*/
public static function logCommand(string $command, array $envs = []): void
{
Expand Down Expand Up @@ -180,27 +197,33 @@ public static function logResult(bool $success, float $duration, ?string $output

/**
* Redact sensitive information from context array.
*
* @param array<string, mixed> $context
* @return array<string, mixed>
*/
private static function redactContext(array $context): array
{
$sensitiveKeys = ['password', 'secret', 'token', 'key', 'credential', 'auth'];
$result = [];

$redact = function ($value, $key) use (&$redact, $sensitiveKeys) {
foreach ($context as $key => $value) {
if (is_array($value)) {
return array_map($redact, $value, array_keys($value));
$result[$key] = self::redactContext($value);
continue;
}

if (is_string($key)) {
foreach ($sensitiveKeys as $sensitiveKey) {
if (stripos($key, $sensitiveKey) !== false) {
return SecretsRedactor::REDACTED;
$result[$key] = SecretsRedactor::REDACTED;
continue 2;
}
}
}

return $value;
};
$result[$key] = $value;
}

return array_map($redact, $context, array_keys($context));
return $result;
}
}
19 changes: 13 additions & 6 deletions src/ProcessManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ class ProcessManager

private static string $input = '';

/** @var array Secrets to redact from error messages */
/** @var array<int, string> Secrets to redact from error messages */
private array $secrets = [];

/** @var array Last executed command (for debugging) */
/** @var array<int, string> Last executed command (for debugging) */
private array $lastCommand = [];

/** @var array Last environment variables (for debugging) */
/** @var array<string, string> Last environment variables (for debugging) */
private array $lastEnvs = [];

public static function getTimeout(): int
Expand Down Expand Up @@ -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<int, string> $secrets Array of secret values to redact.
*/
public function setSecrets(array $secrets): self
{
Expand All @@ -120,7 +120,7 @@ public function setSecrets(array $secrets): self
/**
* Get the last executed command (for debugging).
*
* @return array The command array.
* @return array<int, string> The command array.
*/
public function getLastCommand(): array
{
Expand All @@ -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<string, string> The environment variables with secrets redacted.
*/
public function getLastEnvs(): array
{
Expand All @@ -153,6 +153,9 @@ public function getLastEnvs(): array

/**
* Redact sensitive values from environment variables.
*
* @param array<string, string> $envs
* @return array<string, string>
*/
private function redactEnvValues(array $envs): array
{
Expand All @@ -174,6 +177,10 @@ private function redactEnvValues(array $envs): array
return $redacted;
}

/**
* @param array<int, string> $command
* @param array<string, string> $envs
*/
public function run(array $command, array $envs = [], ?callable $onProgress = null, ?int $timeout = null): Process
{
$this->lastCommand = $command;
Expand Down
3 changes: 3 additions & 0 deletions src/ProgressParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ProgressParser
/** @var string Buffer for incomplete lines */
private string $lineBuffer = '';

/** @var array<string, mixed> Default progress values */
private static array $defaultProgress = [
'raw' => '',
'dataSent' => '0 B',
Expand Down Expand Up @@ -135,6 +136,8 @@ public function getProgress(): object

/**
* Get progress as array for easier manipulation.
*
* @return array<string, mixed>
*/
public function getProgressArray(): array
{
Expand Down
Loading
Loading