Completed
Push — master ( 2083f4...8ff655 )
by Eugene
08:52
created

BufferUnpacker::unpackStrData()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
ccs 0
cts 0
cp 0
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
crap 6
1
<?php
2
3
/*
4
 * This file is part of the rybakit/msgpack.php package.
5
 *
6
 * (c) Eugene Leonovich <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace MessagePack;
13
14
use MessagePack\Exception\InsufficientDataException;
15
use MessagePack\Exception\IntegerOverflowException;
16
use MessagePack\Exception\InvalidCodeException;
17
use MessagePack\Exception\InvalidOptionException;
18
use MessagePack\Exception\UnpackingFailedException;
19
use MessagePack\TypeTransformer\Extension;
20
21
class BufferUnpacker
22
{
23
    private $buffer;
24
    private $offset = 0;
25
    private $isBigIntAsStr;
26
    private $isBigIntAsGmp;
27
28
    /**
29
     * @var Extension[]|null
30
     */
31
    private $transformers;
32
33
    /**
34
     * @param string $buffer
35
     * @param UnpackOptions|int|null $options
36
     *
37
     * @throws InvalidOptionException
38 123
     */
39
    public function __construct($buffer = '', $options = null)
40 123
    {
41 123
        if (!$options instanceof UnpackOptions) {
42
            $options = UnpackOptions::fromBitmask($options);
43
        }
44 123
45 123
        $this->isBigIntAsStr = $options->isBigIntAsStrMode();
46
        $this->isBigIntAsGmp = $options->isBigIntAsGmpMode();
47 123
48 123
        $this->buffer = $buffer;
49
    }
50
51
    public function registerTransformer(Extension $ext)
52
    {
53 2
        $this->transformers[$ext->getType()] = $ext;
54
    }
55 2
56 2
    /**
57
     * @param string $data
58
     *
59
     * @return $this
60
     */
61 1
    public function append($data)
62
    {
63 1
        $this->buffer .= $data;
64
65
        return $this;
66
    }
67
68
    /**
69
     * @param string $buffer
70
     *
71 5
     * @return $this
72
     */
73 5
    public function reset($buffer = '')
74
    {
75 5
        $this->buffer = $buffer;
76
        $this->offset = 0;
77
78
        return $this;
79
    }
80
81
    public function __clone()
82
    {
83 109
        $this->buffer = '';
84
        $this->offset = 0;
85 109
    }
86 109
87
    /**
88 109
     * @return array
89
     */
90
    public function tryUnpack()
91
    {
92
        $data = [];
93
        $offset = $this->offset;
94 3
95
        try {
96 3
            do {
97 3
                $data[] = $this->unpack();
98
                $offset = $this->offset;
99
            } while (isset($this->buffer[$this->offset]));
100
        } catch (InsufficientDataException $e) {
101 3
            $this->offset = $offset;
102 3
        }
103 3
104 1
        if ($this->offset) {
105 1
            $this->buffer = isset($this->buffer[$this->offset]) ? \substr($this->buffer, $this->offset) : '';
106
            $this->offset = 0;
107
        }
108 3
109 3
        return $data;
110 3
    }
111
112
    /**
113 3
     * @throws UnpackingFailedException
114
     *
115
     * @return mixed
116
     */
117
    public function unpack()
118
    {
119
        if (!isset($this->buffer[$this->offset])) {
120
            throw InsufficientDataException::fromOffset($this->buffer, $this->offset, 1);
121 118
        }
122
123 118
        $c = \ord($this->buffer[$this->offset]);
124 4
        ++$this->offset;
125
126
        // fixint
127 116
        if ($c <= 0x7f) {
128 116
            return $c;
129
        }
130
        // fixstr
131 116 View Code Duplication
        if ($c >= 0xa0 && $c <= 0xbf) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
132 20
            return ($c & 0x1f) ? $this->unpackStrData($c & 0x1f) : '';
133
        }
134
        // fixarray
135 113
        if ($c >= 0x90 && $c <= 0x9f) {
136 13
            return ($c & 0xf) ? $this->unpackArrayData($c & 0xf) : [];
137
        }
138
        // fixmap
139 107
        if ($c >= 0x80 && $c <= 0x8f) {
140 6
            return ($c & 0xf) ? $this->unpackMapData($c & 0xf) : [];
141
        }
