Skip to content

Commit 0dbd375

Browse files
p123-stacktransistive
authored andcommitted
Fixed all ResultSummary testkit tests and issues
1 parent 1a8600a commit 0dbd375

16 files changed

+388
-235
lines changed

src/Databags/Notification.php

Lines changed: 66 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,60 +13,96 @@
1313

1414
namespace Laudis\Neo4j\Databags;
1515

16-
/**
17-
* Representation for notifications found when executing a query. A notification can be visualized in a client pinpointing problems or other information about the query.
18-
*
19-
* @psalm-immutable
20-
*/
16+
use InvalidArgumentException;
17+
2118
final class Notification
2219
{
2320
public function __construct(
24-
private readonly string $code,
25-
private readonly string $description,
26-
private readonly ?InputPosition $inputPosition,
27-
private readonly string $severity,
28-
private readonly string $title,
21+
private string $severity,
22+
private string $description,
23+
private string $code,
24+
private Position $position,
25+
private string $title,
26+
private string $category,
2927
) {
3028
}
3129

3230
/**
33-
* Returns a notification code for the discovered issue.
31+
* @throws InvalidArgumentException
32+
*
33+
* @return array{classification: string, category: string, title: string}
3434
*/
35-
public function getCode(): string
35+
private function splitCode(): array
3636
{
37-
return $this->code;
37+
$parts = explode('.', $this->code, 4);
38+
if (count($parts) < 4) {
39+
throw new InvalidArgumentException('Invalid message exception code');
40+
}
41+
42+
return [
43+
'classification' => $parts[1],
44+
'category' => $parts[2],
45+
'title' => $parts[3],
46+
];
3847
}
3948

40-
/**
41-
* Returns a longer description of the notification.
42-
*/
43-
public function getDescription(): string
49+
public function getCodeClassification(): string
4450
{
45-
return $this->description;
51+
return $this->splitCode()['classification'];
4652
}
4753

48-
/**
49-
* The position in the query where this notification points to.
50-
* Not all notifications have a unique position to point to and in that case the position would be set to null.
51-
*/
52-
public function getInputPosition(): ?InputPosition
54+
public function getCodeCategory(): string
5355
{
54-
return $this->inputPosition;
56+
return $this->splitCode()['category'];
57+
}
58+
59+
public function getCodeTitle(): string
60+
{
61+
return $this->splitCode()['title'];
5562
}
5663

57-
/**
58-
* The severity level of the notification.
59-
*/
6064
public function getSeverity(): string
6165
{
6266
return $this->severity;
6367
}
6468

65-
/**
66-
* Returns a short summary of the notification.
67-
*/
69+
public function getDescription(): string
70+
{
71+
return $this->description;
72+
}
73+
74+
public function getCode(): string
75+
{
76+
return $this->code;
77+
}
78+
79+
public function getPosition(): Position
80+
{
81+
return $this->position;
82+
}
83+
6884
public function getTitle(): string
6985
{
7086
return $this->title;
7187
}
88+
89+
public function getCategory(): string
90+
{
91+
return $this->category;
92+
}
93+
94+
/**
95+
* @psalm-external-mutation-free
96+
*/
97+
public function toArray(): array
98+
{
99+
return [
100+
'severity' => $this->severity,
101+
'description' => $this->description,
102+
'code' => $this->code,
103+
'position' => $this->position->toArray(),
104+
'title' => $this->title,
105+
'category' => $this->category,
106+
];
107+
}
72108
}

src/Databags/Plan.php

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,60 +13,49 @@
1313

1414
namespace Laudis\Neo4j\Databags;
1515

