|
24 | 24 | use Laudis\Neo4j\Databags\SummaryCounters;
|
25 | 25 | use Laudis\Neo4j\Enum\QueryTypeEnum;
|
26 | 26 | use Laudis\Neo4j\Types\CypherList;
|
| 27 | +use Laudis\Neo4j\Types\CypherMap; |
27 | 28 | use Psr\Http\Message\RequestInterface;
|
28 | 29 | use Psr\Http\Message\ResponseInterface;
|
29 | 30 | use UnexpectedValueException;
|
30 | 31 |
|
31 | 32 | /**
|
32 | 33 | * Decorates the result of the provided format with an extensive summary.
|
33 | 34 | *
|
34 |
| - * @template T |
35 |
| - * |
36 | 35 | * @psalm-import-type CypherResponseSet from \Laudis\Neo4j\Contracts\FormatterInterface
|
37 | 36 | * @psalm-import-type CypherResponse from \Laudis\Neo4j\Contracts\FormatterInterface
|
38 | 37 | * @psalm-import-type BoltCypherStats from \Laudis\Neo4j\Contracts\FormatterInterface
|
39 | 38 | * @psalm-import-type OGMResults from \Laudis\Neo4j\Formatter\OGMFormatter
|
| 39 | + * @psalm-import-type OGMTypes from \Laudis\Neo4j\Formatter\OGMFormatter |
40 | 40 | *
|
41 |
| - * @implements FormatterInterface<SummarizedResult<T>> |
| 41 | + * @implements FormatterInterface<SummarizedResult<CypherMap<OGMTypes>>> |
42 | 42 | *
|
43 | 43 | * @psalm-immutable
|
44 | 44 | */
|
45 | 45 | final class SummarizedResultFormatter implements FormatterInterface
|
46 | 46 | {
|
47 |
| - /** @var FormatterInterface<T> */ |
48 |
| - private FormatterInterface $formatter; |
| 47 | + private OGMFormatter $formatter; |
49 | 48 |
|
50 | 49 | /**
|
51 |
| - * Creates a new instance of itself by decorating an OGMFormatter. |
52 |
| - * |
53 |
| - * @return self<OGMResults> |
54 |
| - * |
55 | 50 | * @pure
|
56 | 51 | */
|
57 | 52 | public static function create(): self
|
58 | 53 | {
|
59 |
| - return self::createWithFormatter(OGMFormatter::create()); |
| 54 | + return new self(OGMFormatter::create()); |
60 | 55 | }
|
61 | 56 |
|
62 |
| - /** |
63 |
| - * @template U |
64 |
| - * |
65 |
| - * Creates a new summarized result formatter by decorating the given formatter. |
66 |
| - * |
67 |
| - * @param FormatterInterface<U> $formatter |
68 |
| - * |
69 |
| - * @return self<U> |
70 |
| - * |
71 |
| - * @pure |
72 |
| - */ |
73 |
| - public static function createWithFormatter(FormatterInterface $formatter): self |
74 |
| - { |
75 |
| - return new self($formatter); |
76 |
| - } |
77 |
| - |
78 |
| - /** |
79 |
| - * @param FormatterInterface<T> $formatter |
80 |
| - */ |
81 |
| - public function __construct(FormatterInterface $formatter) |
| 57 | + public function __construct(OGMFormatter $formatter) |
82 | 58 | {
|
83 | 59 | $this->formatter = $formatter;
|
84 | 60 | }
|
85 | 61 |
|
86 | 62 | /**
|
87 |
| - * @param CypherResponse $response |
88 |
| - * @param T $results |
| 63 | + * @param CypherResponse $response |
| 64 | + * @param CypherList<CypherMap<OGMTypes>> $results |
89 | 65 | *
|
90 |
| - * @return SummarizedResult<T> |
| 66 | + * @return SummarizedResult<CypherMap<OGMTypes>> |
91 | 67 | */
|
92 |
| - public function formatHttpStats(array $response, ConnectionInterface $connection, Statement $statement, float $resultAvailableAfter, float $resultConsumedAfter, $results): SummarizedResult |
| 68 | + public function formatHttpStats(array $response, ConnectionInterface $connection, Statement $statement, float $resultAvailableAfter, float $resultConsumedAfter, CypherList $results): SummarizedResult |
93 | 69 | {
|
94 | 70 | if (!isset($response['stats'])) {
|
95 | 71 | throw new UnexpectedValueException('No stats found in the response set');
|
@@ -129,7 +105,7 @@ public function formatHttpStats(array $response, ConnectionInterface $connection
|
129 | 105 | )
|
130 | 106 | );
|
131 | 107 |
|
132 |
| - return new SummarizedResult($results, $summary); |
| 108 | + return new SummarizedResult($summary, $results->toArray()); |
133 | 109 | }
|
134 | 110 |
|
135 | 111 | /**
|
@@ -196,12 +172,12 @@ public function formatBoltResult(array $meta, array $results, ConnectionInterfac
|
196 | 172 | );
|
197 | 173 | $formattedResult = $this->formatter->formatBoltResult($meta, $results, $connection, $resultAvailableAfter, $resultConsumedAfter, $statement);
|
198 | 174 |
|
199 |
| - return new SummarizedResult($formattedResult, $summary); |
| 175 | + return new SummarizedResult($summary, $formattedResult->toArray()); |
200 | 176 | }
|
201 | 177 |
|
202 | 178 | public function formatHttpResult(ResponseInterface $response, array $body, ConnectionInterface $connection, float $resultsAvailableAfter, float $resultsConsumedAfter, iterable $statements): CypherList
|
203 | 179 | {
|
204 |
| - /** @var list<SummarizedResult<T>> */ |
| 180 | + /** @var list<SummarizedResult<CypherMap<OGMTypes>>> */ |
205 | 181 | $tbr = [];
|
206 | 182 |
|
207 | 183 | $toDecorate = $this->formatter->formatHttpResult($response, $body, $connection, $resultsAvailableAfter, $resultsConsumedAfter, $statements);
|
|
0 commit comments