142
        // negfixint
143 104
        if ($c >= 0xe0) {
144 11
            return $c - 256;
145
        }
146
147 100
        switch ($c) {
148 4
            case 0xc0: return null;
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
149
            case 0xc2: return false;
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
150
            case 0xc3: return true;
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
151 96
152 96
            // MP_BIN
153 95
            case 0xc4: return $this->unpackStrData($this->unpackUint8());
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
154 93
            case 0xc5: return $this->unpackStrData($this->unpackUint16());
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
155
            case 0xc6: return $this->unpackStrData($this->unpackUint32());
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
156
157 88
            // MP_FLOAT
158 84
            case 0xca: return $this->unpackFloat32();
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
159 83
            case 0xcb: return $this->unpackFloat64();
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
160
161
            // MP_UINT
162 82
            case 0xcc: return $this->unpackUint8();
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
163 79
            case 0xcd: return $this->unpackUint16();
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
164
            case 0xce: return $this->unpackUint32();
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
165
            case 0xcf: return $this->unpackUint64();
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
166 75
167 71
            // MP_INT
168 66
            case 0xd0: return $this->unpackInt8();
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
169 62
            case 0xd1: return $this->unpackInt16();
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
170
            case 0xd2: return $this->unpackInt32();
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
171
            case 0xd3: return $this->unpackInt64();
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
172 52
173 47
            // MP_STR
174 42
            case 0xd9: return $this->unpackStrData($this->unpackUint8());
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
175 37
            case 0xda: return $this->unpackStrData($this->unpackUint16());
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
176
            case 0xdb: return $this->unpackStrData($this->unpackUint32());
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
177
178 32
            // MP_ARRAY
179 28
            case 0xdc: return $this->unpackArrayData($this->unpackUint16());
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
180 26
            case 0xdd: return $this->unpackArrayData($this->unpackUint32());
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
181
182
            // MP_MAP
183 25
            case 0xde: return $this->unpackMapData($this->unpackUint16());
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
184 23
            case 0xdf: return $this->unpackMapData($this->unpackUint32());
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
185
186
            // MP_EXT
187 22
            case 0xd4: return $this->unpackExtData(1);
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
188 20
            case 0xd5: return $this->unpackExtData(2);
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
189
            case 0xd6: return $this->unpackExtData(4);
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
190
            case 0xd7: return $this->unpackExtData(8);
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
191 19
            case 0xd8: return $this->unpackExtData(16);
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
192 16
            case 0xc7: return $this->unpackExtData($this->unpackUint8());
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
193 14
            case 0xc8: return $this->unpackExtData($this->unpackUint16());
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
194 12
            case 0xc9: return $this->unpackExtData($this->unpackUint32());
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
195 10
        }
196 8
197 5
        throw InvalidCodeException::fromUnknownCode($c);
198 3
    }
199
200
    public function unpackNil()
201 1
    {
202
        if (!isset($this->buffer[$this->offset])) {
203
            throw InsufficientDataException::fromOffset($this->buffer, $this->offset, 1);
204 18
        }
205
206 18
        if (0xc0 === \ord($this->buffer[$this->offset++])) {
207 2
            return null;
208
        }
209
210 16
        throw InvalidCodeException::fromExpectedType('nil', \ord($this->buffer[$this->offset - 1]));
211 16
    }
212
213 16
    public function unpackBool()
214
    {
215
        if (!isset($this->buffer[$this->offset])) {
216 15
            throw InsufficientDataException::fromOffset($this->buffer, $this->offset, 1);
217
        }
218 15
219 2
        $c = \ord($this->buffer[$this->offset++]);
220
221
        if (0xc2 === $c) {
222 13
            return false;
223 13
        }
224 13
        if (0xc3 === $c) {
225
            return true;
226 13
        }
227
228
        throw InvalidCodeException::fromExpectedType('bool', $c);
229 11
    }
230
231 11
    public function unpackInt()
