Skip to content

Commit

Permalink
fix: formatting and coding style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
AxiosLeo committed Apr 1, 2024
1 parent dfa613b commit 4c49b56
Show file tree
Hide file tree
Showing 31 changed files with 119 additions and 108 deletions.
6 changes: 3 additions & 3 deletions .php-cs-fixer.dist.php
Expand Up @@ -63,10 +63,10 @@
// 'use',
// ],
'binary_operator_spaces' => [
'default' => 'align_single_space_by_scope',
'default' => 'align',
'operators' => [
'=>' => 'align_single_space_by_scope',
'=' => 'align_single_space_by_scope',
'=>' => 'align',
'=' => 'align',
],
],
'braces' => [
Expand Down
24 changes: 14 additions & 10 deletions functions.php
Expand Up @@ -3,9 +3,13 @@
declare(strict_types=1);

use axios\tools\HMac;
use axios\tools\Path;
use axios\tools\SM3;
use axios\tools\UUID;
use axios\tools\XMLParser;

if (!function_exists('render_str')) {
function render_str(string $template, array $params, string $left_tag='${', string $right_tag='}'): string
function render_str(string $template, array $params, string $left_tag = '${', string $right_tag = '}'): string
{
foreach ($params as $name => $value) {
$template = str_replace($left_tag . $name . $right_tag, $value, $template);
Expand Down Expand Up @@ -55,7 +59,7 @@ function halt(...$args)
if (!function_exists('sm3')) {
function sm3(string $str, bool $raw_output = false): string
{
$sm3 = new \axios\tools\SM3();
$sm3 = new SM3();
$sm3->encode($str);

return $raw_output ? $sm3->getBinary() : $sm3->getHex();
Expand All @@ -65,7 +69,7 @@ function sm3(string $str, bool $raw_output = false): string
if (!function_exists('sm3_file')) {
function sm3_file(string $filepath, bool $raw_output = false): string
{
$sm3 = new \axios\tools\SM3();
$sm3 = new SM3();
$sm3->encodeFile($filepath);

return $raw_output ? $sm3->getBinary() : $sm3->getHex();
Expand All @@ -75,21 +79,21 @@ function sm3_file(string $filepath, bool $raw_output = false): string
if (!function_exists('xml_encode')) {
function xml_encode(array $data, $root_node = 'data', $root_attr = [], $item_node = 'item', $item_key = 'id', $encoding = 'utf-8'): string
{
return \axios\tools\XMLParser::encode($data, $root_node, $root_attr, $item_node, $item_key, $encoding);
return XMLParser::encode($data, $root_node, $root_attr, $item_node, $item_key, $encoding);
}
}

if (!function_exists('xml_decode')) {
function xml_decode(string $xml_string): array
{
return \axios\tools\XMLParser::decode($xml_string);
return XMLParser::decode($xml_string);
}
}

if (!function_exists('uuid')) {
function uuid(string $salt = ''): string
{
$uuid = new \axios\tools\UUID($salt);
$uuid = new UUID($salt);
$str = $uuid->v2();
unset($uuid);

Expand All @@ -100,7 +104,7 @@ function uuid(string $salt = ''): string
if (!function_exists('path_join')) {
function path_join(string ...$paths): string
{
return \axios\tools\Path::join(...$paths);
return Path::join(...$paths);
}
}

Expand All @@ -127,7 +131,7 @@ function client_ip(int $type = 0, bool $advance = false)
if (false !== $pos) {
unset($arr[$pos]);
}
$ip = trim($arr[0]);
$ip = trim($arr[0]);
} elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (isset($_SERVER['REMOTE_ADDR'])) {
Expand All @@ -137,8 +141,8 @@ function client_ip(int $type = 0, bool $advance = false)
$ip = $_SERVER['REMOTE_ADDR'];
}
// IP address legitimacy verification
$long = sprintf('%u', ip2long((string) $ip));
$ip = $long ? [$ip, $long] : ['0.0.0.0', 0];
$long = sprintf('%u', ip2long((string) $ip));
$ip = $long ? [$ip, $long] : ['0.0.0.0', 0];

return $ip[$type];
}
Expand Down
18 changes: 9 additions & 9 deletions src/ArrayMap.php
Expand Up @@ -70,7 +70,7 @@ public function set($key, $value = null): self
}
} else {
$recurArrayChange = function ($array, $keyArr, $value) use (&$recurArrayChange) {
$key = array_shift($keyArr);
$key = array_shift($keyArr);
if (null === $key) {
return $value;
}
Expand All @@ -93,8 +93,8 @@ public function set($key, $value = null): self
return $array;
};

$keyArray = explode($this->separator, trim($key, ' .'));
$this->array = $recurArrayChange($this->array, $keyArray, $value);
$keyArray = explode($this->separator, trim($key, ' .'));
$this->array = $recurArrayChange($this->array, $keyArray, $value);
}

return $this;
Expand Down Expand Up @@ -166,7 +166,7 @@ public function getAllToString(array $map = [])
return $array;
};

$arr = $this->get();
$arr = $this->get();
$recurse($arr);

return $arr;
Expand Down Expand Up @@ -200,16 +200,16 @@ public function delete($key): self
*
* @return $this
*/
public function sort(string $key = null, array $sortRule = []): mixed
public function sort(?string $key = null, array $sortRule = []): mixed
{
$data = $this->get($key);
$data = $this->get($key);
if (!\is_array($data)) {
throw new \InvalidArgumentException('Invalid data. Only supported array.');
}
if (0 === \count($sortRule)) {
throw new \InvalidArgumentException('Invalid sort rule.');
}
$params = [];
$params = [];
foreach ($sortRule as $key => $value) {
$params[] = $key;

Expand All @@ -227,14 +227,14 @@ public function sort(string $key = null, array $sortRule = []): mixed

foreach ($params as $key => $field) {
if (\is_string($field)) {
$item = [];
$item = [];
foreach ($data as $k => $value) {
$item[$k] = $value[$field];
}
$params[$key] = $item;
}
}
$params[] =&$data;
$params[] = &$data;
\call_user_func_array('array_multisort', $params);

return array_pop($params);
Expand Down
4 changes: 2 additions & 2 deletions src/BHDConverter.php
Expand Up @@ -13,8 +13,8 @@ public function __construct(
$dict = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', // len:62
$patch = '0',
) {
$this->dict = $dict;
$this->patch = $patch;
$this->dict = $dict;
$this->patch = $patch;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/CDKEYProducer.php
Expand Up @@ -20,12 +20,12 @@ public function __construct(int $ticket_len, int $mixed_str_len, int $offset = 0
if ($ticket_len > 0) {
$this->code_min = (int) $this->converter->anyToDecimal('1' . str_repeat('0', $ticket_len - 1), 62);
}
$this->code_max = (int) $this->converter->anyToDecimal(str_repeat('Z', $ticket_len), 62);
$this->code_max = (int) $this->converter->anyToDecimal(str_repeat('Z', $ticket_len), 62);
if ($mixed_str_len > 0) {
$this->mix_min = (int) $this->converter->anyToDecimal('1' . str_repeat('0', $mixed_str_len - 1), 62);
}
$this->mix_max = (int) $this->converter->anyToDecimal(str_repeat('Z', $mixed_str_len), 62);
$this->offset = $offset;
$this->mix_max = (int) $this->converter->anyToDecimal(str_repeat('Z', $mixed_str_len), 62);
$this->offset = $offset;
}

public function setOffset(int $offset): self
Expand Down
6 changes: 3 additions & 3 deletions src/CRC64.php
Expand Up @@ -8,14 +8,14 @@ class CRC64
{
private static array $crc64tab = [];

private int $value = 0;
private int $value = 0;

public function __construct()
{
if ([] === self::$crc64tab) {
$poly64rev = (0xC96C5795 << 32) | 0xD7870F42;
for ($n = 0; $n < 256; ++$n) {
$crc = $n;
$crc = $n;
for ($k = 0; $k < 8; ++$k) {
if ($crc & true) {
$crc = ($crc >> 1) & ~(0x8 << 60) ^ $poly64rev;
Expand Down Expand Up @@ -53,6 +53,6 @@ public function result(): string

private function count($byte, $crc): int
{
return self::$crc64tab[($crc ^ $byte) & 0xff] ^ (($crc >> 8) & ~(0xff << 56));
return self::$crc64tab[($crc ^ $byte) & 0xFF] ^ (($crc >> 8) & ~(0xFF << 56));
}
}
2 changes: 1 addition & 1 deletion src/Files.php
Expand Up @@ -98,7 +98,7 @@ public static function write(string $filename, string $text, string $mode = 'w',
if (flock($fp, \LOCK_EX)) {
while ($blank > 0) {
fwrite($fp, \PHP_EOL);
$blank = $blank - 1;
--$blank;
}
fwrite($fp, $text . \PHP_EOL);
flock($fp, \LOCK_UN);
Expand Down
6 changes: 3 additions & 3 deletions src/ForkProcess.php
Expand Up @@ -11,7 +11,7 @@ class ForkProcess
use InstanceTrait;

private array $work_queue = [];
private ?int $max_process;
private ?int $max_process;

public function __construct($max_process = 100)
{
Expand Down Expand Up @@ -42,7 +42,7 @@ public function maxProcess($max_process = null): ?int

public function addWork($class, $func, $args = []): self
{
$queue = [
$queue = [
'class' => $class,
'func' => $func,
'args' => $args,
Expand Down Expand Up @@ -70,7 +70,7 @@ private function exec($queue): bool
if (\is_string($class) && class_exists($class)) {
$class = new $class();
}
$fork = $this->fork();
$fork = $this->fork();
if ($fork) {
return true;
}
Expand Down
8 changes: 4 additions & 4 deletions src/HMac.php
Expand Up @@ -22,10 +22,10 @@ public function count(string $algorithm, $data = null, $secret = null, bool $raw
if (\strlen($secret) > $size) {
$secret = pack($pack, $callback($secret));
}
$key = str_pad($secret, $size, \chr(0x00));
$ipad = $key ^ str_repeat(\chr(0x36), $size);
$opad = $key ^ str_repeat(\chr(0x5C), $size);
$hmac = $callback($opad . pack($pack, $callback($ipad . $data)));
$key = str_pad($secret, $size, \chr(0x00));
$ipad = $key ^ str_repeat(\chr(0x36), $size);
$opad = $key ^ str_repeat(\chr(0x5C), $size);
$hmac = $callback($opad . pack($pack, $callback($ipad . $data)));

return $raw_output ? pack($pack, $hmac) : $hmac;
}
Expand Down
8 changes: 4 additions & 4 deletions src/ListToTree.php
Expand Up @@ -21,9 +21,9 @@ class ListToTree

private string $parent_index = 'parent_id';

private string $node_index = 'id';
private string $node_index = 'id';

private string $node_name = 'child';
private string $node_name = 'child';

public function __construct(array $list = [])
{
Expand All @@ -37,8 +37,8 @@ public function toTree(): array
foreach ($data as $d) {
$items[$d[$this->node_index]] = $d;
}
$tree = [];
$n = 0;
$tree = [];
$n = 0;
foreach ($items as $node_index => $item) {
if (isset($items[$item[$this->parent_index]])) {
$items[$item[$this->parent_index]][$this->node_name][] = &$items[$node_index];
Expand Down
6 changes: 3 additions & 3 deletions src/MimeTypes.php
Expand Up @@ -7,7 +7,7 @@
class MimeTypes
{
// copy from : https://github.com/ralouphie/mimey/blob/develop/mime.types.php
public array $mimes = [
public array $mimes = [
'wof' => [
0 => 'application/font-woff',
],
Expand Down Expand Up @@ -2979,7 +2979,7 @@ class MimeTypes
0 => 'x-conference/x-cooltalk',
],
];
public array $extensions = [
public array $extensions = [
'application/font-woff' => [
0 => 'wof',
],
Expand Down Expand Up @@ -5543,7 +5543,7 @@ class MimeTypes
'extensions' => [],
];

private array $types = [
private array $types = [
'text',
'application',
'video',
Expand Down
6 changes: 2 additions & 4 deletions src/Path.php
Expand Up @@ -10,16 +10,14 @@ class Path

/**
* path join.
*
* @param string ...$paths
*/
public static function join(string ...$paths): string
{
$is_win = \PHP_SHLIB_SUFFIX === 'dll';
$is_win = \PHP_SHLIB_SUFFIX === 'dll';
if (0 === count($paths)) {
throw new \InvalidArgumentException('At least one parameter needs to be passed in.');
}
$base = array_shift($paths);
$base = array_shift($paths);
if ($is_win && str_contains($base, \DIRECTORY_SEPARATOR)) {
$pathResult = explode(\DIRECTORY_SEPARATOR, $base);
} else {
Expand Down
4 changes: 1 addition & 3 deletions src/PharOperator.php
Expand Up @@ -35,8 +35,6 @@ public function __construct($zip_dir = null, $include = '/\.*$/', $exclude = [])
}

/**
* @param $index
*
* @return $this
*/
public function setIndex(string $index): self
Expand All @@ -55,7 +53,7 @@ public function addExclude(string $exclude): self

public function zip(string $output_path): void
{
$save_path = $output_path;
$save_path = $output_path;
if (is_dir($save_path)) {
throw new \InvalidArgumentException("{$output_path} must be file path.");
}
Expand Down
12 changes: 6 additions & 6 deletions src/RSACrypt.php
Expand Up @@ -6,15 +6,15 @@

class RSACrypt
{
public array $config = [
public array $config = [
'digest_alg' => 'sha256',
'private_key_bits' => 2048,
'private_key_type' => \OPENSSL_KEYTYPE_RSA,
];
private string $private_key = '';
private string $public_key = '';
private int $encrypt_block_size = 200;
private int $decrypt_block_size = 256;
private string $private_key = '';
private string $public_key = '';
private int $encrypt_block_size = 200;
private int $decrypt_block_size = 256;

public function __construct($config = [])
{
Expand Down Expand Up @@ -69,7 +69,7 @@ public function create(array $config = []): self
$res = openssl_pkey_new($config);
openssl_pkey_export($res, $pri_key);
$this->privateKey($pri_key);
$res = openssl_pkey_get_details($res);
$res = openssl_pkey_get_details($res);
$this->publicKey($res['key']);

return $this;
Expand Down

0 comments on commit 4c49b56

Please sign in to comment.