Completed
Push — master ( b27f98...c4b59d )
by Eugene
07:22
created

BufferUnpacker::unpackExtData()   B

Complexity

Conditions 4
Paths 5

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 4

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 23
ccs 12
cts 12
cp 1
rs 8.7972
cc 4
eloc 12
nc 5
nop 1
crap 4
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\UnpackingFailedException;
17
use MessagePack\TypeTransformer\Unpackable;
18
19
class BufferUnpacker
20
{
21
    private $buffer;
22
    private $offset = 0;
23
    private $isBigIntAsStr;
24
    private $isBigIntAsGmp;
25
26
    /**
27
     * @var Unpackable[]|null
28
     */
29
    private $transformers;
30
31
    /**
32
     * @param string $buffer
33
     * @param UnpackOptions|int|null $options
34
     *
35
     * @throws \MessagePack\Exception\InvalidOptionException
36
     */
37 233
    public function __construct(string $buffer = '', $options = null)
38
    {
39 233
        if (null === $options) {
40 232
            $options = UnpackOptions::fromDefaults();
41 8
        } elseif (!$options instanceof PackOptions) {
42 8
            $options = UnpackOptions::fromBitmask($options);
0 ignored issues
show
Bug introduced by
It seems like $options can also be of type object<MessagePack\UnpackOptions>; however, MessagePack\UnpackOptions::fromBitmask() does only seem to accept integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
43
        }
44
45 233
        $this->isBigIntAsStr = $options->isBigIntAsStrMode();
46 233
        $this->isBigIntAsGmp = $options->isBigIntAsGmpMode();
47
48 233
        $this->buffer = $buffer;
49 233
    }
50
51 1
    public function registerTransformer(Unpackable $transformer) : self
52
    {
53 1
        $this->transformers[$transformer->getType()] = $transformer;
54
55 1
        return $this;
56
    }
57
58 5
    public function append(string $data) : self
59
    {
60 5
        $this->buffer .= $data;
61
62 5
        return $this;
63
    }
64
65 211
    public function reset(string $buffer = '') : self
66
    {
67 211
        $this->buffer = $buffer;
68 211
        $this->offset = 0;
69
70 211
        return $this;
71
    }
72
73 1
    public function __clone()
74
    {
75 1
        $this->buffer = '';
76 1
        $this->offset = 0;
77 1
    }
78
79 3
    public function tryUnpack() : array
80
    {
81 3
        $data = [];
82 3
        $offset = $this->offset;
83
84
        try {
85
            do {
86 3
                $data[] = $this->unpack();
87 3
                $offset = $this->offset;
88 3
            } while (isset($this->buffer[$this->offset]));
89 1
        } catch (InsufficientDataException $e) {
90 1
            $this->offset = $offset;
91
        }
92
93 3
        if ($this->offset) {
94 3
            $this->buffer = isset($this->buffer[$this->offset]) ? \substr($this->buffer, $this->offset) : '';
95 3
            $this->offset = 0;
96
        }
97
98 3
        return $data;
99
    }
100
101 138
    public function unpack()
102
    {
103 138
        if (!isset($this->buffer[$this->offset])) {
104 5
            throw InsufficientDataException::unexpectedLength($this->buffer, $this->offset, 1);
105
        }
106
107 135
        $c = \ord($this->buffer[$this->offset]);
108 135
        ++$this->offset;
109
110
        // fixint
111 135
        if ($c <= 0x7f) {
112 31
            return $c;
113
        }
114
        // fixstr
115 128 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...
116 18
            return ($c & 0x1f) ? $this->unpackStrData($c & 0x1f) : '';
117
        }
118
        // fixarray
119 121
        if ($c >= 0x90 && $c <= 0x9f) {
120 8
            return ($c & 0xf) ? $this->unpackArrayData($c & 0xf) : [];
121
        }
122
        // fixmap
123 118
        if ($c >= 0x80 && $c <= 0x8f) {
124 13
            return ($c & 0xf) ? $this->unpackMapData($c & 0xf) : [];
125
        }
126
        // negfixint
127 114
        if ($c >= 0xe0) {
128 5
            return $c - 0x100;
129
        }
130
131 109
        switch ($c) {
132 109
            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...
133 108
            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...
134 105
            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...
135
136
            // bin
137 98
            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...
138 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...
139 92
            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...
140
141
            // float
142 91
            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...
143 88
            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...
144
145
            // uint
146 84
            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...
147 80
            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...
148 73
            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...
149 68
            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...
150
151
            // int
152 56
            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...
153 51
            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...
154 46
            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...
155 41
            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...
156
157
            // str
158 33
            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...
159 29
            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...
160 27
            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...
161
162
            // array
163 26
            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...
164 24
            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...
165
166
            // map
167 23
            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...
168 21
            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...
169
170
            // ext
171 20
            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...
172 17
            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...
173 15
            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...
174 13
            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...
175 11
            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...
176 9
            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...
177 5
            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...
178 3
            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...
179
        }
180
181 1
        throw UnpackingFailedException::unknownCode($c);
182
    }