232 2
    {
233
        if (!isset($this->buffer[$this->offset])) {
234
            throw InsufficientDataException::fromOffset($this->buffer, $this->offset, 1);
235 9
        }
236 9
237
        $c = \ord($this->buffer[$this->offset++]);
238 9
239
        // fixint
240 9
        if ($c <= 0x7f) {
241
            return $c;
242
        }
243 10
        // negfixint
244
        if ($c >= 0xe0) {
245 10
            return $c - 256;
246 1
        }
247
248
        switch ($c) {
249 9
            // MP_UINT
250 9
            case 0xcc: return $this->unpackUint8();
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
251
            case 0xcd: return $this->unpackUint16();
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
252
            case 0xce: return $this->unpackUint32();
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
253
            case 0xcf: return $this->unpackUint64();
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
254 9
255 9
            // MP_INT
256
            case 0xd0: return $this->unpackInt8();
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
257
            case 0xd1: return $this->unpackInt16();
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
258
            case 0xd2: return $this->unpackInt32();
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
259
            case 0xd3: return $this->unpackInt64();
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
260
        }
261 9
262
        throw InvalidCodeException::fromExpectedType('int', $c);
263
    }
264 15
265
    public function unpackFloat()
266 15
    {
267 1
        if (!isset($this->buffer[$this->offset])) {
268
            throw InsufficientDataException::fromOffset($this->buffer, $this->offset, 1);
269
        }
270 14
271 14
        $c = \ord($this->buffer[$this->offset++]);
272
273 14
        if (0xcb === $c) {
274 3
            return $this->unpackFloat64();
275
        }
276
        if (0xca === $c) {
277 11
            return $this->unpackFloat32();
278
        }
279
280 5
        throw InvalidCodeException::fromExpectedType('float', $c);
281
    }
282 5
283 1
    public function unpackStr()
284
    {
285
        if (!isset($this->buffer[$this->offset])) {
286 4
            throw InsufficientDataException::fromOffset($this->buffer, $this->offset, 1);
287 4
        }
288 4
289
        $c = \ord($this->buffer[$this->offset++]);
290 4
291 3 View Code Duplication
        if ($c >= 0xa0 && $c <= 0xbf) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
292
            return ($c & 0x1f) ? $this->unpackStrData($c & 0x1f) : '';
293
        }
294 1
        if (0xd9 === $c) {
295
            return $this->unpackStrData($this->unpackUint8());
296
        }
297 5
        if (0xda === $c) {
298
            return $this->unpackStrData($this->unpackUint16());
299 5
        }
300 1
        if (0xdb === $c) {
301
            return $this->unpackStrData($this->unpackUint32());
302
        }
303 4
304 4
        throw InvalidCodeException::fromExpectedType('str', $c);
305
    }
306 4
307
    public function unpackBin()
308 4
    {
309
        if (!isset($this->buffer[$this->offset])) {
310
            throw InsufficientDataException::fromOffset($this->buffer, $this->offset, 1);
311 5
        }
312
313 5
        $c = \ord($this->buffer[$this->offset++]);
314 1
315
        if (0xc4 === $c) {
316
            return $this->unpackStrData($this->unpackUint8());
317 4
        }
318 4
        if (0xc5 === $c) {
319
            return $this->unpackStrData($this->unpackUint16());
320 4
        }
321
        if (0xc6 === $c) {
322 4
            return $this->unpackStrData($this->unpackUint32());
323
        }
324
325 3
        throw InvalidCodeException::fromExpectedType('bin', $c);
326
    }
327 3
328 1
    public function unpackArray()
329
    {
330
        $size = $this->unpackArrayHeader();
331 2
332 2
        $array = [];
333
        while ($size--) {
334 2
            $array[] = $this->unpack();
335
        }
336 2
337
        return $array;
338
    }
339 4
340 View Code Duplication
    public function unpackArrayHeader()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
341 4
    {
342 1
        if (!isset($this->buffer[$this->offset])) {
343
            throw InsufficientDataException::fromOffset($this->buffer, $this->offset, 1);
344
        }
345 3
346 3
        $c = \ord($this->buffer[$this->offset++]);
347
348 3
        if ($c >= 0x90 && $c <= 0x9f) {
349
            return $c & 0xf;
350 3
        }
351
        if (0xdc === $c) {
352
            return $this->unpackUint16();
353 25
        }
354
        if (0xdd === $c) {
355 25
            return $this->unpackUint32();
356 1
        }
357
358
        throw InvalidCodeException::fromExpectedType('array header', $c);
359 25
    }
360 25
361
    public function unpackMap()
362 25
    {
363
        $size = $this->unpackMapHeader();
364
365 8
        $map = [];
366
        while ($size--) {
367 8
            $map[$this->unpack()] = $this->unpack();
368 8
        }
369 8
370
        return $map;
371
    }
