This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | declare(strict_types=1); |
||
3 | |||
4 | namespace MessagePack; |
||
5 | |||
6 | use MessagePack\{ |
||
7 | Exception\InsufficientData, |
||
8 | Exception\UnknownByteHeader, |
||
9 | Ext |
||
10 | }; |
||
11 | use const MessagePack\ORD; |
||
12 | use function MessagePack\{toDouble, toFloat}; |
||
13 | use function sprintf; |
||
14 | use function substr; |
||
15 | |||
16 | final class Decoder |
||
17 | { |
||
18 | /** @var string */ |
||
19 | private $data = ''; |
||
20 | |||
21 | /** @var int */ |
||
22 | private $offset = 0; |
||
23 | |||
24 | 93 | public function decode(string $data) |
|
25 | { |
||
26 | 93 | $this->data = $data; |
|
27 | 93 | $this->offset = 0; |
|
28 | |||
29 | 93 | return $this->parse(); |
|
30 | } |
||
31 | |||
32 | 93 | private function parse() |
|
33 | { |
||
34 | 93 | if (!isset($this->data[$this->offset])) { |
|
35 | 1 | throw InsufficientData::fromOffset($this->data, $this->offset, 1); |
|
36 | } |
||
37 | |||
38 | 92 | $byte = ORD[$this->data[$this->offset++]]; |
|
39 | |||
40 | 92 | if ($byte < 0xc0) { |
|
41 | // positive fixint |
||
42 | 15 | if ($byte < 0x80) { |
|
43 | 11 | return $byte; |
|
44 | } |
||
45 | // fixmap |
||
46 | 7 | if ($byte < 0x90) { |
|
47 | 2 | return $this->decodeMap($byte & 0xf); |
|
48 | } |
||
49 | // fixarray |
||
50 | 5 | if ($byte < 0xa0) { |
|
51 | 2 | return $this->decodeArray($byte & 0x0f); |
|
52 | } |
||
53 | // fixstr |
||
54 | 3 | return $this->decodeStr($byte & 0x1f); |
|
55 | } |
||
56 | // negative fixint |
||
57 | 83 | if ($byte > 0xdf) { |
|
58 | 2 | return $byte - 0x100; |
|
59 | } |
||
60 | |||
61 | 81 | switch ($byte) { |
|
62 | 81 | case 0xc0: return null; |
|
0 ignored issues
–
show
Terminating statement must be on a line by itself
As per the PSR-2 coding standard, the switch ($expr) {
case "A":
doSomething();
break; //wrong
case "B":
doSomething();
break; //right
case "C:":
doSomething();
return true; //right
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
63 | 80 | case 0xc2: return false; |
|
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() Terminating statement must be on a line by itself
As per the PSR-2 coding standard, the switch ($expr) {
case "A":
doSomething();
break; //wrong
case "B":
doSomething();
break; //right
case "C:":
doSomething();
return true; //right
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
64 | 79 | case 0xc3: return true; |
|
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() Terminating statement must be on a line by itself
As per the PSR-2 coding standard, the switch ($expr) {
case "A":
doSomething();
break; //wrong
case "B":
doSomething();
break; //right
case "C:":
doSomething();
return true; //right
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
65 | |||
66 | // bin 8/16/32 |
||
67 | 77 | case 0xc4: return $this->decodeStr($this->decodeUint8()); |
|
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() Terminating statement must be on a line by itself
As per the PSR-2 coding standard, the switch ($expr) {
case "A":
doSomething();
break; //wrong
case "B":
doSomething();
break; //right
case "C:":
doSomething();
return true; //right
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
68 | 77 | case 0xc5: return $this->decodeStr($this->decodeUint16()); |
|
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() Terminating statement must be on a line by itself
As per the PSR-2 coding standard, the switch ($expr) {
case "A":
doSomething();
break; //wrong
case "B":
doSomething();
break; //right
case "C:":
doSomething();
return true; //right
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
69 | 77 | case 0xc6: return $this->decodeStr($this->decodeUint32()); |
|
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() Terminating statement must be on a line by itself
As per the PSR-2 coding standard, the switch ($expr) {
case "A":
doSomething();
break; //wrong
case "B":
doSomething();
break; //right
case "C:":
doSomething();
return true; //right
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
70 | |||
71 | // float 32/64 |
||
72 | 77 | case 0xca: return $this->decodeFloat32(); |
|
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() Terminating statement must be on a line by itself
As per the PSR-2 coding standard, the switch ($expr) {
case "A":
doSomething();
break; //wrong
case "B":
doSomething();
break; //right
case "C:":
doSomething();
return true; //right
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
73 | 72 | case 0xcb: return $this->decodeFloat64(); |
|
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() Terminating statement must be on a line by itself
As per the PSR-2 coding standard, the switch ($expr) {
case "A":
doSomething();
break; //wrong
case "B":
doSomething();
break; //right
case "C:":
doSomething();
return true; //right
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
74 | |||
75 | // uint 8/16/32/64 |
||
76 | 65 | case 0xcc: return $this->decodeUint8(); |
|
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() Terminating statement must be on a line by itself
As per the PSR-2 coding standard, the switch ($expr) {
case "A":
doSomething();
break; //wrong
case "B":
doSomething();
break; //right
case "C:":
doSomething();
return true; //right
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
77 | 62 | case 0xcd: return $this->decodeUint16(); |
|
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() Terminating statement must be on a line by itself
As per the PSR-2 coding standard, the switch ($expr) {
case "A":
doSomething();
break; //wrong
case "B":
doSomething();
break; //right
case "C:":
doSomething();
return true; //right
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
78 | 59 | case 0xce: return $this->decodeUint32(); |
|
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() Terminating statement must be on a line by itself
As per the PSR-2 coding standard, the switch ($expr) {
case "A":
doSomething();
break; //wrong
case "B":
doSomething();
break; //right
case "C:":
doSomething();
return true; //right
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
79 | 56 | case 0xcf: return $this->decodeUint64(); |
|
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() Terminating statement must be on a line by itself
As per the PSR-2 coding standard, the switch ($expr) {
case "A":
doSomething();
break; //wrong
case "B":
doSomething();
break; //right
case "C:":
doSomething();
return true; //right
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
80 | |||
81 | // int 8/16/32/64 |
||
82 | 53 | case 0xd0: return $this->decodeInt8(); |
|
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() Terminating statement must be on a line by itself
As per the PSR-2 coding standard, the switch ($expr) {
case "A":
doSomething();
break; //wrong
case "B":
doSomething();
break; //right
case "C:":
doSomething();
return true; //right
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
83 | 50 | case 0xd1: return $this->decodeInt16(); |
|
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() Terminating statement must be on a line by itself
As per the PSR-2 coding standard, the switch ($expr) {
case "A":
doSomething();
break; //wrong
case "B":
doSomething();
break; //right
case "C:":
doSomething();
return true; //right
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
84 | 47 | case 0xd2: return $this->decodeInt32(); |
|
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() Terminating statement must be on a line by itself
As per the PSR-2 coding standard, the switch ($expr) {
case "A":
doSomething();
break; //wrong
case "B":
doSomething();
break; //right
case "C:":
doSomething();
return true; //right
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
85 | 39 | case 0xd3: return $this->decodeInt64(); |
|
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() Terminating statement must be on a line by itself
As per the PSR-2 coding standard, the switch ($expr) {
case "A":
doSomething();
break; //wrong
case "B":
doSomething();
break; //right
case "C:":
doSomething();
return true; //right
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
86 | |||
87 | // str 8/16/32 |
||
88 | 29 | case 0xd9: return $this->decodeStr($this->decodeUint8()); |
|
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() Terminating statement must be on a line by itself
As per the PSR-2 coding standard, the switch ($expr) {
case "A":
doSomething();
break; //wrong
case "B":
doSomething();
break; //right
case "C:":
doSomething();
return true; //right
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
89 | 27 | case 0xda: return $this->decodeStr($this->decodeUint16()); |
|
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() Terminating statement must be on a line by itself
As per the PSR-2 coding standard, the switch ($expr) {
case "A":
doSomething();
break; //wrong
case "B":
doSomething();
break; //right
case "C:":
doSomething();
return true; //right
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
90 | 25 | case 0xdb: return $this->decodeStr($this->decodeUint32()); |
|
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() Terminating statement must be on a line by itself
As per the PSR-2 coding standard, the switch ($expr) {
case "A":
doSomething();
break; //wrong
case "B":
doSomething();
break; //right
case "C:":
doSomething();
return true; //right
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
91 | |||
92 | // array 16/32 |
||
93 | 24 | case 0xdc: return $this->decodeArray($this->decodeUint16()); |
|
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() Terminating statement must be on a line by itself
As per the PSR-2 coding standard, the switch ($expr) {
case "A":
doSomething();
break; //wrong
case "B":
doSomething();
break; //right
case "C:":
doSomething();
return true; //right
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
94 | 22 | case 0xdd: return $this->decodeArray($this->decodeUint32()); |
|
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() Terminating statement must be on a line by itself
As per the PSR-2 coding standard, the switch ($expr) {
case "A":
doSomething();
break; //wrong
case "B":
doSomething();
break; //right
case "C:":
doSomething();
return true; //right
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
95 | |||
96 | // map 16/32 |
||
97 | 21 | case 0xde: return $this->decodeMap($this->decodeUint16()); |
|
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() Terminating statement must be on a line by itself
As per the PSR-2 coding standard, the switch ($expr) {
case "A":
doSomething();
break; //wrong
case "B":
doSomething();
break; //right
case "C:":
doSomething();
return true; //right
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
98 | 19 | case 0xdf: return $this->decodeMap($this->decodeUint32()); |
|
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() Terminating statement must be on a line by itself
As per the PSR-2 coding standard, the switch ($expr) {
case "A":
doSomething();
break; //wrong
case "B":
doSomething();
break; //right
case "C:":
doSomething();
return true; //right
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
99 | |||
100 | // fixext 1/2/4/8/16 |
||
101 | 18 | case 0xd4: return $this->decodeExt(1); |
|
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() Terminating statement must be on a line by itself
As per the PSR-2 coding standard, the switch ($expr) {
case "A":
doSomething();
break; //wrong
case "B":
doSomething();
break; //right
case "C:":
doSomething();
return true; //right
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
102 | 16 | case 0xd5: return $this->decodeExt(2); |
|
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() Terminating statement must be on a line by itself
As per the PSR-2 coding standard, the switch ($expr) {
case "A":
doSomething();
break; //wrong
case "B":
doSomething();
break; //right
case "C:":
doSomething();
return true; //right
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
103 | 14 | case 0xd6: return $this->decodeExt(4); |
|
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() Terminating statement must be on a line by itself
As per the PSR-2 coding standard, the switch ($expr) {
case "A":
doSomething();
break; //wrong
case "B":
doSomething();
break; //right
case "C:":
doSomething();
return true; //right
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
104 | 12 | case 0xd7: return $this->decodeExt(8); |
|
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() Terminating statement must be on a line by itself
As per the PSR-2 coding standard, the switch ($expr) {
case "A":
doSomething();
break; //wrong
case "B":
doSomething();
break; //right
case "C:":
doSomething();
return true; //right
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
105 | 10 | case 0xd8: return $this->decodeExt(16); |
|
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() Terminating statement must be on a line by itself
As per the PSR-2 coding standard, the switch ($expr) {
case "A":
doSomething();
break; //wrong
case "B":
doSomething();
break; //right
case "C:":
doSomething();
return true; //right
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
106 | |||
107 | // ext 8/16/32 |
||
108 | 8 | case 0xc7: return $this->decodeExt($this->decodeUint8()); |
|
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() Terminating statement must be on a line by itself
As per the PSR-2 coding standard, the switch ($expr) {
case "A":
doSomething();
break; //wrong
case "B":
doSomething();
break; //right
case "C:":
doSomething();
return true; //right
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
109 | 6 | case 0xc8: return $this->decodeExt($this->decodeUint16()); |
|
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() Terminating statement must be on a line by itself
As per the PSR-2 coding standard, the switch ($expr) {
case "A":
doSomething();
break; //wrong
case "B":
doSomething();
break; //right
case "C:":
doSomething();
return true; //right
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
110 | 3 | case 0xc9: return $this->decodeExt($this->decodeUint32()); |
|
0 ignored issues
–
show
The case body in a switch statement must start on the line following the statement.
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement. switch ($expr) {
case "A":
doSomething(); //right
break;
case "B":
doSomethingElse(); //wrong
break;
} To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() Terminating statement must be on a line by itself
As per the PSR-2 coding standard, the switch ($expr) {
case "A":
doSomething();
break; //wrong
case "B":
doSomething();
break; //right
case "C:":
doSomething();
return true; //right
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig. ![]() |
|||
111 | } |
||
0 ignored issues
–
show
|
|||
112 | |||
113 | 1 | throw UnknownByteHeader::fromOffset($byte, $this->offset); |
|
114 | } |
||
115 | |||
116 | 5 | private function decodeFloat32(): float |
|
117 | { |
||
118 | 5 | if (!isset($this->data[$this->offset + 3])) { |
|
119 | 1 | throw InsufficientData::fromOffset($this->data, $this->offset, 4); |
|
120 | } |
||
121 | |||
122 | 4 | $num = ORD[$this->data[$this->offset++]] * 0x1000000 |
|
123 | 4 | | ORD[$this->data[$this->offset++]] << 16 |
|
124 | 4 | | ORD[$this->data[$this->offset++]] << 8 |
|
125 | 4 | | ORD[$this->data[$this->offset++]]; |
|
126 | |||
127 | 4 | return toFloat($num); |
|
128 | } |
||
129 | |||
130 | 7 | private function decodeFloat64(): float |
|
131 | { |
||
132 | 7 | if (!isset($this->data[$this->offset + 7])) { |
|
133 | 1 | throw InsufficientData::fromOffset($this->data, $this->offset, 8); |
|
134 | } |
||
135 | |||
136 | 6 | $x = ORD[$this->data[$this->offset++]] * 0x1000000 |
|
137 | 6 | | ORD[$this->data[$this->offset++]] << 16 |
|
138 | 6 | | ORD[$this->data[$this->offset++]] << 8 |
|
139 | 6 | | ORD[$this->data[$this->offset++]]; |
|
140 | |||
141 | 6 | $y = ORD[$this->data[$this->offset++]] * 0x1000000 |
|
142 | 6 | | ORD[$this->data[$this->offset++]] << 16 |
|
143 | 6 | | ORD[$this->data[$this->offset++]] << 8 |
|
144 | 6 | | ORD[$this->data[$this->offset++]]; |
|
145 | |||
146 | 6 | return toDouble($y, $x); |
|
147 | } |
||
148 | |||
149 | 9 | private function decodeUint8(): int |
|
150 | { |
||
151 | 9 | if (!isset($this->data[$this->offset])) { |
|
152 | 2 | throw InsufficientData::fromOffset($this->data, $this->offset, 1); |
|
153 | } |
||
154 | |||
155 | 7 | return ORD($this->data[$this->offset++]); |
|
156 | } |
||
157 | |||
158 | 13 | private function decodeUint16(): int |
|
159 | { |
||
160 | 13 | if (!isset($this->data[$this->offset + 1])) { |
|
161 | 2 | throw InsufficientData::fromOffset($this->data, $this->offset, 2); |
|
162 | } |
||
163 | |||
164 | 11 | return ORD[$this->data[$this->offset++]] << 8 |
|
165 | 11 | | ORD[$this->data[$this->offset++]]; |
|
166 | } |
||
167 | |||
168 | 8 | private function decodeUint32(): int |
|
169 | { |
||
170 | 8 | if (!isset($this->data[$this->offset + 3])) { |
|
171 | 2 | throw InsufficientData::fromOffset($this->data, $this->offset, 4); |
|
172 | } |
||
173 | |||
174 | 6 | return ORD[$this->data[$this->offset++]] * 0x1000000 |
|
175 | 6 | | ORD[$this->data[$this->offset++]] << 16 |
|
176 | 6 | | ORD[$this->data[$this->offset++]] << 8 |
|
177 | 6 | | ORD[$this->data[$this->offset++]]; |
|
178 | } |
||
179 | |||
180 | 3 | private function decodeUint64() |
|
181 | { |
||
182 | 3 | if (!isset($this->data[$this->offset + 7])) { |
|
183 | 1 | throw InsufficientData::fromOffset($this->data, $this->offset, 8); |
|
184 | } |
||
185 | |||
186 | 2 | $num = (ORD[$this->data[$this->offset++]] * 0x1000000 |
|
187 | 2 | | ORD[$this->data[$this->offset++]] << 16 |
|
188 | 2 | | ORD[$this->data[$this->offset++]] << 8 |
|
189 | 2 | | ORD[$this->data[$this->offset++]]) * 0x100000000 |
|
190 | 2 | | ORD[$this->data[$this->offset++]] * 0x1000000 |
|
191 | 2 | | ORD[$this->data[$this->offset++]] << 16 |
|
192 | 2 | | ORD[$this->data[$this->offset++]] << 8 |
|
193 | 2 | | ORD[$this->data[$this->offset++]]; |
|
194 | |||
195 | 2 | return $num < 0 ? sprintf('%u', $num) : $num; |
|
196 | } |
||
197 | |||
198 | 3 | private function decodeInt8(): int |
|
199 | { |
||
200 | 3 | if (!isset($this->data[$this->offset])) { |
|
201 | 1 | throw InsufficientData::fromOffset($this->data, $this->offset, 1); |
|
202 | } |
||
203 | |||
204 | 2 | $num = ORD[$this->data[$this->offset++]]; |
|
205 | |||
206 | 2 | return $num & 0x80 ? $num - 0x100 : $num; |
|
207 | } |
||
208 | |||
209 | 3 | private function decodeInt16(): int |
|
210 | { |
||
211 | 3 | if (!isset($this->data[$this->offset + 1])) { |
|
212 | 1 | throw InsufficientData::fromOffset($this->data, $this->offset, 2); |
|
213 | } |
||
214 | |||
215 | 2 | $num = ORD[$this->data[$this->offset++]] << 8 |
|
216 | 2 | | ORD[$this->data[$this->offset++]]; |
|
217 | |||
218 | 2 | return $num & 0x8000 ? $num - 0x10000 : $num; |
|
219 | } |
||
220 | |||
221 | 8 | private function decodeInt32(): int |
|
222 | { |
||
223 | 8 | if (!isset($this->data[$this->offset + 3])) { |
|
224 | 1 | throw InsufficientData::fromOffset($this->data, $this->offset, 4); |
|
225 | } |
||
226 | |||
227 | 7 | $num = ORD[$this->data[$this->offset++]] << 24 |
|
228 | 7 | | ORD[$this->data[$this->offset++]] << 16 |
|
229 | 7 | | ORD[$this->data[$this->offset++]] << 8 |
|
230 | 7 | | ORD[$this->data[$this->offset++]]; |
|
231 | |||
232 | 7 | return $num & 0x80000000 ? $num - 0x100000000 : $num; |
|
233 | } |
||
234 | |||
235 | 10 | private function decodeInt64(): int |
|
236 | { |
||
237 | 10 | if (!isset($this->data[$this->offset + 7])) { |
|
238 | 1 | throw InsufficientData::fromOffset($this->data, $this->offset, 8); |
|
239 | } |
||
240 | |||
241 | 9 | $num = ORD[$this->data[$this->offset++]] << 24 |
|
242 | 9 | | ORD[$this->data[$this->offset++]] << 16 |
|
243 | 9 | | ORD[$this->data[$this->offset++]] << 8 |
|
244 | 9 | | ORD[$this->data[$this->offset++]]; |
|
245 | |||
246 | 9 | if ($num & 0x80000000) { |
|
247 | 8 | $num -= 0x100000000; |
|
248 | } |
||
249 | |||
250 | 9 | return $num * 0x100000000 |
|
251 | 9 | | ORD[$this->data[$this->offset++]] * 0x1000000 |
|
252 | 9 | | ORD[$this->data[$this->offset++]] << 16 |
|
253 | 9 | | ORD[$this->data[$this->offset++]] << 8 |
|
254 | 9 | | ORD[$this->data[$this->offset++]]; |
|
255 | } |
||
256 | |||
257 | 8 | private function decodeStr(int $length): string |
|
258 | { |
||
259 | 8 | if (0 === $length) { |
|
260 | 1 | return ''; |
|
261 | } |
||
262 | |||
263 | 7 | if (!isset($this->data[$this->offset + $length - 1])) { |
|
264 | 1 | throw InsufficientData::fromOffset($this->data, $this->offset, $length); |
|
265 | } |
||
266 | |||
267 | 6 | $str = substr($this->data, $this->offset++, $length); |
|
268 | 6 | $this->offset += $length; |
|
269 | |||
270 | 6 | return $str; |
|
271 | } |
||
272 | |||
273 | 5 | private function decodeArray(int $size): array |
|
274 | { |
||
275 | 5 | $array = []; |
|
276 | 5 | while ($size--) { |
|
277 | 4 | $array[] = $this->parse(); |
|
278 | } |
||
279 | |||
280 | 5 | return $array; |
|
281 | } |
||
282 | |||
283 | 5 | private function decodeMap(int $size): array |
|
284 | { |
||
285 | 5 | $map = []; |
|
286 | 5 | while ($size--) { |
|
287 | 5 | $map[$this->parse()] = $this->parse(); |
|
288 | } |
||
289 | |||
290 | 5 | return $map; |
|
291 | } |
||
292 | |||
293 | 14 | private function decodeExt(int $length): Ext |
|
294 | { |
||
295 | 14 | if (!isset($this->data[$this->offset + $length - 1])) { |
|
296 | 5 | throw InsufficientData::fromOffset($this->data, $this->offset, $length); |
|
297 | } |
||
298 | |||
299 | 9 | $type = ORD[$this->data[$this->offset++]]; |
|
300 | 9 | $data = substr($this->data, $this->offset++, $length); |
|
301 | |||
302 | 9 | $this->offset += $length; |
|
303 | |||
304 | 9 | return Ext::make($type, $data); |
|
305 | } |
||
306 | } |
||
307 |
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.