16-
use Laudis\Neo4j\Types\AbstractCypherObject;
17-
use Laudis\Neo4j\Types\CypherList;
18-
use Laudis\Neo4j\Types\CypherMap;
19-
2016
/**
2117
* This describes the plan that the database planner produced and used (or will use) to execute your query.
2218
*
2319
* @see https://neo4j.com/docs/cypher-manual/current/execution-plans/
24-
*
25-
* @psalm-immutable
26-
*
27-
* @extends AbstractCypherObject<string, mixed>
2820
*/
29-
final class Plan extends AbstractCypherObject
21+
final class Plan
3022
{
3123
/**
32-
* @param CypherMap<mixed> $arguments
33-
* @param CypherList<Plan> $list
34-
* @param CypherList<string> $identifiers
24+
* @param list<Plan> $children
25+
* @param list<string> $identifiers
3526
*/
3627
public function __construct(
37-
private readonly CypherMap $arguments,
38-
private readonly CypherList $list,
39-
private readonly CypherList $identifiers,
28+
private readonly PlanArguments $args,
29+
private readonly array $children,
30+
private readonly array $identifiers,
4031
private readonly string $operator,
4132
) {
4233
}
4334

4435
/**
4536
* Returns the arguments for the operator.
46-
*
47-
* @return CypherMap<mixed>
4837
*/
49-
public function getArguments(): CypherMap
38+
public function getArgs(): PlanArguments
5039
{
51-
return $this->arguments;
40+
return $this->args;
5241
}
5342

5443
/**
5544
* Returns the sub-plans.
5645
*
57-
* @return CypherList<Plan>
46+
* @return list<Plan>
5847
*/
59-
public function getList(): CypherList
48+
public function getChildren(): array
6049
{
61-
return $this->list;
50+
return $this->children;
6251
}
6352

6453
/**
6554
* Identifiers used by this part of the plan.
6655
*
67-
* @return CypherList<string>
56+
* @return list<string>
6857
*/
69-
public function getIdentifiers(): CypherList
58+
public function getIdentifiers(): array
7059
{
7160
return $this->identifiers;
7261
}
@@ -82,8 +71,8 @@ public function getOperator(): string
8271
public function toArray(): array
8372
{
8473
return [
85-
'arguments' => $this->arguments,
86-
'list' => $this->list,
74+
'arguments' => $this->args,
75+
'list' => $this->children,
8776
'identifiers' => $this->identifiers,
8877
'operator' => $this->operator,
8978
];

src/Databags/PlanArguments.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Neo4j PHP Client and Driver package.
7+
*
8+
* (c) Nagels <https://nagels.tech>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
namespace Laudis\Neo4j\Databags;
15+
16+
final class PlanArguments
17+
{
18+
public function __construct(
19+
public readonly ?int $globalMemory = null,
20+
public readonly ?string $plannerImpl = null,
21+
public readonly ?int $memory = null,
22+
public readonly ?string $stringRepresentation = null,
23+
public readonly ?string $runtime = null,
24+
public readonly ?int $time = null,
25+
public readonly ?int $pageCacheMisses = null,
26+
public readonly ?int $pageCacheHits = null,
27+
public readonly ?string $runtimeImpl = null,
28+
public readonly ?string $version = null,
29+
public readonly ?int $dbHits = null,
30+
public readonly ?int $batchSize = null,
31+
public readonly ?string $details = null,
32+
public readonly ?string $plannerVersion = null,
33+
public readonly ?string $pipelineInfo = null,
34+
public readonly string|float|null $runtimeVersion = null,
35+
public readonly ?int $id = null,
36+
public readonly ?float $estimatedRows = null,
37+
public readonly ?string $planner = null,
38+
public readonly ?int $rows = null,
39+
) {
40+
}
41+
42+
/**
43+
* @psalm-external-mutation-free
44+
*/
45+
public function toArray(): array
46+
{
47+
return [
48+
'globalMemory' => $this->globalMemory,
49+
'plannerImpl' => $this->plannerImpl,
50+
'memory' => $this->memory,
51+
'stringRepresentation' => $this->stringRepresentation,
52+
'runtime' => $this->runtime,
53+
'time' => $this->time,
54+
'pageCacheMisses' => $this->pageCacheMisses,
55+
'pageCacheHits' => $this->pageCacheHits,
56+
'runtimeImpl' => $this->runtimeImpl,
57+
'version' => $this->version,
58+
'dbHits' => $this->dbHits,
59+
'batchSize' => $this->batchSize,
60+
'details' => $this->details,
61+
'plannerVersion' => $this->plannerVersion,
62+
'pipelineInfo' => $this->pipelineInfo,
63+
'runtimeVersion' => $this->runtimeVersion,
64+
'id' => $this->id,
65+
'estimatedRows' => $this->estimatedRows,
66+
'planner' => $this->planner,
67+
'rows' => $this->rows,
68+
];
69+
}
70+
}

src/Databags/InputPosition.php renamed to src/Databags/Position.php

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,38 @@
1414
namespace Laudis\Neo4j\Databags;
1515

1616
/**
17-
* An input position refers to a specific character in a query.
18-
*
1917
* @psalm-immutable
2018
*/
21-
final class InputPosition
19+
final class Position
2220
{
2321
public function __construct(
24-
private readonly int $column,
25-
private readonly int $line,
26-
private readonly int $offset,
22+
private int $column,
23+
private int $offset,
24+
private int $line,
2725
) {
2826
}
2927

30-
/**
31-
* The column number referred to by the position; column numbers start at 1.
32-
*/
33-
public function getColumn(): int
34-
{
35-
return $this->column;
36-
}
37-
38-
/**
39-
* The line number referred to by the position; line numbers start at 1.
40-
*/
4128
public function getLine(): int
4229
{
4330
return $this->line;
4431
}
4532

46-
/**
47-
* The character offset referred to by this position; offset numbers start at 0.
48-
*/
4933
public function getOffset(): int
5034
{
5135
return $this->offset;
5236
}
37+
38+
public function getColumn(): int
39+
{
40+
return $this->column;
41+
}
42+
43+
public function toArray(): array
44+
{
45+
return [
46+
'column' => $this->column,
47+
'offset' => $this->offset,
48+
'line' => $this->line,
49+
];
50+
}
5351
}

0 commit comments

Comments
 (0)