2424use function is_array ;
2525use function is_object ;
2626use Laudis \Neo4j \Contracts \FormatterInterface ;
27+ use Laudis \Neo4j \Types \CypherList ;
28+ use Laudis \Neo4j \Types \CypherMap ;
2729use Psr \Http \Message \RequestInterface ;
2830use Psr \Http \Message \ResponseInterface ;
2931use UnexpectedValueException ;
3335 * @psalm-import-type CypherRowResponse from \Laudis\Neo4j\Contracts\FormatterInterface
3436 * @psalm-import-type CypherResponse from \Laudis\Neo4j\Contracts\FormatterInterface
3537 * @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>
3742 */
3843final class BasicFormatter implements FormatterInterface
3944{
4045 /**
4146 * @param array{fields: array<int, string>} $meta
4247 * @param array<array-key, array> $results
4348 *
44- * @return Vector<Map<string, scalar| array|null>>
49+ * @return CypherList<CypherMap< array|scalar |null>>
4550 */
46- public function formatBoltResult (array $ meta , array $ results , Bolt $ bolt ): Vector
51+ public function formatBoltResult (array $ meta , array $ results , Bolt $ bolt ): CypherList
4752 {
4853 $ results = array_slice ($ results , 0 , count ($ results ) - 1 );
4954
55+ /** @var Vector<CypherMap<scalar|array|null>> */
5056 $ tbr = new Vector ();
5157 foreach ($ results as $ result ) {
5258 $ tbr ->push ($ this ->formatRow ($ meta , $ result ));
5359 }
5460
55- return $ tbr ;
61+ return new CypherList ( $ tbr) ;
5662 }
5763
58- public function formatHttpResult (ResponseInterface $ response , array $ body ): Vector
64+ public function formatHttpResult (ResponseInterface $ response , array $ body ): CypherList
5965 {
66+ /** @var Vector<CypherList<CypherMap<scalar|array|null>>> */
6067 $ tbr = new Vector ();
6168
6269 foreach ($ body ['results ' ] as $ results ) {
6370 $ tbr ->push ($ this ->buildResult ($ results ));
6471 }
6572
66- return $ tbr ;
73+ return new CypherList ( $ tbr) ;
6774 }
6875
6976 /**
7077 * @psalm-param CypherResponse $result
7178 *
72- * @return Vector<Map<string, scalar|array|null>>
79+ * @return CypherList<CypherMap< scalar|array|null>>
7380 */
74- private function buildResult (array $ result ): Vector
81+ private function buildResult (array $ result ): CypherList
7582 {
83+ /** @psalm-var Vector<CypherMap<null|scalar|array>> */
7684 $ tbr = new Vector ();
7785
7886 $ columns = $ result ['columns ' ];
@@ -84,26 +92,26 @@ private function buildResult(array $result): Vector
8492 foreach ($ columns as $ index => $ key ) {
8593 $ map ->put ($ key , $ vector ->get ($ index ));
8694 }
87- $ tbr ->push ($ map );
95+ $ tbr ->push (new CypherMap ( $ map) );
8896 }
8997
90- return $ tbr ;
98+ return new CypherList ( $ tbr) ;
9199 }
92100
93101 /**
94102 * @param array{fields: array<int, string>} $meta
95103 *
96- * @return Map<string, scalar|array|null>
104+ * @return CypherMap< scalar|array|null>
97105 */
98- private function formatRow (array $ meta , array $ result ): Map
106+ private function formatRow (array $ meta , array $ result ): CypherMap
99107 {
100108 /** @var Map<string, scalar|array|null> $map */
101109 $ map = new Map ();
102110 foreach ($ meta ['fields ' ] as $ i => $ column ) {
103111 $ map ->put ($ column , $ this ->mapValue ($ result [$ i ]));
104112 }
105113
106- return $ map ;
114+ return new CypherMap ( $ map) ;
107115 }
108116
109117 private function mapPath (Path $ path ): array
0 commit comments