diff --git a/src/Deployment/CliRunner.php b/src/Deployment/CliRunner.php index 84ebe61..7faf684 100644 --- a/src/Deployment/CliRunner.php +++ b/src/Deployment/CliRunner.php @@ -232,7 +232,7 @@ private function loadConfig(): ?array XX, [ - 'config' => [CommandLine::REALPATH => true], + 'config' => [CommandLine::RealPath => true], ], ); diff --git a/src/Deployment/CommandLine.php b/src/Deployment/CommandLine.php index ceefad4..ea5bf37 100644 --- a/src/Deployment/CommandLine.php +++ b/src/Deployment/CommandLine.php @@ -17,11 +17,11 @@ class CommandLine { public const - ARGUMENT = 'argument', - OPTIONAL = 'optional', - REPEATABLE = 'repeatable', - REALPATH = 'realpath', - VALUE = 'default'; + Argument = 'argument', + Optional = 'optional', + Repeatable = 'repeatable', + RealPath = 'realpath', + Value = 'default'; /** @var array[] */ private array $options = []; @@ -49,10 +49,10 @@ public function __construct(string $help, array $defaults = []) $name = end($m[1]); $opts = $this->options[$name] ?? []; $this->options[$name] = $opts + [ - self::ARGUMENT => (bool) end($m[2]), - self::OPTIONAL => isset($line[2]) || (substr(end($m[2]), 0, 1) === '[') || isset($opts[self::VALUE]), - self::REPEATABLE => (bool) end($m[3]), - self::VALUE => $line[2] ?? null, + self::Argument => (bool) end($m[2]), + self::Optional => isset($line[2]) || (substr(end($m[2]), 0, 1) === '[') || isset($opts[self::Value]), + self::Repeatable => (bool) end($m[3]), + self::Value => $line[2] ?? null, ]; if ($name !== $m[1][0]) { $this->aliases[$m[1][0]] = $name; @@ -83,7 +83,7 @@ public function parse(array $args = null): array } $name = current($this->positional); $this->checkArg($this->options[$name], $arg); - if (empty($this->options[$name][self::REPEATABLE])) { + if (empty($this->options[$name][self::Repeatable])) { $params[$name] = $arg; next($this->positional); } else { @@ -103,19 +103,19 @@ public function parse(array $args = null): array $opt = $this->options[$name]; - if ($arg !== true && empty($opt[self::ARGUMENT])) { + if ($arg !== true && empty($opt[self::Argument])) { throw new \Exception("Option $name has not argument."); - } elseif ($arg === true && !empty($opt[self::ARGUMENT])) { + } elseif ($arg === true && !empty($opt[self::Argument])) { if (isset($args[$i]) && $args[$i][0] !== '-') { $arg = $args[$i++]; - } elseif (empty($opt[self::OPTIONAL])) { + } elseif (empty($opt[self::Optional])) { throw new \Exception("Option $name requires argument."); } } $this->checkArg($opt, $arg); - if (empty($opt[self::REPEATABLE])) { + if (empty($opt[self::Repeatable])) { $params[$name] = $arg; } else { $params[$name][] = $arg; @@ -125,14 +125,14 @@ public function parse(array $args = null): array foreach ($this->options as $name => $opt) { if (isset($params[$name])) { continue; - } elseif (isset($opt[self::VALUE])) { - $params[$name] = $opt[self::VALUE]; - } elseif ($name[0] !== '-' && empty($opt[self::OPTIONAL])) { + } elseif (isset($opt[self::Value])) { + $params[$name] = $opt[self::Value]; + } elseif ($name[0] !== '-' && empty($opt[self::Optional])) { throw new \Exception("Missing required argument <$name>."); } else { $params[$name] = null; } - if (!empty($opt[self::REPEATABLE])) { + if (!empty($opt[self::Repeatable])) { $params[$name] = (array) $params[$name]; } } @@ -148,7 +148,7 @@ public function help(): void public function checkArg(array $opt, &$arg): void { - if (!empty($opt[self::REALPATH])) { + if (!empty($opt[self::RealPath])) { $path = realpath($arg); if ($path === false) { throw new \Exception("File path '$arg' not found."); diff --git a/src/Deployment/Deployer.php b/src/Deployment/Deployer.php index ba1aaa9..117c0b3 100644 --- a/src/Deployment/Deployer.php +++ b/src/Deployment/Deployer.php @@ -16,7 +16,7 @@ */ class Deployer { - private const TEMPORARY_SUFFIX = '.deploytmp'; + private const TemporarySuffix = '.deploytmp'; public string $deploymentFile = '.htdeployment'; @@ -266,7 +266,7 @@ private function uploadPaths(array $paths, array &$tempFiles): void continue; } - $tempFiles[$path . self::TEMPORARY_SUFFIX] = true; + $tempFiles[$path . self::TemporarySuffix] = true; $localFile = $this->preprocess($path); if ($localFile !== $this->localDir . $path) { $path .= ' (filters applied)'; @@ -274,7 +274,7 @@ private function uploadPaths(array $paths, array &$tempFiles): void $this->server->writeFile( $localFile, - $remotePath . self::TEMPORARY_SUFFIX, + $remotePath . self::TemporarySuffix, function ($percent) use ($num, $paths, $path) { $this->writeProgress($num + 1, count($paths), $path, $percent, 'green'); }, @@ -294,8 +294,8 @@ private function renamePaths(array $paths, array &$tempFiles): void foreach ($files as $num => $file) { $this->writeProgress($num + 1, count($files), "Renaming $file", null, 'olive'); $remoteFile = $this->remoteDir . $file; - $this->server->renameFile($remoteFile . self::TEMPORARY_SUFFIX, $remoteFile); - unset($tempFiles[$file . self::TEMPORARY_SUFFIX]); + $this->server->renameFile($remoteFile . self::TemporarySuffix, $remoteFile); + unset($tempFiles[$file . self::TemporarySuffix]); } } diff --git a/src/Deployment/FtpServer.php b/src/Deployment/FtpServer.php index e0ee07b..d60aa88 100644 --- a/src/Deployment/FtpServer.php +++ b/src/Deployment/FtpServer.php @@ -16,8 +16,8 @@ */ class FtpServer implements Server { - private const RETRIES = 10; - private const BLOCK_SIZE = 400000; + private const Retries = 10; + private const BlockSize = 400000; public ?int $filePermissions = null; public ?int $dirPermissions = null; @@ -101,7 +101,7 @@ public function writeFile(string $local, string $remote, callable $progress = nu $blocks = 0; do { if ($progress) { - $progress(min($blocks * self::BLOCK_SIZE / $size, 100)); + $progress(min($blocks * self::BlockSize / $size, 100)); } $ret = $blocks === 0 ? Safe::ftp_nb_put($this->connection, $remote, $local, FTP_BINARY) diff --git a/src/Deployment/RetryServer.php b/src/Deployment/RetryServer.php index f11029b..a90c5d8 100644 --- a/src/Deployment/RetryServer.php +++ b/src/Deployment/RetryServer.php @@ -16,8 +16,8 @@ */ class RetryServer implements Server { - private const RETRIES = 20; - private const DELAY = 2; + private const Retries = 20; + private const Delay = 2; private Server $server; private Logger $logger; @@ -115,7 +115,7 @@ private function retry(string $method, array $args) return $this->server->$method(...$args); } catch (ServerException $e) { - if ($counter < self::RETRIES) { + if ($counter < self::Retries) { if ($e->getMessage() !== $lastError) { $lastError = $e->getMessage(); $this->logger->log("Error: $e", 'red'); @@ -128,7 +128,7 @@ private function retry(string $method, array $args) $counter++; $this->logger->progress('retrying ' . str_pad(str_repeat('.', $counter % 40), 40)); - sleep(self::DELAY); + sleep(self::Delay); goto retry; } throw $e;