372 8
373 View Code Duplication
    public function unpackMapHeader()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
374
    {
375 13
        if (!isset($this->buffer[$this->offset])) {
376
            throw InsufficientDataException::fromOffset($this->buffer, $this->offset, 1);
377 13
        }
378 13
379 13
        $c = \ord($this->buffer[$this->offset++]);
380
381
        if ($c >= 0x80 && $c <= 0x8f) {
382 13
            return $c & 0xf;
383
        }
384
        if (0xde === $c) {
385 15
            return $this->unpackUint16();
386
        }
387 15
        if (0xdf === $c) {
388 5
            return $this->unpackUint32();
389
        }
390
391 10
        throw InvalidCodeException::fromExpectedType('map header', $c);
392
    }
393 10
394 1
    public function unpackExt()
395
    {
396
        if (!isset($this->buffer[$this->offset])) {
397 9
            throw InsufficientDataException::fromOffset($this->buffer, $this->offset, 1);
398 9
        }
399
400 9
        $c = \ord($this->buffer[$this->offset++]);
401
402
        switch ($c) {
403 5
            case 0xd4: return $this->unpackExtData(1);
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
404
            case 0xd5: return $this->unpackExtData(2);
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
405 5
            case 0xd6: return $this->unpackExtData(4);
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
406 3
            case 0xd7: return $this->unpackExtData(8);
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
407
            case 0xd8: return $this->unpackExtData(16);
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
408 2
            case 0xc7: return $this->unpackExtData($this->unpackUint8());
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
409 1
            case 0xc8: return $this->unpackExtData($this->unpackUint16());
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
410
            case 0xc9: return $this->unpackExtData($this->unpackUint32());
0 ignored issues
show
Coding Style introduced by
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.

Loading history...
Coding Style introduced by
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

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.

Loading history...
411
        }
412 1
413
        throw InvalidCodeException::fromExpectedType('ext header', $c);
414
    }
415
416
    private function unpackUint8()
417
    {
418
        if (!isset($this->buffer[$this->offset])) {
419
            throw InsufficientDataException::fromOffset($this->buffer, $this->offset, 1);
420
        }
421
422
        return \ord($this->buffer[$this->offset++]);
423
    }
424
425
    private function unpackUint16()
426
    {
427
        if (!isset($this->buffer[$this->offset + 1])) {
428
            throw InsufficientDataException::fromOffset($this->buffer, $this->offset, 2);
429
        }
430
431
        $hi = \ord($this->buffer[$this->offset]);
432
        $lo = \ord($this->buffer[$this->offset + 1]);
433
        $this->offset += 2;
434
435
        return $hi << 8 | $lo;
436
    }
437
438 View Code Duplication
    private function unpackUint32()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
439
    {
440
        if (!isset($this->buffer[$this->offset + 3])) {
441
            throw InsufficientDataException::fromOffset($this->buffer, $this->offset, 4);
442
        }
443
444
        $num = \substr($this->buffer, $this->offset, 4);
445
        $this->offset += 4;
446
447
        $num = \unpack('N', $num);
448
449
        return $num[1];
450
    }
451
452
    private function unpackUint64()
453
    {
454
        if (!isset($this->buffer[$this->offset + 7])) {
455
            throw InsufficientDataException::fromOffset($this->buffer, $this->offset, 8);
456
        }
457
458
        $num = \substr($this->buffer, $this->offset, 8);
459
        $this->offset += 8;
460
461
        //$num = \unpack('J', $num);
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
462
463
        $set = \unpack('N2', $num);
464
        $value = $set[1] << 32 | $set[2];
465
466
        // PHP does not support unsigned integers.
467
        // If a number is bigger than 2^63, it will be interpreted as a float.
468
        // @link http://php.net/manual/en/language.types.integer.php#language.types.integer.overflow
469
470
        return $value < 0 ? $this->handleIntOverflow($value) : $value;
471
    }
472
473
    private function unpackInt8()
474
    {
475
        if (!isset($this->buffer[$this->offset])) {
476
            throw InsufficientDataException::fromOffset($this->buffer, $this->offset, 1);
477
        }
478
479
        $num = \ord($this->buffer[$this->offset]);
480
        ++$this->offset;
481
482
        return $num > 0x7f ? $num - 256 : $num;
483
    }
