24
24
use function is_array ;
25
25
use function is_object ;
26
26
use Laudis \Neo4j \Contracts \FormatterInterface ;
27
+ use Laudis \Neo4j \Types \CypherList ;
28
+ use Laudis \Neo4j \Types \CypherMap ;
27
29
use Psr \Http \Message \RequestInterface ;
28
30
use Psr \Http \Message \ResponseInterface ;
29
31
use UnexpectedValueException ;
33
35
* @psalm-import-type CypherRowResponse from \Laudis\Neo4j\Contracts\FormatterInterface
34
36
* @psalm-import-type CypherResponse from \Laudis\Neo4j\Contracts\FormatterInterface
35
37
* @psalm-import-type CypherResponseSet from \Laudis\Neo4j\Contracts\FormatterInterface
36
- * @implements FormatterInterface<Vector<Map<string, scalar|array|null>>>
38
+ *
39
+ * @psalm-type BasicResults = CypherList<CypherMap<scalar|array|null>>
40
+ *
41
+ * @implements FormatterInterface<BasicResults>
37
42
*/
38
43
final class BasicFormatter implements FormatterInterface
39
44
{
40
45
/**
41
46
* @param array{fields: array<int, string>} $meta
42
47
* @param array<array-key, array> $results
43
48
*
44
- * @return Vector<Map<string, scalar| array|null>>
49
+ * @return CypherList<CypherMap< array|scalar |null>>
45
50
*/
46
- public function formatBoltResult (array $ meta , array $ results , Bolt $ bolt ): Vector
51
+ public function formatBoltResult (array $ meta , array $ results , Bolt $ bolt ): CypherList
47
52
{
48
53
$ results = array_slice ($ results , 0 , count ($ results ) - 1 );
49
54
55
+ /** @var Vector<CypherMap<scalar|array|null>> */
50
56
$ tbr = new Vector ();
51
57
foreach ($ results as $ result ) {
52
58
$ tbr ->push ($ this ->formatRow ($ meta , $ result ));
53
59
}
54
60
55
- return $ tbr ;
61
+ return new CypherList ( $ tbr) ;
56
62
}
57
63
58
- public function formatHttpResult (ResponseInterface $ response , array $ body ): Vector
64
+ public function formatHttpResult (ResponseInterface $ response , array $ body ): CypherList
59
65
{
66
+ /** @var Vector<CypherList<CypherMap<scalar|array|null>>> */
60
67
$ tbr = new Vector ();
61
68
62
69
foreach ($ body ['results ' ] as $ results ) {
63
70
$ tbr ->push ($ this ->buildResult ($ results ));
64
71
}
65
72
66
- return $ tbr ;
73
+ return new CypherList ( $ tbr) ;
67
74
}
68
75
69
76
/**
70
77
* @psalm-param CypherResponse $result
71
78
*
72
- * @return Vector<Map<string, scalar|array|null>>
79
+ * @return CypherList<CypherMap< scalar|array|null>>
73
80
*/
74
- private function buildResult (array $ result ): Vector
81
+ private function buildResult (array $ result ): CypherList
75
82
{
83
+ /** @psalm-var Vector<CypherMap<null|scalar|array>> */
76
84
$ tbr = new Vector ();
77
85
78
86
$ columns = $ result ['columns ' ];
@@ -84,26 +92,26 @@ private function buildResult(array $result): Vector
84
92
foreach ($ columns as $ index => $ key ) {
85
93
$ map ->put ($ key , $ vector ->get ($ index ));
86
94
}
87
- $ tbr ->push ($ map );
95
+ $ tbr ->push (new CypherMap ( $ map) );
88
96
}
89
97
90
- return $ tbr ;
98
+ return new CypherList ( $ tbr) ;
91
99
}
92
100
93
101
/**
94
102
* @param array{fields: array<int, string>} $meta
95
103
*
96
- * @return Map<string, scalar|array|null>
104
+ * @return CypherMap< scalar|array|null>
97
105
*/
98
- private function formatRow (array $ meta , array $ result ): Map
106
+ private function formatRow (array $ meta , array $ result ): CypherMap
99
107
{
100
108
/** @var Map<string, scalar|array|null> $map */
101
109
$ map = new Map ();
102
110
foreach ($ meta ['fields ' ] as $ i => $ column ) {
103
111
$ map ->put ($ column , $ this ->mapValue ($ result [$ i ]));
104
112
}
105
113
106
- return $ map ;
114
+ return new CypherMap ( $ map) ;
107
115
}
108
116
109
117
private function mapPath (Path $ path ): array
0 commit comments