Skip to content

Commit

Permalink
Cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
freost committed Nov 11, 2024
1 parent b7eb83f commit b42d6da
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/mako/cli/output/components/Countdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ public function draw(int $from = 5): void

$dots = 0;

$fromLength = strlen($from);
$fromLength = strlen((string) $from);

$totalLength = $fromLength + 5;

do {
do {
$numbers = str_pad($from, $fromLength, '0', STR_PAD_LEFT);
$numbers = str_pad((string) $from, $fromLength, '0', STR_PAD_LEFT);

$this->output->write("\r" . str_pad($numbers . ' ' . str_repeat('.', $dots) . ' ', $totalLength, ' '));

Expand Down
4 changes: 2 additions & 2 deletions src/mako/cli/output/components/OrderedList.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected function calculateWidth(array $items, string $marker): array
}
}

$number = strlen($count);
$number = strlen((string) $count);

$marker = strlen(sprintf($this->formatter === null ? $marker : $this->formatter->stripTags($marker), '')) + $number;

Expand All @@ -66,7 +66,7 @@ protected function calculateWidth(array $items, string $marker): array
*/
protected function buildListItem(string $item, string $marker, int $width, int $number, int $nestingLevel, int $parentWidth): string
{
$marker = str_repeat(' ', $width - strlen($number)) . sprintf($marker, $number);
$marker = str_repeat(' ', $width - strlen((string) $number)) . sprintf($marker, $number);

return str_repeat($this->padding, $nestingLevel) . str_repeat(' ', $parentWidth) . "{$marker} {$item}" . PHP_EOL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function buildProgressBar(float $percent): string

$progress = number_format($percent * 100, 2, '.');

return str_pad($this->progress, strlen($this->itemCount), '0', STR_PAD_LEFT)
return str_pad((string) $this->progress, strlen((string) $this->itemCount), '0', STR_PAD_LEFT)
. "/{$this->itemCount} "
. str_repeat($this->progressBar->getFilled(), $fill)
. str_repeat($this->progressBar->getEmpty(), ($this->width - $fill))
Expand Down
2 changes: 1 addition & 1 deletion src/mako/error/handlers/web/DevelopmentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ protected function getExceptionAsXml(Throwable $exception): string

$xml->addChild('file', $exception->getFile());

$xml->addChild('line', $exception->getLine());
$xml->addChild('line', (string) $exception->getLine());

$xml->addChild('exception_id', $this->exceptionId);

Expand Down
6 changes: 3 additions & 3 deletions src/mako/file/FileSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,23 +256,23 @@ public function get(string $path): false|string
/**
* Writes the supplied data to a file.
*/
public static function put(string $path, mixed $data, bool $lock = false): false|string
public static function put(string $path, mixed $data, bool $lock = false): false|int
{
return file_put_contents($path, $data, $lock ? LOCK_EX : 0);
}

/**
* Prepends the supplied data to a file.
*/
public static function prepend(string $path, mixed $data, bool $lock = false): false|string
public static function prepend(string $path, mixed $data, bool $lock = false): false|int
{
return file_put_contents($path, $data . file_get_contents($path), $lock ? LOCK_EX : 0);
}

/**
* Appends the supplied data to a file.
*/
public static function append(string $path, mixed $data, bool $lock = false): false|string
public static function append(string $path, mixed $data, bool $lock = false): false|int
{
return file_put_contents($path, $data, $lock ? FILE_APPEND | LOCK_EX : FILE_APPEND);
}
Expand Down
4 changes: 2 additions & 2 deletions src/mako/http/response/senders/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public function send(Request $request, Response $response): void

$range = ['start' => 0, 'end' => $this->fileSize - 1];

$response->headers->add('Content-Length', $this->fileSize);
$response->headers->add('Content-Length', (string) $this->fileSize);
}
else {
// Valid range so we'll need to tell the client which range we're sending
Expand All @@ -266,7 +266,7 @@ public function send(Request $request, Response $response): void

$response->headers->add('Content-Range', sprintf('bytes %s-%s/%s', $range['start'], $range['end'], $this->fileSize));

$response->headers->add('Content-Length', $range['end'] - $range['start'] + 1);
$response->headers->add('Content-Length', (string) ($range['end'] - $range['start'] + 1));
}

// Send headers and the requested byte range
Expand Down
11 changes: 3 additions & 8 deletions src/mako/redis/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use function explode;
use function implode;
use function in_array;
use function is_string;
use function strlen;
use function substr;
use function trim;
Expand Down Expand Up @@ -192,9 +191,9 @@ public function getAttributes(): array
*/
protected function createClusterClient(string $server): Redis
{
[$server, $port] = explode(':', $server, 2);
[$host, $port] = explode(':', $server, 2);

return new static(new Connection($server, $port, $this->connection->getOptions()), [
return new static(new Connection($host, (int) $port, $this->connection->getOptions()), [
'resp' => $this->resp,
'username' => $this->username,
'password' => $this->password,
Expand Down Expand Up @@ -641,10 +640,6 @@ protected function buildAndSendCommandAndReturnResponse(array $command, array $a
*/
public function executeCommand(string $command, mixed ...$arguments): mixed
{
if (is_string($command)) {
$command = explode(' ', $command);
}

return $this->buildAndSendCommandAndReturnResponse($command, $arguments);
return $this->buildAndSendCommandAndReturnResponse(explode(' ', $command), $arguments);
}
}
2 changes: 1 addition & 1 deletion src/mako/utility/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public static function mask(string $string, int $visible = 3, string $mask = '*'
*/
public static function increment(string $string, int $start = 1, string $separator = '_'): string
{
preg_match('/(.+)' . preg_quote($separator) . '([0-9]+)$/', $string, $matches);
preg_match('/(.+)' . preg_quote($separator, delimiter: '/') . '([0-9]+)$/', $string, $matches);

return isset($matches[2]) ? "{$matches[1]}{$separator}" . ((int) $matches[2] + 1) : "{$string}{$separator}{$start}";
}
Expand Down
2 changes: 1 addition & 1 deletion src/mako/utility/UUID.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public static function v4Sequential(): string
{
[$usec, $sec] = explode(' ', microtime());

$random = hex2bin(dechex($sec . substr($usec, 2, 5)) . bin2hex(random_bytes(10)));
$random = hex2bin(dechex((int) ($sec . substr($usec, 2, 5))) . bin2hex(random_bytes(10)));

$random[6] = chr(ord($random[6]) & 0x0f | 0x40);

Expand Down

0 comments on commit b42d6da

Please sign in to comment.