484
485
    private function unpackInt16()
486
    {
487
        if (!isset($this->buffer[$this->offset + 1])) {
488
            throw InsufficientDataException::fromOffset($this->buffer, $this->offset, 2);
489
        }
490
491
        $hi = \ord($this->buffer[$this->offset]);
492
        $lo = \ord($this->buffer[$this->offset + 1]);
493
        $this->offset += 2;
494
495
        if ($hi > 0x7f) {
496
            return -(0x010000 - ($hi << 8 | $lo));
497
        }
498
499
        return $hi << 8 | $lo;
500
    }
501
502 View Code Duplication
    private function unpackInt32()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
503
    {
504
        if (!isset($this->buffer[$this->offset + 3])) {
505
            throw InsufficientDataException::fromOffset($this->buffer, $this->offset, 4);
506
        }
507
508
        $num = \substr($this->buffer, $this->offset, 4);
509
        $this->offset += 4;
510
511
        $num = \unpack('i', \strrev($num));
512
513
        return $num[1];
514
    }
515
516 View Code Duplication
    private function unpackInt64()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
517
    {
518
        if (!isset($this->buffer[$this->offset + 7])) {
519
            throw InsufficientDataException::fromOffset($this->buffer, $this->offset, 8);
520
        }
521
522
        $num = \substr($this->buffer, $this->offset, 8);
523
        $this->offset += 8;
524
525
        $set = \unpack('N2', $num);
526
527
        return $set[1] << 32 | $set[2];
528
    }
529
530 View Code Duplication
    private function unpackFloat32()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
531
    {
532
        if (!isset($this->buffer[$this->offset + 3])) {
533
            throw InsufficientDataException::fromOffset($this->buffer, $this->offset, 4);
534
        }
535
536
        $num = \substr($this->buffer, $this->offset, 4);
537
        $this->offset += 4;
538
539
        $num = \unpack('f', \strrev($num));
540
541
        return $num[1];
542
    }
543
544 View Code Duplication
    private function unpackFloat64()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
545
    {
546
        if (!isset($this->buffer[$this->offset + 7])) {
547
            throw InsufficientDataException::fromOffset($this->buffer, $this->offset, 8);
548
        }
549
550
        $num = \substr($this->buffer, $this->offset, 8);
551
        $this->offset += 8;
552
553
        $num = \unpack('d', \strrev($num));
554
555
        return $num[1];
556
    }
557
558
    private function unpackStrData($length)
559
    {
560
        if (!isset($this->buffer[$this->offset + $length - 1])) {
561
            throw InsufficientDataException::fromOffset($this->buffer, $this->offset, $length);
562
        }
563
564
        $str = \substr($this->buffer, $this->offset, $length);
565
        $this->offset += $length;
566
567
        return $str;
568
    }
569
570
    private function unpackArrayData($size)
571
    {
572
        $array = [];
573
        while ($size--) {
574
            $array[] = $this->unpack();
575
        }
576
577
        return $array;
578
    }
579
580
    private function unpackMapData($size)
581
    {
582
        $map = [];
583
        while ($size--) {
584
            $map[$this->unpack()] = $this->unpack();
585
        }
586
587
        return $map;
588
    }
589
590
    private function unpackExtData($length)
591
    {
592
        if (!isset($this->buffer[$this->offset + $length - 1])) {
593
            throw InsufficientDataException::fromOffset($this->buffer, $this->offset, $length);
594
        }
595
596
        // int8
597
        $num = \ord($this->buffer[$this->offset]);
598
        ++$this->offset;
599
600
        $type = $num > 0x7f ? $num - 256 : $num;
601
602
        if (isset($this->transformers[$type])) {
603
            return $this->transformers[$type]->unpack($this, $length);
604
        }
605
606
        $data = \substr($this->buffer, $this->offset, $length);
607
        $this->offset += $length;
608
609
        return new Ext($type, $data);
610
    }
611
612
    private function handleIntOverflow($value)
613
    {
614
        if ($this->isBigIntAsStr) {
615
            return \sprintf('%u', $value);
616
        }
617
        if ($this->isBigIntAsGmp) {
618
            return \gmp_init(\sprintf('%u', $value));
619
        }
620
621
        throw new IntegerOverflowException($value);
622
    }
623
}
624