Skip to content

Commit

Permalink
PascalCase constants
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Feb 28, 2023
1 parent 5c713aa commit 217c019
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/Deployment/CliRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ private function loadConfig(): ?array

XX,
[
'config' => [CommandLine::REALPATH => true],
'config' => [CommandLine::RealPath => true],
],
);

Expand Down
38 changes: 19 additions & 19 deletions src/Deployment/CommandLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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;
Expand All @@ -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];
}
}
Expand All @@ -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.");
Expand Down
10 changes: 5 additions & 5 deletions src/Deployment/Deployer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
class Deployer
{
private const TEMPORARY_SUFFIX = '.deploytmp';
private const TemporarySuffix = '.deploytmp';

public string $deploymentFile = '.htdeployment';

Expand Down Expand Up @@ -266,15 +266,15 @@ 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)';
}

$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');
},
Expand All @@ -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]);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Deployment/FtpServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions src/Deployment/RetryServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand All @@ -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;
Expand Down

0 comments on commit 217c019

Please sign in to comment.