183
184 3
    public function unpackNil()
185
    {
186 3
        if (!isset($this->buffer[$this->offset])) {
187 1
            throw InsufficientDataException::unexpectedLength($this->buffer, $this->offset, 1);
188
        }
189
190 2
        if ("\xc0" === $this->buffer[$this->offset]) {
191 1
            ++$this->offset;
192
193 1
            return null;
194
        }
195
196 1
        throw UnpackingFailedException::unexpectedCode(\ord($this->buffer[$this->offset++]), 'nil');
197
    }
198
199 4
    public function unpackBool()
200
    {
201 4
        if (!isset($this->buffer[$this->offset])) {
202 1
            throw InsufficientDataException::unexpectedLength($this->buffer, $this->offset, 1);
203
        }
204
205 3
        $c = \ord($this->buffer[$this->offset]);
206 3
        ++$this->offset;
207
208 3
        if (0xc2 === $c) {
209 1
            return false;
210
        }
211 2
        if (0xc3 === $c) {
212 1
            return true;
213
        }
214
215 1
        throw UnpackingFailedException::unexpectedCode($c, 'bool');
216
    }
217
218 40
    public function unpackInt()
219
    {
220 40
        if (!isset($this->buffer[$this->offset])) {
221 1
            throw InsufficientDataException::unexpectedLength($this->buffer, $this->offset, 1);
222
        }
223
224 39
        $c = \ord($this->buffer[$this->offset]);
225 39
        ++$this->offset;
226
227
        // fixint
228 39
        if ($c <= 0x7f) {
229 3
            return $c;
230
        }
231
        // negfixint
232 36
        if ($c >= 0xe0) {
233 3
            return $c - 0x100;
234
        }
235
236 33
        switch ($c) {
237
            // uint
238 33
            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...
239 30
            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...
240 27
            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...
241 24
            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...
242
243
            // int
244 20
            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...
245 16
            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...
246 12
            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...
247 8
            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...
248
        }
249
250 1
        throw UnpackingFailedException::unexpectedCode($c, 'int');
251
    }
252
253 7
    public function unpackFloat()
254
    {
255 7
        if (!isset($this->buffer[$this->offset])) {
256 1
            throw InsufficientDataException::unexpectedLength($this->buffer, $this->offset, 1);
257
        }
258
259 6
        $c = \ord($this->buffer[$this->offset]);
260 6
        ++$this->offset;
261
262 6
        if (0xcb === $c) {
263 3
            return $this->unpackFloat64();
264
        }
265 3
        if (0xca === $c) {
266 2
            return $this->unpackFloat32();
267
        }
268
269 1
        throw UnpackingFailedException::unexpectedCode($c, 'float');
270
    }
271
272 14
    public function unpackStr()
273
    {
274 14
        if (!isset($this->buffer[$this->offset])) {
275 1
            throw InsufficientDataException::unexpectedLength($this->buffer, $this->offset, 1);
276
        }
277
278 13
        $c = \ord($this->buffer[$this->offset]);
279 13
        ++$this->offset;
280
281 13 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...
282 5
            return ($c & 0x1f) ? $this->unpackStrData($c & 0x1f) : '';
283
        }
284 8
        if (0xd9 === $c) {
285 4
            return $this->unpackStrData($this->unpackUint8());
286
        }
287 4
        if (0xda === $c) {
288 2
            return $this->unpackStrData($this->unpackUint16());
289
        }
290 2
        if (0xdb === $c) {
291 1
            return $this->unpackStrData($this->unpackUint32());
292
        }
293
294 1
        throw UnpackingFailedException::unexpectedCode($c, 'str');
295
    }
296
297 7
    public function unpackBin()
298
    {
299 7
        if (!isset($this->buffer[$this->offset])) {
300 1
            throw InsufficientDataException::unexpectedLength($this->buffer, $this->offset, 1);
301
        }
302
303 6
        $c = \ord($this->buffer[$this->offset]);
304 6
        ++$this->offset;
305
306 6
        if (0xc4 === $c) {
307 3
            return $this->unpackStrData($this->unpackUint8());
308
        }
309 3
        if (0xc5 === $c) {
310 1
            return $this->unpackStrData($this->unpackUint16());
311
        }
312 2
        if (0xc6 === $c) {
313 1
            return $this->unpackStrData($this->unpackUint32());
314
        }
315
316 1
        throw UnpackingFailedException::unexpectedCode($c, 'bin');
317
    }
