13
13
14
14
namespace Laudis \Neo4j \Formatter ;
15
15
16
- use stdClass ;
17
16
use function array_slice ;
18
17
use Bolt \structures \Path ;
19
18
use function count ;
28
27
use Laudis \Neo4j \Types \CypherMap ;
29
28
use Psr \Http \Message \RequestInterface ;
30
29
use Psr \Http \Message \ResponseInterface ;
30
+ use stdClass ;
31
31
use UnexpectedValueException ;
32
32
33
33
/**
34
34
* Formats the result in basic CypherLists and CypherMaps. All cypher types are erased so that the map only contains scalar, null or array values.
35
35
*
36
- * @psalm-import-type CypherError from \Laudis\Neo4j\Contracts\FormatterInterface
37
- * @psalm-import-type CypherRowResponse from \Laudis\Neo4j\Contracts\FormatterInterface
38
- * @psalm-import-type CypherResponse from \Laudis\Neo4j\Contracts\FormatterInterface
39
- * @psalm-import-type CypherResponseSet from \Laudis\Neo4j\Contracts\FormatterInterface
40
- *
41
36
* @psalm-type BasicResults = CypherList<CypherMap<scalar|array|null>>
42
37
*
43
38
* @implements FormatterInterface<BasicResults>
@@ -80,6 +75,7 @@ public function formatHttpResult(ResponseInterface $response, stdClass $body, ?C
80
75
/** @var list<CypherList<CypherMap<scalar|array|null>>> */
81
76
$ tbr = [];
82
77
78
+ /** @var stdClass $results */
83
79
foreach ($ body ->results as $ results ) {
84
80
$ tbr [] = $ this ->buildResult ($ results );
85
81
}
@@ -95,15 +91,19 @@ private function buildResult(stdClass $result): CypherList
95
91
/** @var list<CypherMap<scalar|array|null>> */
96
92
$ tbr = [];
97
93
94
+ /** @var list<string> $columns */
98
95
$ columns = (array ) $ result ->columns ;
96
+ /** @var stdClass $dataRow */
99
97
foreach ($ result ->data as $ dataRow ) {
100
- $ row = $ dataRow ->row ;
101
98
/** @var array<string, scalar|array|null> $map */
102
99
$ map = [];
103
- $ vector = $ row ;
100
+ /** @var list<stdClass|scalar|array|null> */
101
+ $ vector = $ dataRow ->row ;
104
102
foreach ($ columns as $ index => $ key ) {
105
- // Make sure it are all arrays now
106
- $ map [$ key ] = json_decode (json_encode ($ vector [$ index ], JSON_THROW_ON_ERROR ), true , 512 , JSON_THROW_ON_ERROR );
103
+ // Removes the stdClasses from the json objects
104
+ /** @var scalar|array|null */
105
+ $ decoded = json_decode (json_encode ($ vector [$ index ], JSON_THROW_ON_ERROR ), true , 512 , JSON_THROW_ON_ERROR );
106
+ $ map [$ key ] = $ decoded ;
107
107
}
108
108
$ tbr [] = new CypherMap ($ map );
109
109
}
0 commit comments