Skip to content

Commit 123697f

Browse files
committed
extracted map from cyphermap
1 parent 9bac7aa commit 123697f

File tree

4 files changed

+547
-437
lines changed

4 files changed

+547
-437
lines changed

src/Types/ArrayList.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Laudis\Neo4j\Exception\RuntimeTypeException;
2121
use Laudis\Neo4j\TypeCaster;
2222
use OutOfBoundsException;
23+
use function is_iterable;
2324
use function sort;
2425
use function usort;
2526

@@ -224,30 +225,28 @@ public function getAsObject(int $key, string $class): object
224225
}
225226

226227
/**
227-
* @return CypherMap<mixed>
228+
* @return Map<mixed>
228229
*/
229-
public function getAsCypherMap(int $key): CypherMap
230+
public function getAsMap(int $key): Map
230231
{
231232
$value = $this->get($key);
232-
$tbr = TypeCaster::toCypherMap($value);
233-
if ($tbr === null) {
234-
throw new RuntimeTypeException($value, CypherMap::class);
233+
if (!is_iterable($value)) {
234+
throw new RuntimeTypeException($value, Map::class);
235235
}
236236

237-
return $tbr;
237+
return Map::fromIterable($value);
238238
}
239239

240240
/**
241-
* @return CypherList<mixed>
241+
* @return ArrayList<mixed>
242242
*/
243-
public function getAsCypherList(int $key): CypherList
243+
public function getAsArrayList(int $key): ArrayList
244244
{
245245
$value = $this->get($key);
246-
$tbr = TypeCaster::toCypherList($value);
247-
if ($tbr === null) {
248-
throw new RuntimeTypeException($value, CypherList::class);
246+
if (!is_iterable($value)) {
247+
throw new RuntimeTypeException($value, ArrayList::class);
249248
}
250249

251-
return $tbr;
250+
return ArrayList::fromIterable($value);
252251
}
253252
}

src/Types/CypherList.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,34 @@
3434
*/
3535
final class CypherList extends ArrayList
3636
{
37+
/**
38+
* @return CypherMap<mixed>
39+
*/
40+
public function getAsCypherMap(int $key): CypherMap
41+
{
42+
$value = $this->get($key);
43+
$tbr = TypeCaster::toCypherMap($value);
44+
if ($tbr === null) {
45+
throw new RuntimeTypeException($value, CypherMap::class);
46+
}
47+
48+
return $tbr;
49+
}
50+
51+
/**
52+
* @return CypherList<mixed>
53+
*/
54+
public function getAsCypherList(int $key): CypherList
55+
{
56+
$value = $this->get($key);
57+
$tbr = TypeCaster::toCypherList($value);
58+
if ($tbr === null) {
59+
throw new RuntimeTypeException($value, CypherList::class);
60+
}
61+
62+
return $tbr;
63+
}
64+
3765
public function getAsDate(int $key): Date
3866
{
3967
return $this->getAsObject($key, Date::class);

0 commit comments

Comments
 (0)