318
319 8
    public function unpackArray()
320
    {
321 8
        $size = $this->unpackArrayHeader();
322
323 6
        $array = [];
324 6
        while ($size--) {
325 5
            $array[] = $this->unpack();
326
        }
327
328 6
        return $array;
329
    }
330
331 8 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...
332
    {
333 8
        if (!isset($this->buffer[$this->offset])) {
334 1
            throw InsufficientDataException::unexpectedLength($this->buffer, $this->offset, 1);
335
        }
336
337 7
        $c = \ord($this->buffer[$this->offset]);
338 7
        ++$this->offset;
339
340 7
        if ($c >= 0x90 && $c <= 0x9f) {
341 3
            return $c & 0xf;
342
        }
343 4
        if (0xdc === $c) {
344 2
            return $this->unpackUint16();
345
        }
346 2
        if (0xdd === $c) {
347 1
            return $this->unpackUint32();
348
        }
349
350 1
        throw UnpackingFailedException::unexpectedCode($c, 'array header');
351
    }
352
353 13
    public function unpackMap()
354
    {
355 13
        $size = $this->unpackMapHeader();
356
357 11
        $map = [];
358 11
        while ($size--) {
359 10
            $map[$this->unpack()] = $this->unpack();
360
        }
361
362 11
        return $map;
363
    }
364
365 13 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...
366
    {
367 13
        if (!isset($this->buffer[$this->offset])) {
368 1
            throw InsufficientDataException::unexpectedLength($this->buffer, $this->offset, 1);
369
        }
370
371 12
        $c = \ord($this->buffer[$this->offset]);
372 12
        ++$this->offset;
373
374 12
        if ($c >= 0x80 && $c <= 0x8f) {
375 8
            return $c & 0xf;
376
        }
377 4
        if (0xde === $c) {
378 2
            return $this->unpackUint16();
379
        }
380 2
        if (0xdf === $c) {
381 1
            return $this->unpackUint32();
382
        }
383
384 1
        throw UnpackingFailedException::unexpectedCode($c, 'map header');
385
    }
386
387 10
    public function unpackExt()
388
    {
389 10
        if (!isset($this->buffer[$this->offset])) {
390 1
            throw InsufficientDataException::unexpectedLength($this->buffer, $this->offset, 1);
391
        }
392
393 9
        $c = \ord($this->buffer[$this->offset]);
394 9
        ++$this->offset;
395
396 9
        switch ($c) {
397 9
            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...
398 8
            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...
399 7
            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...
400 6
            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...
401 5
            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...
402 4
            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...
403 3
            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...
404 2
            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...
405
        }
406
407 1
        throw UnpackingFailedException::unexpectedCode($c, 'ext header');
408
    }
409
410 34
    private function unpackUint8()
411
    {
412 34
        if (!isset($this->buffer[$this->offset])) {
413 2
            throw InsufficientDataException::unexpectedLength($this->buffer, $this->offset, 1);
414
        }
415
416 32
        return \ord($this->buffer[$this->offset++]);
417
    }
418
419 28
    private function unpackUint16()
420
    {
421 28
        if (!isset($this->buffer[$this->offset + 1])) {
422 2
            throw InsufficientDataException::unexpectedLength($this->buffer, $this->offset, 2);
423
        }
424
425 26
        $hi = \ord($this->buffer[$this->offset]);
426 26
        $lo = \ord($this->buffer[++$this->offset]);
427 26
        ++$this->offset;
428
429 26
        return $hi << 8 | $lo;
430
    }
431
432 20
    private function unpackUint32()
433
    {
434 20
        if (!isset($this->buffer[$this->offset + 3])) {
435 2
            throw InsufficientDataException::unexpectedLength($this->buffer, $this->offset, 4);
436
        }
437
438 18
        $num = \unpack('N', $this->buffer, $this->offset)[1];
439 18
        $this->offset += 4;
440
441 18
        return $num;
442
    }
443
444 16 View Code Duplication
    private function unpackUint64()
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...
445
    {
446 16
        if (!isset($this->buffer[$this->offset + 7])) {
447 1
            throw InsufficientDataException::unexpectedLength($this->buffer, $this->offset, 8);
448
        }
449
450 15
        $num = \unpack('J', $this->buffer, $this->offset)[1];
451 15
        $this->offset += 8;
452
453 15
        return $num < 0 ? $this->handleIntOverflow($num) : $num;
454
    }
455
456 9
    private function unpackInt8()
457
    {
458 9
        if (!isset($this->buffer[$this->offset])) {
459 1
            throw InsufficientDataException::unexpectedLength($this->buffer, $this->offset, 1);
460
        }
461
462 8
        $num = \ord($this->buffer[$this->offset]);
463 8
        ++$this->offset;
464
465 8
        return $num > 0x7f ? $num - 0x100 : $num;
466
    }
467
468 9
    private function unpackInt16()
469
    {
470 9
        if (!isset($this->buffer[$this->offset + 1])) {
471 1
            throw InsufficientDataException::unexpectedLength($this->buffer, $this->offset, 2);
472
        }
473
474 8
        $hi = \ord($this->buffer[$this->offset]);
475 8
        $lo = \ord($this->buffer[++$this->offset]);
476 8
        ++$this->offset;
477
478 8
        return $hi > 0x7f ? $hi << 8 | $lo - 0x10000 : $hi << 8 | $lo;
479
    }
480
481 9 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...
482
    {
483 9
        if (!isset($this->buffer[$this->offset + 3])) {
484 1
            throw InsufficientDataException::unexpectedLength($this->buffer, $this->offset, 4);
485
        }
486
487 8
        $num = \unpack('N', $this->buffer, $this->offset)[1];
488 8
        $this->offset += 4;
489
490 8
        return $num > 0x7fffffff ? $num - 0x100000000 : $num;
491
    }
492
493 15
    private function unpackInt64()
494
    {
495 15
        if (!isset($this->buffer[$this->offset + 7])) {
496 1
            throw InsufficientDataException::unexpectedLength($this->buffer, $this->offset, 8);
497
        }
498
499 14
        $num = \unpack('J', $this->buffer, $this->offset)[1];
500 14
        $this->offset += 8;
501
502 14
        return $num;
503
    }
504
505 5
    private function unpackFloat32()
506
    {
507 5
        if (!isset($this->buffer[$this->offset + 3])) {
508 1
            throw InsufficientDataException::unexpectedLength($this->buffer, $this->offset, 4);
509
        }
510
511 4
        $num = \unpack('G', $this->buffer, $this->offset)[1];
512 4
        $this->offset += 4;
513
514 4
        return $num;
515
    }
516
517 7
    private function unpackFloat64()
518
    {
519 7
        if (!isset($this->buffer[$this->offset + 7])) {
520 1
            throw InsufficientDataException::unexpectedLength($this->buffer, $this->offset, 8);
521
        }
522
523 6
        $num = \unpack('E', $this->buffer, $this->offset)[1];
524 6
        $this->offset += 8;
525
526 6
        return $num;
527
    }
528
529 47
    private function unpackStrData($length)
530
    {
531 47
        if (!isset($this->buffer[$this->offset + $length - 1])) {
532 1
            throw InsufficientDataException::unexpectedLength($this->buffer, $this->offset, $length);
533
        }
534
535 47
        $str = \substr($this->buffer, $this->offset, $length);
536 47
        $this->offset += $length;
537
538 47
        return $str;
539
    }
540
541 10
    private function unpackArrayData($size)
542
    {
543 10
        $array = [];
544 10
        while ($size--) {
545 10
            $array[] = $this->unpack();
546
        }
547
548 10
        return $array;
549
    }
550
551 15
    private function unpackMapData($size)
552
    {
553 15
        $map = [];
554 15
        while ($size--) {
555 15
            $map[$this->unpack()] = $this->unpack();
556
        }
557
558 15
        return $map;
559
    }
560
561 24
    private function unpackExtData($length)
562
    {
563 24
        if (!isset($this->buffer[$this->offset + $length - 1])) {
564 5
            throw InsufficientDataException::unexpectedLength($this->buffer, $this->offset, $length);
565
        }
566
567
        // int8
568 19
        $type = \ord($this->buffer[$this->offset]);
569 19
        ++$this->offset;
570
571 19
        if ($type > 0x7f) {
572
            $type -= 0x100;
573 19
        }
574 1
575
        if (isset($this->transformers[$type])) {
576
            return $this->transformers[$type]->unpack($this, $length);
577 18
        }
578 18
579
        $data = \substr($this->buffer, $this->offset, $length);
580 18
        $this->offset += $length;
581
582
        return new Ext($type, $data);
583 5
    }
584
585 5
    private function handleIntOverflow($value)
586 3
    {
587
        if ($this->isBigIntAsStr) {
588 2
            return \sprintf('%u', $value);
589 1
        }
590
        if ($this->isBigIntAsGmp) {
591
            return \gmp_init(\sprintf('%u', $value));
592 1
        }
593
594
        throw new IntegerOverflowException($value);
595
    }
596
}
597