Completed
Pull Request — master (#26)
by
unknown
04:27
created

BufferUnpacker::unpackArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

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