Skip to content

Commit b127a53

Browse files
committed
run code inspect check, some update
1 parent 636d20e commit b127a53

File tree

9 files changed

+81
-55
lines changed

9 files changed

+81
-55
lines changed

src/DataHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ protected function split_packet($length, $packet, $user)
115115
if ($user->hasSentClose) {
116116
$this->disconnect($user->socket);
117117
} else {
118-
if ((preg_match('//u', $message)) || ($headers['opcode'] == 2)) {
118+
if (((int)$headers['opcode'] === 2) || preg_match('//u', $message)) {
119119
//$this->stdout("Text msg encoded UTF-8 or Binary msg\n".$message);
120120
$this->process($user, $message);
121121
} else {

src/Frame/HybiFrame.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class HybiFrame extends Frame
6565
*/
6666
public function encode($payload, $type = Protocol::TYPE_TEXT, $masked = false)
6767
{
68-
if (!\is_int($type) || !\in_array($type, Protocol::FRAME_TYPES)) {
68+
if (!\is_int($type) || !in_array($type, Protocol::FRAME_TYPES, true)) {
6969
throw new InvalidArgumentException('Invalid frame type');
7070
}
7171

@@ -292,39 +292,47 @@ public function receiveData($data)
292292
* @return bool
293293
* @throws FrameException
294294
*/
295-
public function isFinal()
295+
public function isFinal(): bool
296296
{
297297
if (!isset($this->buffer[self::BYTE_HEADER])) {
298298
throw new FrameException('Cannot yet tell if frame is final');
299299
}
300300

301-
return (boolean)(\ord($this->buffer[self::BYTE_HEADER]) & self::BITFIELD_FINAL);
301+
return (bool)(\ord($this->buffer[self::BYTE_HEADER]) & self::BITFIELD_FINAL);
302302
}
303303

304304
/**
305305
* @throws FrameException
306306
*/
307-
public function getType()
307+
public function getType(): int
308308
{
309309
if (!isset($this->buffer[self::BYTE_HEADER])) {
310310
throw new FrameException('Cannot yet tell type of frame');
311311
}
312312

313-
$type = (int)(\ord($this->buffer[self::BYTE_HEADER]) & self::BITFIELD_TYPE);
313+
$type = (\ord($this->buffer[self::BYTE_HEADER]) & self::BITFIELD_TYPE);
314314

315-
if (!\in_array($type, Protocol::FRAME_TYPES)) {
315+
if (!in_array($type, Protocol::FRAME_TYPES, true)) {
316316
throw new FrameException('Invalid payload type');
317317
}
318318

319319
return $type;
320320
}
321321

322-
protected function getExpectedBufferLength()
322+
/**
323+
* @return int
324+
* @throws FrameException
325+
*/
326+
protected function getExpectedBufferLength(): int
323327
{
324328
return $this->getLength() + $this->getPayloadOffset();
325329
}
326330

327-
public function getLength()
331+
/**
332+
* @return int
333+
* @throws FrameException
334+
*/
335+
public function getLength(): int
328336
{
329337
if (!$this->length) {
330338
$initial = $this->getInitialLength();
@@ -353,6 +361,9 @@ public function getLength()
353361
return $this->length;
354362
}
355363

364+
/**
365+
* @throws FrameException
366+
*/
356367
protected function decodeFramePayloadFromBuffer()
357368
{
358369
$payload = substr($this->buffer, $this->getPayloadOffset());

src/Helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static function frame(string $s): string
4545
* @param $buffer
4646
* @return string
4747
*/
48-
public static function decode($buffer)
48+
public static function decode($buffer): string
4949
{
5050
/*$len = $masks = $data =*/
5151
$decoded = '';

src/Payload/Payload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function encode(string $data, int $type = Protocol::TYPE_TEXT, bool $mask
5656
*
5757
* @return Frame
5858
*/
59-
abstract protected function getFrame();
59+
abstract protected function getFrame(): Frame;
6060

6161
/**
6262
* Whether this payload is waiting for more data

src/Payload/PayloadHandler.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
namespace MyLib\WebSocket\Util\Payload;
44

5-
use Inhere\Library\StdObject;
65
use InvalidArgumentException;
7-
use Wrench\Exception\PayloadException;
6+
use MyLib\ObjUtil\Obj;
7+
use MyLib\PhpUtil\PhpHelper;
8+
use MyLib\WebSocket\Util\Exception\PayloadException;
89

910
/**
1011
* Handles chunking and splitting of payloads into frames
1112
*/
12-
class PayloadHandler extends StdObject
13+
class PayloadHandler
1314
{
1415
/**
1516
* A callback that will be called when a complete payload is available
@@ -20,6 +21,7 @@ class PayloadHandler extends StdObject
2021

2122
/**
2223
* The current payload
24+
* @var Payload
2325
*/
2426
protected $payload;
2527

@@ -30,7 +32,7 @@ class PayloadHandler extends StdObject
3032
*/
3133
public function __construct(callable $callback, array $options = [])
3234
{
33-
parent::__construct($options);
35+
Obj::init($this, $options);
3436

3537
$this->callback = $callback;
3638
}
@@ -49,6 +51,7 @@ public function handle(string $data)
4951

5052
while ($data) { // Each iteration pulls off a single payload chunk
5153
$size = \strlen($data);
54+
$chunkSize = 0;
5255
$remaining = $this->payload->getRemainingData();
5356

5457
// If we don't yet know how much data is remaining, read data into
@@ -91,7 +94,7 @@ public function handle(string $data)
9194
*/
9295
protected function emit(Payload $payload)
9396
{
94-
\call_user_func($this->callback, $payload);
97+
PhpHelper::call($this->callback, $payload);
9598
}
9699

97100
/**

src/Protocol/Hybi10Protocol.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Hybi10Protocol extends HybiProtocol
1212
/**
1313
* @see Protocol::getVersion()
1414
*/
15-
public function getVersion(): string
15+
public function getVersion(): int
1616
{
1717
return self::VERSION;
1818
}

0 commit comments

Comments
 (0)