@@ -129,7 +129,7 @@ |
||
129 | 129 | $log[$name] = $value ? strtotime(explode('.', $value)[0]) : 0; |
130 | 130 | break; |
131 | 131 | case "int": |
132 | - $log[$name] = $value ? (int)$value : 0; |
|
132 | + $log[$name] = $value ? ( int ) $value : 0; |
|
133 | 133 | break; |
134 | 134 | case "string": |
135 | 135 | $log[$name] = $value ? trim($value) : ''; |
@@ -25,7 +25,7 @@ |
||
25 | 25 | continue; |
26 | 26 | } |
27 | 27 | ArrayHelper::remove($msg, '%c'); |
28 | - echo implode($this->split, $msg) . PHP_EOL; |
|
28 | + echo implode($this->split, $msg).PHP_EOL; |
|
29 | 29 | } |
30 | 30 | } |
31 | 31 | } |
@@ -10,7 +10,7 @@ |
||
10 | 10 | */ |
11 | 11 | function rgo(Closure $function, ?Closure $defer = null): int |
12 | 12 | { |
13 | - $cid = go(function () use ($function, $defer): int { |
|
13 | + $cid = go(function() use ($function, $defer) : int { |
|
14 | 14 | try { |
15 | 15 | if (is_callable($defer)) { |
16 | 16 | defer($defer); |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | public function __construct(array $target, array $configs = []) |
21 | 21 | { |
22 | 22 | $this->template = explode($this->split, ini_get('seaslog.default_template')); |
23 | - ini_set('seaslog.recall_depth', (string)$this->recall_depth); |
|
23 | + ini_set('seaslog.recall_depth', ( string ) $this->recall_depth); |
|
24 | 24 | parent::__construct($target, $configs); |
25 | 25 | } |
26 | 26 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | $template = $this->getUserTemplate(); |
56 | 56 | $module = ArrayHelper::remove($context, 'module'); |
57 | 57 | if ($module !== null) { |
58 | - Seaslog::setLogger($this->appName . '_' . $module); |
|
58 | + Seaslog::setLogger($this->appName.'_'.$module); |
|
59 | 59 | } |
60 | 60 | isset($template['%Q']) && Seaslog::setRequestID($template['%Q']); |
61 | 61 | foreach (array_filter([ |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | case AbstractConfig::TYPE_FIELD: |
76 | 76 | $template = implode($this->split, $template); |
77 | 77 | } |
78 | - $message = $template . $this->split . $message; |
|
78 | + $message = $template.$this->split.$message; |
|
79 | 79 | } |
80 | 80 | Seaslog::$level($message); |
81 | 81 | $this->flush(); |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | if (($flush || Seaslog::getBufferCount() >= $this->bufferSize) && ($buffer = Seaslog::getBuffer()) !== false) { |
92 | 92 | Seaslog::flushBuffer(0); |
93 | 93 | foreach ($this->targetList as $index => $target) { |
94 | - rgo(function () use ($target, $buffer) { |
|
94 | + rgo(function() use ($target, $buffer) { |
|
95 | 95 | $target->export($buffer); |
96 | 96 | }); |
97 | 97 | } |
@@ -50,15 +50,15 @@ discard block |
||
50 | 50 | } |
51 | 51 | |
52 | 52 | $header = $this->requestHeader('seaslog-kafka', 0, self::PRODUCE_REQUEST); |
53 | - $data = self::pack(self::BIT_B16, (string)($payloads['required_ack'] ?? 0)); |
|
54 | - $data .= self::pack(self::BIT_B32, (string)($payloads['timeout'] ?? 100)); |
|
53 | + $data = self::pack(self::BIT_B16, ( string ) ($payloads['required_ack'] ?? 0)); |
|
54 | + $data .= self::pack(self::BIT_B32, ( string ) ($payloads['timeout'] ?? 100)); |
|
55 | 55 | $data .= self::encodeArray( |
56 | 56 | $payloads['data'], |
57 | 57 | [$this, 'encodeProduceTopic'], |
58 | 58 | $payloads['compression'] ?? self::COMPRESSION_NONE |
59 | 59 | ); |
60 | 60 | |
61 | - return self::encodeString($header . $data, self::PACK_INT32); |
|
61 | + return self::encodeString($header.$data, self::PACK_INT32); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -99,9 +99,9 @@ discard block |
||
99 | 99 | throw new InvalidArgumentException('given produce data invalid. `messages` is undefined.'); |
100 | 100 | } |
101 | 101 | |
102 | - $data = self::pack(self::BIT_B32, (string)$values['partition_id']); |
|
102 | + $data = self::pack(self::BIT_B32, ( string ) $values['partition_id']); |
|
103 | 103 | $data .= self::encodeString( |
104 | - $this->encodeMessageSet((array)$values['messages'], $compression), |
|
104 | + $this->encodeMessageSet(( array ) $values['messages'], $compression), |
|
105 | 105 | self::PACK_INT32 |
106 | 106 | ); |
107 | 107 | |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | foreach ($messages as $message) { |
127 | 127 | $encodedMessage = $this->encodeMessage($message); |
128 | 128 | |
129 | - $data .= self::pack(self::BIT_B64, (string)$next) |
|
129 | + $data .= self::pack(self::BIT_B64, ( string ) $next) |
|
130 | 130 | . self::encodeString($encodedMessage, self::PACK_INT32); |
131 | 131 | |
132 | 132 | ++$next; |
@@ -151,8 +151,8 @@ discard block |
||
151 | 151 | $magic = $this->computeMagicByte(); |
152 | 152 | $attributes = $this->computeAttributes($magic, $compression, $this->computeTimestampType($magic)); |
153 | 153 | |
154 | - $data = self::pack(self::BIT_B8, (string)$magic); |
|
155 | - $data .= self::pack(self::BIT_B8, (string)$attributes); |
|
154 | + $data = self::pack(self::BIT_B8, ( string ) $magic); |
|
155 | + $data .= self::pack(self::BIT_B8, ( string ) $attributes); |
|
156 | 156 | |
157 | 157 | if ($magic >= self::MESSAGE_MAGIC_VERSION1) { |
158 | 158 | $data .= self::pack(self::BIT_B64, $this->clock->now()->format('Uv')); |
@@ -171,10 +171,10 @@ discard block |
||
171 | 171 | // message value |
172 | 172 | $data .= self::encodeString($message, self::PACK_INT32, $compression); |
173 | 173 | |
174 | - $crc = (string)crc32($data); |
|
174 | + $crc = ( string ) crc32($data); |
|
175 | 175 | |
176 | 176 | // int32 -- crc code string data |
177 | - $message = self::pack(self::BIT_B32, $crc) . $data; |
|
177 | + $message = self::pack(self::BIT_B32, $crc).$data; |
|
178 | 178 | |
179 | 179 | return $message; |
180 | 180 | } |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | $topic = self::encodeString($values['topic_name'], self::PACK_INT16); |
238 | 238 | $partitions = self::encodeArray($values['partitions'], [$this, 'encodeProducePartition'], $compression); |
239 | 239 | |
240 | - return $topic . $partitions; |
|
240 | + return $topic.$partitions; |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | /** |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | $body .= $options !== null ? $func($value, $options) : $func($value); |
130 | 130 | } |
131 | 131 | |
132 | - return self::pack(self::BIT_B32, (string)$arrayCount) . $body; |
|
132 | + return self::pack(self::BIT_B32, ( string ) $arrayCount).$body; |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | public static function pack(string $type, string $data): string |
@@ -138,11 +138,11 @@ discard block |
||
138 | 138 | return pack($type, $data); |
139 | 139 | } |
140 | 140 | |
141 | - if ((int)$data === -1) { // -1L |
|
141 | + if (( int ) $data === -1) { // -1L |
|
142 | 142 | return hex2bin('ffffffffffffffff'); |
143 | 143 | } |
144 | 144 | |
145 | - if ((int)$data === -2) { // -2L |
|
145 | + if (( int ) $data === -2) { // -2L |
|
146 | 146 | return hex2bin('fffffffffffffffe'); |
147 | 147 | } |
148 | 148 | |
@@ -179,9 +179,9 @@ discard block |
||
179 | 179 | public function requestHeader(string $clientId, int $correlationId, int $apiKey): string |
180 | 180 | { |
181 | 181 | // int16 -- apiKey int16 -- apiVersion int32 correlationId |
182 | - $binData = self::pack(self::BIT_B16, (string)$apiKey); |
|
183 | - $binData .= self::pack(self::BIT_B16, (string)$this->getApiVersion($apiKey)); |
|
184 | - $binData .= self::pack(self::BIT_B32, (string)$correlationId); |
|
182 | + $binData = self::pack(self::BIT_B16, ( string ) $apiKey); |
|
183 | + $binData .= self::pack(self::BIT_B16, ( string ) $this->getApiVersion($apiKey)); |
|
184 | + $binData .= self::pack(self::BIT_B32, ( string ) $correlationId); |
|
185 | 185 | |
186 | 186 | // concat client id |
187 | 187 | $binData .= self::encodeString($clientId, self::PACK_INT16); |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | $packLen = $bytes === self::PACK_INT32 ? self::BIT_B32 : self::BIT_B16; |
227 | 227 | $string = self::compress($string, $compression); |
228 | 228 | |
229 | - return self::pack($packLen, (string)strlen($string)) . $string; |
|
229 | + return self::pack($packLen, ( string ) strlen($string)).$string; |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | } |
246 | 246 | |
247 | 247 | if ($compression !== self::COMPRESSION_GZIP) { |
248 | - throw new BadMethodCallException('Unknown compression flag: ' . $compression); |
|
248 | + throw new BadMethodCallException('Unknown compression flag: '.$compression); |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | return gzencode($string); |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | return ['length' => $offset, 'data' => '']; |
273 | 273 | } |
274 | 274 | |
275 | - $data = (string)substr($data, $offset, (int)$packLen); |
|
275 | + $data = ( string ) substr($data, $offset, ( int ) $packLen); |
|
276 | 276 | $offset += $packLen; |
277 | 277 | |
278 | 278 | return ['length' => $offset, 'data' => self::decompress($data, $compression)]; |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | $length = strlen($bytes); |
342 | 342 | |
343 | 343 | if ($length !== $expectedLength) { |
344 | - throw new Exception('unpack failed. string(raw) length is ' . $length . ' , TO ' . $type); |
|
344 | + throw new Exception('unpack failed. string(raw) length is '.$length.' , TO '.$type); |
|
345 | 345 | } |
346 | 346 | } |
347 | 347 | |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | } else { |
359 | 359 | [$endianTest] = array_values($value); |
360 | 360 | |
361 | - self::$isLittleEndianSystem = (int)$endianTest === 1; |
|
361 | + self::$isLittleEndianSystem = ( int ) $endianTest === 1; |
|
362 | 362 | } |
363 | 363 | } |
364 | 364 | |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | */ |
375 | 375 | public static function convertSignedShortFromLittleEndianToBigEndian(array $bits): array |
376 | 376 | { |
377 | - $convert = function (int $bit): int { |
|
377 | + $convert = function(int $bit): int { |
|
378 | 378 | $lsb = $bit & 0xff; |
379 | 379 | $msb = $bit >> 8 & 0xff; |
380 | 380 | $bit = $lsb << 8 | $msb; |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | } |
401 | 401 | |
402 | 402 | if ($compression !== self::COMPRESSION_GZIP) { |
403 | - throw new BadMethodCallException('Unknown compression flag: ' . $compression); |
|
403 | + throw new BadMethodCallException('Unknown compression flag: '.$compression); |
|
404 | 404 | } |
405 | 405 | |
406 | 406 | return gzdecode($string); |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | if (!isset($ret['length'], $ret['data'])) { |
435 | 435 | throw new Exception('Decode array failed, given function return format is invalid'); |
436 | 436 | } |
437 | - if ((int)$ret['length'] === 0) { |
|
437 | + if (( int ) $ret['length'] === 0) { |
|
438 | 438 | continue; |
439 | 439 | } |
440 | 440 |
@@ -77,7 +77,7 @@ |
||
77 | 77 | if ($this->maxWait > 0 && $this->waitStack->count() > $this->maxWait) { |
78 | 78 | throw new Exception('Connection pool queue is full'); |
79 | 79 | } |
80 | - $this->waitStack->push((int)Co::getCid()); |
|
80 | + $this->waitStack->push(( int ) Co::getCid()); |
|
81 | 81 | Co::yield(); |
82 | 82 | return $this->queue->shift(); |
83 | 83 | } |
@@ -70,11 +70,11 @@ discard block |
||
70 | 70 | ]; |
71 | 71 | |
72 | 72 | $requestData = ProtocolTool::encode(ProtocolTool::PRODUCE_REQUEST, $params); |
73 | - rgo(function () use ($connect, $requestData, $requiredAck, $callback) { |
|
73 | + rgo(function() use ($connect, $requestData, $requiredAck, $callback) { |
|
74 | 74 | if ($requiredAck !== 0) { |
75 | 75 | $connect->send($requestData); |
76 | 76 | $dataLen = Protocol::unpack(Protocol::BIT_B32, $connect->recv(4)); |
77 | - $recordSet = $connect->recv((int)$dataLen); |
|
77 | + $recordSet = $connect->recv(( int ) $dataLen); |
|
78 | 78 | $this->pool->release($connect); |
79 | 79 | Protocol::unpack(Protocol::BIT_B32, substr($recordSet, 0, 4)); |
80 | 80 | $callback && $callback(ProtocolTool::decode(ProtocolTool::PRODUCE_REQUEST, |
@@ -93,14 +93,14 @@ discard block |
||
93 | 93 | public function syncMeta(): void |
94 | 94 | { |
95 | 95 | $socket = $this->pool->getConnection(); |
96 | - rgo(function () use ($socket) { |
|
96 | + rgo(function() use ($socket) { |
|
97 | 97 | while (true) { |
98 | 98 | try { |
99 | 99 | $params = []; |
100 | 100 | $requestData = ProtocolTool::encode(ProtocolTool::METADATA_REQUEST, $params); |
101 | 101 | $socket->send($requestData); |
102 | 102 | $dataLen = Protocol::unpack(Protocol::BIT_B32, $socket->recv(4)); |
103 | - $data = $socket->recv((int)$dataLen); |
|
103 | + $data = $socket->recv(( int ) $dataLen); |
|
104 | 104 | Protocol::unpack(Protocol::BIT_B32, substr($data, 0, 4)); |
105 | 105 | $result = ProtocolTool::decode(ProtocolTool::METADATA_REQUEST, substr($data, 4)); |
106 | 106 | if (!isset($result['brokers'], $result['topics'])) { |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | $level = $this->getLevelColor(trim($msg[$this->levelIndex])); |
83 | 83 | if (isset($this->colorTemplate[$index])) { |
84 | 84 | $color = $this->colorTemplate[$index]; |
85 | - $msgValue = is_string($msgValue) ? trim($msgValue) : (string)$msgValue; |
|
85 | + $msgValue = is_string($msgValue) ? trim($msgValue) : ( string ) $msgValue; |
|
86 | 86 | switch ($color) { |
87 | 87 | case self::COLOR_LEVEL: |
88 | 88 | $context[] = $this->color->getColoredString($msgValue, $level); |
@@ -101,8 +101,8 @@ discard block |
||
101 | 101 | } |
102 | 102 | } |
103 | 103 | if (isset($context)) { |
104 | - echo implode(' ' . $this->color->getColoredString('|', $this->splitColor) . ' ', |
|
105 | - $context) . PHP_EOL; |
|
104 | + echo implode(' '.$this->color->getColoredString('|', $this->splitColor).' ', |
|
105 | + $context).PHP_EOL; |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | } |