Skip to content

Commit 2db3d83

Browse files
committed
fixed type hints in basic formatter
1 parent 2fb73f8 commit 2db3d83

File tree

5 files changed

+20
-23
lines changed

5 files changed

+20
-23
lines changed

src/Contracts/FormatterInterface.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ public function formatBoltResult(array $meta, array $results, ConnectionInterfac
8383
/**
8484
* Formats the results of the HTTP protocol to the unified format.
8585
*
86-
* @param stdClass $body
8786
* @param iterable<Statement> $statements
8887
*
8988
* @throws JsonException

src/Formatter/BasicFormatter.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace Laudis\Neo4j\Formatter;
1515

16-
use stdClass;
1716
use function array_slice;
1817
use Bolt\structures\Path;
1918
use function count;
@@ -28,16 +27,12 @@
2827
use Laudis\Neo4j\Types\CypherMap;
2928
use Psr\Http\Message\RequestInterface;
3029
use Psr\Http\Message\ResponseInterface;
30+
use stdClass;
3131
use UnexpectedValueException;
3232

3333
/**
3434
* Formats the result in basic CypherLists and CypherMaps. All cypher types are erased so that the map only contains scalar, null or array values.
3535
*
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-
*
4136
* @psalm-type BasicResults = CypherList<CypherMap<scalar|array|null>>
4237
*
4338
* @implements FormatterInterface<BasicResults>
@@ -80,6 +75,7 @@ public function formatHttpResult(ResponseInterface $response, stdClass $body, ?C
8075
/** @var list<CypherList<CypherMap<scalar|array|null>>> */
8176
$tbr = [];
8277

78+
/** @var stdClass $results */
8379
foreach ($body->results as $results) {
8480
$tbr[] = $this->buildResult($results);
8581
}
@@ -95,15 +91,19 @@ private function buildResult(stdClass $result): CypherList
9591
/** @var list<CypherMap<scalar|array|null>> */
9692
$tbr = [];
9793

94+
/** @var list<string> $columns */
9895
$columns = (array) $result->columns;
96+
/** @var stdClass $dataRow */
9997
foreach ($result->data as $dataRow) {
100-
$row = $dataRow->row;
10198
/** @var array<string, scalar|array|null> $map */
10299
$map = [];
103-
$vector = $row;
100+
/** @var list<stdClass|scalar|array|null> */
101+
$vector = $dataRow->row;
104102
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;
107107
}
108108
$tbr[] = new CypherMap($map);
109109
}

src/Formatter/Specialised/HttpMetaInfo.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,11 @@
1515
use stdClass;
1616

1717
/**
18-
* @psalm-type RelationshipArray = array{id: string, type: string, startNode: string, endNode: string, properties: array<string, scalar|null|array<array-key, scalar|null|array>>}
19-
* @psalm-type NodeArray = array{id: string, labels: list<string>, properties: array<string, scalar|null|array}
20-
* @psalm-type Meta = array{id?: int, type: string, deleted?: bool}
21-
* @psalm-type MetaArray = list<Meta|null|list<array{id: int, type: string, deleted: bool}>>
22-
* @psalm-type CypherResultDataRow = array{row: list<scalar|array|null>, meta: MetaArray, graph: array{nodes: list<NodeArray>, relationships: list<RelationshipArray>}}
23-
*
2418
* @psalm-immutable
2519
*/
2620
final class HttpMetaInfo
2721
{
28-
/** @var list<stdClass|list> */
22+
/** @var list<stdClass|list<stdClass>> */
2923
private array $meta;
3024
/** @var list<stdClass> */
3125
private array $nodes;
@@ -58,11 +52,12 @@ public static function createFromData(stdClass $data): self
5852
/** @var stdClass */
5953
$graph = $data->graph;
6054

55+
/** @psalm-suppress MixedArgument */
6156
return new self($data->meta, $graph->nodes, $graph->relationships);
6257
}
6358

6459
/**
65-
* @return stdClass|list|null
60+
* @return stdClass|list<stdClass>|null
6661
*/
6762
public function currentMeta()
6863
{
@@ -112,15 +107,19 @@ public function getCurrentType(): ?string
112107
return null;
113108
}
114109

110+
/** @var string */
115111
return $currentMeta->type;
116112
}
117113

118114
public function withNestedMeta(): self
119115
{
120116
$tbr = clone $this;
121117

122-
$tbr->meta = (array) $this->currentMeta();
123-
$tbr->currentMeta = 0;
118+
$currentMeta = $this->currentMeta();
119+
if (is_array($currentMeta)) {
120+
$tbr->meta = $currentMeta;
121+
$tbr->currentMeta = 0;
122+
}
124123

125124
return $tbr;
126125
}

src/Formatter/SummarizedResultFormatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace Laudis\Neo4j\Formatter;
1515

16-
use stdClass;
1716
use function in_array;
1817
use function is_int;
1918
use Laudis\Neo4j\Contracts\ConnectionInterface;
@@ -28,6 +27,7 @@
2827
use Laudis\Neo4j\Types\CypherMap;
2928
use Psr\Http\Message\RequestInterface;
3029
use Psr\Http\Message\ResponseInterface;
30+
use stdClass;
3131
use UnexpectedValueException;
3232

3333
/**

tests/Integration/OGMFormatterIntegrationTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
use function range;
3838
use function sprintf;
3939
use function str_contains;
40-
use function str_starts_with;
4140

4241
/**
4342
* @psalm-import-type OGMResults from \Laudis\Neo4j\Formatter\OGMFormatter

0 commit comments

Comments
 (0)