Skip to content

Commit cbc0fe8

Browse files
fixed unpacking structures
1 parent c934265 commit cbc0fe8

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed

Unpacker.php

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -65,38 +65,18 @@ private function next(int $length): string
6565
}
6666

6767
/**
68-
* @param bool $structures
6968
* @return mixed
7069
* @throws Exception
7170
*/
72-
private function u(bool $structures = true)
71+
private function u()
7372
{
7473
$marker = ord($this->next(1));
7574
$result = false;
7675

77-
if ($structures) {
78-
$output = $this->unpackStruct($marker, $result);
79-
if ($result) {
80-
return $output;
81-
}
82-
$output = $this->unpackNode($marker, $result);
83-
if ($result) {
84-
return $output;
85-
}
86-
$output = $this->unpackRelationship($marker, $result);
87-
if ($result) {
88-
return $output;
89-
}
90-
$output = $this->unpackPath($marker, $result);
91-
if ($result) {
92-
return $output;
93-
}
94-
$output = $this->unpackUnboundRelationship($marker, $result);
95-
if ($result) {
96-
return $output;
97-
}
76+
$output = $this->unpackStruct($marker, $result);
77+
if ($result) {
78+
return $output;
9879
}
99-
10080
$output = $this->unpackFloat($marker, $result);
10181
if ($result) {
10282
return $output;
@@ -140,8 +120,31 @@ private function unpackStruct(int $marker, bool &$result = false)
140120
$size = 0b10110000 ^ $marker;
141121
$result = true;
142122
}
123+
124+
if (!$result) {
125+
return null;
126+
}
127+
128+
$marker = ord($this->next(1));
129+
130+
$output = $this->unpackNode($marker, $result);
131+
if ($result) {
132+
return $output;
133+
}
134+
$output = $this->unpackRelationship($marker, $result);
135+
if ($result) {
136+
return $output;
137+
}
138+
$output = $this->unpackPath($marker, $result);
139+
if ($result) {
140+
return $output;
141+
}
142+
$output = $this->unpackUnboundRelationship($marker, $result);
143+
if ($result) {
144+
return $output;
145+
}
143146

144-
return $result ? $this->u() : null;
147+
return null;
145148
}
146149

147150
/**
@@ -310,7 +313,7 @@ private function unpackMap(int $marker, bool &$result = false): array
310313
$output = [];
311314
if ($size != -1) {
312315
for ($i = 0; $i < $size; $i++) {
313-
$output[$this->u(false)] = $this->u();
316+
$output[$this->u()] = $this->u();
314317
}
315318
$result = true;
316319
}

0 commit comments

Comments
 (0)