@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @return string|bool|array{hash:string, key:string, iv:string} |
30 | 30 | * @throws bptException |
31 | 31 | */ |
32 | - public static function crypto (string $action, string $text, string $key = null, string $iv = null): bool|array|string { |
|
32 | + public static function crypto(string $action, string $text, string $key = null, string $iv = null): bool | array | string { |
|
33 | 33 | if (extension_loaded('openssl')) { |
34 | 34 | if ($action === cryptoAction::ENCRYPT) { |
35 | 35 | $key = self::randomString(64); |
@@ -39,22 +39,22 @@ discard block |
||
39 | 39 | } |
40 | 40 | elseif ($action === cryptoAction::DECRYPT) { |
41 | 41 | if (empty($key)) { |
42 | - logger::write("tools::crypto function used\nkey parameter is not set",loggerTypes::ERROR); |
|
42 | + logger::write("tools::crypto function used\nkey parameter is not set", loggerTypes::ERROR); |
|
43 | 43 | throw new bptException('ARGUMENT_NOT_FOUND_KEY'); |
44 | 44 | } |
45 | 45 | elseif (empty($iv)) { |
46 | - logger::write("tools::crypto function used\niv parameter is not set",loggerTypes::ERROR); |
|
46 | + logger::write("tools::crypto function used\niv parameter is not set", loggerTypes::ERROR); |
|
47 | 47 | throw new bptException('ARGUMENT_NOT_FOUND_IV'); |
48 | 48 | } |
49 | 49 | return openssl_decrypt(base64_decode($text), 'AES-256-CBC', $key, 1, $iv); |
50 | 50 | } |
51 | 51 | else { |
52 | - logger::write("tools::crypto function used\naction is not right, its must be `encode` or `decode`",loggerTypes::WARNING); |
|
52 | + logger::write("tools::crypto function used\naction is not right, its must be `encode` or `decode`", loggerTypes::WARNING); |
|
53 | 53 | return false; |
54 | 54 | } |
55 | 55 | } |
56 | 56 | else { |
57 | - logger::write("tools::crypto function used\nopenssl extension is not found , It may not be installed or enabled",loggerTypes::ERROR); |
|
57 | + logger::write("tools::crypto function used\nopenssl extension is not found , It may not be installed or enabled", loggerTypes::ERROR); |
|
58 | 58 | throw new bptException('OPENSSL_EXTENSION_MISSING'); |
59 | 59 | } |
60 | 60 | } |
@@ -36,24 +36,20 @@ |
||
36 | 36 | $iv = self::randomString(); |
37 | 37 | $output = base64_encode(openssl_encrypt($text, 'AES-256-CBC', $key, 1, $iv)); |
38 | 38 | return ['hash' => $output, 'key' => $key, 'iv' => $iv]; |
39 | - } |
|
40 | - elseif ($action === cryptoAction::DECRYPT) { |
|
39 | + } elseif ($action === cryptoAction::DECRYPT) { |
|
41 | 40 | if (empty($key)) { |
42 | 41 | logger::write("tools::crypto function used\nkey parameter is not set",loggerTypes::ERROR); |
43 | 42 | throw new bptException('ARGUMENT_NOT_FOUND_KEY'); |
44 | - } |
|
45 | - elseif (empty($iv)) { |
|
43 | + } elseif (empty($iv)) { |
|
46 | 44 | logger::write("tools::crypto function used\niv parameter is not set",loggerTypes::ERROR); |
47 | 45 | throw new bptException('ARGUMENT_NOT_FOUND_IV'); |
48 | 46 | } |
49 | 47 | return openssl_decrypt(base64_decode($text), 'AES-256-CBC', $key, 1, $iv); |
50 | - } |
|
51 | - else { |
|
48 | + } else { |
|
52 | 49 | logger::write("tools::crypto function used\naction is not right, its must be `encode` or `decode`",loggerTypes::WARNING); |
53 | 50 | return false; |
54 | 51 | } |
55 | - } |
|
56 | - else { |
|
52 | + } else { |
|
57 | 53 | logger::write("tools::crypto function used\nopenssl extension is not found , It may not be installed or enabled",loggerTypes::ERROR); |
58 | 54 | throw new bptException('OPENSSL_EXTENSION_MISSING'); |
59 | 55 | } |
@@ -21,10 +21,10 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @return string |
23 | 23 | */ |
24 | - public static function byteFormat (int $byte, int $precision = 2): string { |
|
24 | + public static function byteFormat(int $byte, int $precision = 2): string { |
|
25 | 25 | $rate_counter = 0; |
26 | 26 | |
27 | - while ($byte > 1024){ |
|
27 | + while ($byte > 1024) { |
|
28 | 28 | $byte /= 1024; |
29 | 29 | $rate_counter++; |
30 | 30 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | $byte = round($byte, $precision); |
34 | 34 | } |
35 | 35 | |
36 | - return $byte . ' ' . ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'][$rate_counter]; |
|
36 | + return $byte.' '.['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'][$rate_counter]; |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -50,10 +50,10 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @return string|false return false when mode is incorrect |
52 | 52 | */ |
53 | - public static function modeEscape (string $text, string $mode = parseMode::HTML): string|false { |
|
53 | + public static function modeEscape(string $text, string $mode = parseMode::HTML): string | false { |
|
54 | 54 | return match ($mode) { |
55 | - parseMode::HTML => str_replace(['&', '<', '>',], ["&", "<", ">",], $text), |
|
56 | - parseMode::MARKDOWN => str_replace(['\\', '_', '*', '`', '['], ['\\\\', '\_', '\*', '\`', '\[',], $text), |
|
55 | + parseMode::HTML => str_replace(['&', '<', '>', ], ["&", "<", ">", ], $text), |
|
56 | + parseMode::MARKDOWN => str_replace(['\\', '_', '*', '`', '['], ['\\\\', '\_', '\*', '\`', '\[', ], $text), |
|
57 | 57 | parseMode::MARKDOWNV2 => str_replace( |
58 | 58 | ['_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!', '\\'], |
59 | 59 | ['\_', '\*', '\[', '\]', '\(', '\)', '\~', '\`', '\>', '\#', '\+', '\-', '\=', '\|', '\{', '\}', '\.', '\!', '\\\\'], |
@@ -92,12 +92,12 @@ discard block |
||
92 | 92 | * @return array{status: string,year: string,month: string,day: string,hour: string,minute: string,second: string} |
93 | 93 | * @throws Exception |
94 | 94 | */ |
95 | - public static function timeDiff (int|string $target_time, int|string|null $base_time = null): array { |
|
95 | + public static function timeDiff(int | string $target_time, int | string | null $base_time = null): array { |
|
96 | 96 | if (!isset($base_time)) { |
97 | 97 | $base_time = '@'.time(); |
98 | 98 | } |
99 | 99 | $base_time = new DateTime($base_time); |
100 | - $target_time = new DateTime(is_numeric($target_time) ? '@' . $target_time : $target_time . ' +00:00'); |
|
100 | + $target_time = new DateTime(is_numeric($target_time) ? '@'.$target_time : $target_time.' +00:00'); |
|
101 | 101 | |
102 | 102 | $diff = $base_time->diff($target_time); |
103 | 103 |
@@ -105,8 +105,9 @@ |
||
105 | 105 | foreach ($string as $k => &$v) { |
106 | 106 | if ($diff->$v) { |
107 | 107 | $v = $diff->$v; |
108 | + } else { |
|
109 | + unset($string[$k]); |
|
108 | 110 | } |
109 | - else unset($string[$k]); |
|
110 | 111 | } |
111 | 112 | $string['status'] = $base_time < $target_time ? 'later' : 'ago'; |
112 | 113 |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * |
27 | 27 | * @return string|int|false string for formatted data , int for normal data , false when size can not be found(file not found or ...) |
28 | 28 | */ |
29 | - public static function size (string $path, bool $format = true): string|int|false { |
|
29 | + public static function size(string $path, bool $format = true): string | int | false { |
|
30 | 30 | if (filter_var($path, FILTER_VALIDATE_URL)) { |
31 | 31 | $ch = curl_init($path); |
32 | 32 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * @return bool |
59 | 59 | * @throws bptException |
60 | 60 | */ |
61 | - public static function delete (string $path, bool $sub = true): bool { |
|
61 | + public static function delete(string $path, bool $sub = true): bool { |
|
62 | 62 | if (is_dir($path)) { |
63 | 63 | if (count(scandir($path)) > 2) { |
64 | 64 | if ($sub) { |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | return rmdir($path); |
71 | 71 | } |
72 | 72 | else { |
73 | - logger::write("tools::delete function used\ndelete function cannot delete folder because its have subFiles and sub parameter haven't true value",loggerTypes::ERROR); |
|
73 | + logger::write("tools::delete function used\ndelete function cannot delete folder because its have subFiles and sub parameter haven't true value", loggerTypes::ERROR); |
|
74 | 74 | throw new bptException('DELETE_FOLDER_HAS_SUB'); |
75 | 75 | } |
76 | 76 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @return bool |
91 | 91 | * @throws bptException when zip extension not found |
92 | 92 | */ |
93 | - public static function zip (string $path, string $destination): bool { |
|
93 | + public static function zip(string $path, string $destination): bool { |
|
94 | 94 | if (extension_loaded('zip')) { |
95 | 95 | $rootPath = realpath($path); |
96 | 96 | $zip = new ZipArchive(); |
@@ -35,14 +35,14 @@ discard block |
||
35 | 35 | curl_exec($ch); |
36 | 36 | $size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD); |
37 | 37 | curl_close($ch); |
38 | - } |
|
39 | - else { |
|
38 | + } else { |
|
40 | 39 | $size = file_exists($path) ? filesize($path) : false; |
41 | 40 | } |
42 | 41 | if (isset($size) && is_numeric($size)) { |
43 | 42 | return $format ? tools::byteFormat($size) : $size; |
43 | + } else { |
|
44 | + return false; |
|
44 | 45 | } |
45 | - else return false; |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -68,15 +68,16 @@ discard block |
||
68 | 68 | $file->isDir() ? rmdir($file->getRealPath()) : unlink($file->getRealPath()); |
69 | 69 | } |
70 | 70 | return rmdir($path); |
71 | - } |
|
72 | - else { |
|
71 | + } else { |
|
73 | 72 | logger::write("tools::delete function used\ndelete function cannot delete folder because its have subFiles and sub parameter haven't true value",loggerTypes::ERROR); |
74 | 73 | throw new bptException('DELETE_FOLDER_HAS_SUB'); |
75 | 74 | } |
75 | + } else { |
|
76 | + return rmdir($path); |
|
76 | 77 | } |
77 | - else return rmdir($path); |
|
78 | + } else { |
|
79 | + return unlink($path); |
|
78 | 80 | } |
79 | - else return unlink($path); |
|
80 | 81 | } |
81 | 82 | |
82 | 83 | /** |
@@ -104,13 +105,11 @@ discard block |
||
104 | 105 | $zip->addFile($filePath, substr($filePath, $root_len)); |
105 | 106 | } |
106 | 107 | } |
107 | - } |
|
108 | - else { |
|
108 | + } else { |
|
109 | 109 | $zip->addFile($path, basename($path)); |
110 | 110 | } |
111 | 111 | return $zip->close(); |
112 | - } |
|
113 | - else { |
|
112 | + } else { |
|
114 | 113 | logger::write("tools::zip function used\nzip extension is not found , It may not be installed or enabled", loggerTypes::ERROR); |
115 | 114 | throw new bptException('ZIP_EXTENSION_MISSING'); |
116 | 115 | } |
@@ -11,32 +11,32 @@ discard block |
||
11 | 11 | class answer { |
12 | 12 | private static bool $is_answered = false; |
13 | 13 | |
14 | - public static function init(string $method,array $data) { |
|
14 | + public static function init(string $method, array $data) { |
|
15 | 15 | self::checkAnswered(); |
16 | 16 | self::checkWebhook(); |
17 | 17 | self::sieveData($data); |
18 | 18 | self::$is_answered = true; |
19 | 19 | $data['method'] = $method; |
20 | 20 | $payload = json_encode($data); |
21 | - header('Content-Type: application/json;Content-Length: ' . strlen($payload)); |
|
21 | + header('Content-Type: application/json;Content-Length: '.strlen($payload)); |
|
22 | 22 | echo $payload; |
23 | 23 | return true; |
24 | 24 | } |
25 | 25 | |
26 | 26 | private static function checkAnswered() { |
27 | 27 | if (self::$is_answered) { |
28 | - logger::write('You can use answer mode only once for each webhook update , You already did it!',loggerTypes::ERROR); |
|
28 | + logger::write('You can use answer mode only once for each webhook update , You already did it!', loggerTypes::ERROR); |
|
29 | 29 | throw new bptException('ANSWER_MODE_USED'); |
30 | 30 | } |
31 | 31 | } |
32 | 32 | |
33 | 33 | private static function checkWebhook() { |
34 | - if(settings::$receiver === receiver::GETUPDATES) { |
|
35 | - logger::write('Answer mode only work when receiver is webhook',loggerTypes::ERROR); |
|
34 | + if (settings::$receiver === receiver::GETUPDATES) { |
|
35 | + logger::write('Answer mode only work when receiver is webhook', loggerTypes::ERROR); |
|
36 | 36 | throw new bptException('ANSWER_MODE_GETUPDATES'); |
37 | 37 | } |
38 | - elseif(settings::$multi) { |
|
39 | - logger::write('You can not use answer mode when multi setting is on',loggerTypes::ERROR); |
|
38 | + elseif (settings::$multi) { |
|
39 | + logger::write('You can not use answer mode when multi setting is on', loggerTypes::ERROR); |
|
40 | 40 | throw new bptException('ANSWER_MODE_MULTI'); |
41 | 41 | } |
42 | 42 | } |
@@ -46,11 +46,11 @@ discard block |
||
46 | 46 | unset($data['forgot']); |
47 | 47 | unset($data['return_array']); |
48 | 48 | |
49 | - foreach ($data as $key=>&$value){ |
|
50 | - if (!isset($value)){ |
|
49 | + foreach ($data as $key=>&$value) { |
|
50 | + if (!isset($value)) { |
|
51 | 51 | unset($data[$key]); |
52 | 52 | } |
53 | - elseif (is_array($value) || is_object($value)){ |
|
53 | + elseif (is_array($value) || is_object($value)) { |
|
54 | 54 | $value = json_encode($value); |
55 | 55 | } |
56 | 56 | } |
@@ -34,8 +34,7 @@ discard block |
||
34 | 34 | if(settings::$receiver === receiver::GETUPDATES) { |
35 | 35 | logger::write('Answer mode only work when receiver is webhook',loggerTypes::ERROR); |
36 | 36 | throw new bptException('ANSWER_MODE_GETUPDATES'); |
37 | - } |
|
38 | - elseif(settings::$multi) { |
|
37 | + } elseif(settings::$multi) { |
|
39 | 38 | logger::write('You can not use answer mode when multi setting is on',loggerTypes::ERROR); |
40 | 39 | throw new bptException('ANSWER_MODE_MULTI'); |
41 | 40 | } |
@@ -49,8 +48,7 @@ discard block |
||
49 | 48 | foreach ($data as $key=>&$value){ |
50 | 49 | if (!isset($value)){ |
51 | 50 | unset($data[$key]); |
52 | - } |
|
53 | - elseif (is_array($value) || is_object($value)){ |
|
51 | + } elseif (is_array($value) || is_object($value)){ |
|
54 | 52 | $value = json_encode($value); |
55 | 53 | } |
56 | 54 | } |