Skip to content

Commit 383ee61

Browse files
committed
fixed internal typing issues
1 parent 9aeb94a commit 383ee61

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

src/Formatter/OGMFormatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
* @psalm-import-type MetaArray from \Laudis\Neo4j\Formatter\Specialised\HttpOGMArrayTranslator
4444
* @psalm-import-type RelationshipArray from \Laudis\Neo4j\Formatter\Specialised\HttpOGMArrayTranslator
4545
*
46-
* @psalm-type CypherResultDataRow = list<array{row: list<scalar|array|null>, meta: list<MetaArray>, graph: array{nodes: list<NodeArray>, relationships: list<RelationshipArray>}}>
46+
* @psalm-type CypherResultDataRow = list<array{row: list<scalar|array|null>, meta: MetaArray, graph: array{nodes: list<NodeArray>, relationships: list<RelationshipArray>}}>
4747
* @psalm-type CypherResult = array{columns: list<string>, data: CypherResultDataRow}
4848
*
4949
* @psalm-import-type BoltMeta from \Laudis\Neo4j\Contracts\FormatterInterface

src/Formatter/Specialised/HttpOGMArrayTranslator.php

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@
2525
use Laudis\Neo4j\Types\UnboundRelationship;
2626
use Laudis\Neo4j\Types\WGS843DPoint;
2727
use Laudis\Neo4j\Types\WGS84Point;
28+
use RuntimeException;
2829

2930
/**
3031
* Maps the arrays to their respective values.
3132
*
32-
* @psalm-type RelationshipArray = array{id: string, type: string, startNode: string, endNode: string, properties?: array<string, scalar|null|array<array-key, scalar|null|array>>}
33+
* @psalm-type RelationshipArray = array{id: string, type: string, startNode: string, endNode: string, properties: array<string, scalar|null|array<array-key, scalar|null|array>>}
3334
* @psalm-type NodeArray = array{id: string, labels: list<string>, properties: array<string, scalar|null|array}
34-
* @psalm-type MetaArray = null|array{id?: int, type: string, deleted?: bool}
35+
* @psalm-type Meta = array{id?: int, type: string, deleted?: bool}
36+
* @psalm-type MetaArray = list<Meta|null|list<array{id: int, type: string, deleted: bool}>>
3537
*
3638
* @psalm-import-type OGMTypes from \Laudis\Neo4j\Formatter\OGMFormatter
3739
*
@@ -94,10 +96,10 @@ private function translateCypherList(array $value): CypherList
9496

9597
/**
9698
* @param list<RelationshipArray> $relationships
97-
* @param list<MetaArray|null> $meta
99+
* @param MetaArray $meta
98100
* @param list<NodeArray> $nodes
99101
*
100-
* @return array{0: int, 1: int, 2:Cartesian3DPoint|CartesianPoint|CypherList|CypherMap|Node|Relationship|WGS843DPoint|WGS84Point}
102+
* @return array{0: int, 1: int, 2:Cartesian3DPoint|CartesianPoint|CypherList|CypherMap|Node|Relationship|WGS843DPoint|WGS84Point|Path}
101103
*/
102104
public function translate(array $meta, array $relationships, int $metaIndex, int $relationshipIndex, array $nodes, array $value): array
103105
{
@@ -112,6 +114,11 @@ public function translate(array $meta, array $relationships, int $metaIndex, int
112114
++$relationshipIncrease;
113115
break;
114116
case 'path':
117+
/**
118+
* @psalm-suppress UnnecessaryVarAnnotation False positive
119+
*
120+
* @var list<array{id: int, type: string, deleted: bool}> $currentMeta
121+
*/
115122
[$path, $relIncrease] = $this->path($currentMeta, $nodes, $relationships, $relationshipIndex);
116123
$relationshipIncrease += $relIncrease;
117124
$tbr = $path;
@@ -120,20 +127,31 @@ public function translate(array $meta, array $relationships, int $metaIndex, int
120127
$tbr = $this->translatePoint($value);
121128
break;
122129
default:
123-
/** @var array<array-key, array|scalar|null> $value */
124-
$tbr = $this->translateContainer($value);
125130
if ($type === 'node' && isset($currentMeta['id'])) {
126-
$tbr = $this->translateNode($nodes, $currentMeta['id']);
131+
/** @var int $id */
132+
$id = $currentMeta['id'];
133+
$tbr = $this->translateNode($nodes, $id);
134+
} else {
135+
/** @var array<array-key, array|scalar|null> $value */
136+
$tbr = $this->translateContainer($value);
127137
}
128138
break;
129139
}
130140

131141
return [$metaIncrease, $relationshipIncrease, $tbr];
132142
}
133143

144+
/**
145+
* @param list<array{id: int, type: string, deleted: bool}> $meta
146+
* @param list<NodeArray> $nodes
147+
* @param list<RelationshipArray> $relationships
148+
*
149+
* @return array{0: Path, 1: int}
150+
*/
134151
private function path(array $meta, array $nodes, array $relationships, int $relIndex): array
135152
{
136153
$nodesTbr = [];
154+
/** @var list<int> $ids */
137155
$ids = [];
138156
$rels = [];
139157
$relIncrease = 0;
@@ -142,7 +160,8 @@ private function path(array $meta, array $nodes, array $relationships, int $relI
142160
$rel = $relationships[$relIndex];
143161
++$relIndex;
144162
++$relIncrease;
145-
$rels[] = new UnboundRelationship((int) $rel['id'], $rel['type'], new CypherMap($rel['properties']));
163+
$props = $this->translateCypherMap($rel['properties']);
164+
$rels[] = new UnboundRelationship((int) $rel['id'], $rel['type'], $props);
146165
} else {
147166
$nodesTbr[] = $this->translateNode($nodes, $nodeOrRel['id']);
148167
}
@@ -157,18 +176,13 @@ private function path(array $meta, array $nodes, array $relationships, int $relI
157176
*/
158177
private function translateNode(array $nodes, int $id): Node
159178
{
160-
/** @var list<string> */
161-
$labels = [];
162-
$props = [];
163179
foreach ($nodes as $node) {
164180
if ((int) $node['id'] === $id) {
165-
$labels = $node['labels'];
166-
$props = $node['properties'];
167-
break;
181+
return new Node($id, new CypherList($node['labels']), $this->translateCypherMap($node['properties']));
168182
}
169183
}
170184

171-
return new Node($id, new CypherList($labels), new CypherMap($props));
185+
throw new RuntimeException('Error when translating node: Cannot find node with id: '.$id);
172186
}
173187

174188
/**

src/Formatter/Specialised/HttpOGMStringTranslator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
final class HttpOGMStringTranslator
4040
{
4141
/**
42-
* @param list<MetaArray> $meta
42+
* @param MetaArray $meta
4343
*
4444
* @throws Exception
4545
*

0 commit comments

Comments
 (0)