Skip to content

Commit 3ac6243

Browse files
resolved changes according to comments
1 parent 379ec73 commit 3ac6243

21 files changed

+88
-129
lines changed

src/Objects/Authentication.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ public static function fromEnvironment(): AuthenticateInterface
2626
);
2727
}
2828

29-
public static function noAuth(): AuthenticateInterface
30-
{
31-
return new NoAuth();
32-
}
33-
3429

3530
public static function bearer(string $token): AuthenticateInterface
3631
{

src/Objects/Bookmarks.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class Bookmarks implements \Countable, JsonSerializable
88
{
9-
public function __construct(private array $bookmarks)
9+
public function __construct(public array $bookmarks)
1010
{
1111
}
1212

@@ -17,12 +17,6 @@ public function addBookmarks(?Bookmarks $newBookmarks): void
1717
}
1818
}
1919

20-
21-
public function getBookmarks(): array
22-
{
23-
return $this->bookmarks;
24-
}
25-
2620
#[\Override]
2721
public function count(): int
2822
{

src/Objects/Node.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,5 @@ public function toArray(): array
2929
'_properties' => $this->properties,
3030
];
3131
}
32-
public function getProperties(): array
33-
{
34-
return $this->properties;
35-
}
3632

37-
public function getLabels(): array
38-
{
39-
return $this->labels;
40-
}
4133
}

src/Objects/Path.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,4 @@ public function __construct(array $nodes, array $relationships)
3030
$this->relationships = $relationships;
3131
}
3232

33-
public function getNodes(): array
34-
{
35-
return $this->nodes;
36-
}
37-
38-
public function getRelationships(): array
39-
{
40-
return $this->relationships;
41-
}
42-
4333
}

src/Objects/Point.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,4 @@ public function __toString(): string
3131
return "SRID={$this->srid};POINT ({$this->x} {$this->y})";
3232
}
3333

34-
public function getX(): float
35-
{
36-
return $this->x;
37-
}
38-
public function getY(): float
39-
{
40-
return $this->y;
41-
}
42-
public function getZ(): float
43-
{
44-
return $this->z;
45-
}
46-
public function getSrid(): float
47-
{
48-
return $this->srid;
49-
}
5034
}

src/Objects/Relationship.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,4 @@ public function __construct(string $type, array $properties = [])
3030
$this->properties = $properties;
3131
}
3232

33-
public function getType(): string
34-
{
35-
return $this->type;
36-
}
37-
38-
public function getProperties(): array
39-
{
40-
return $this->properties;
41-
}
42-
43-
4433
}

src/ResponseParser.php

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,40 @@ private function validateAndDecodeResponse(ResponseInterface $response): array
4949
return $data;
5050
}
5151

52-
private function mapRows(array $keys, array $values): array
52+
/**
53+
* @return list<ResultRow>
54+
*/
55+
/**
56+
* @param list<string> $fields
57+
* @param list<array<array-key, mixed>> $values
58+
* @return list<ResultRow>
59+
*/
60+
private function mapRows(array $fields, array $values): array
5361
{
54-
return array_map(function ($row) use ($keys) {
55-
$mapped = [];
56-
foreach ($keys as $index => $key) {
57-
$fieldData = $row[$index] ?? null;
58-
if (is_string($fieldData)) {
59-
$fieldData = ['$type' => 'String', '_value' => $fieldData];
60-
}
61-
$mapped[$key] = $this->ogm->map($fieldData);
62-
}
63-
return new ResultRow($mapped);
64-
}, $values);
62+
return array_map(
63+
fn (array $row): ResultRow => new ResultRow(
64+
array_combine(
65+
$fields,
66+
array_map([$this, 'formatOGMOutput'], $row)
67+
) ?: [] // Ensure array_combine never returns false
68+
),
69+
$values
70+
);
71+
}
72+
73+
/**
74+
* Ensures mapped output follows expected format
75+
*
76+
* @param mixed $value
77+
* @return mixed
78+
*/
79+
private function formatOGMOutput(mixed $value): mixed
80+
{
81+
if (is_array($value) && array_key_exists('$type', $value) && array_key_exists('_value', $value)) {
82+
return $this->ogm->map($value);
83+
}
84+
85+
return $value;
6586
}
6687

6788
private function buildCounters(array $countersData): ResultCounters

src/Results/ResultSet.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,35 +38,11 @@ public function getIterator(): Traversable
3838
return new ArrayIterator($this->rows);
3939
}
4040

41-
public function getQueryCounters(): ?ResultCounters
42-
{
43-
return $this->counters;
44-
}
45-
4641

4742
#[\Override]
4843
public function count(): int
4944
{
5045
return count($this->rows);
5146
}
5247

53-
public function getBookmarks(): ?Bookmarks
54-
{
55-
return $this->bookmarks;
56-
}
57-
58-
public function getAccessMode(): ?AccessMode
59-
{
60-
return $this->accessMode;
61-
}
62-
63-
public function getData(): array
64-
{
65-
return $this->rows;
66-
}
67-
68-
public function getProfiledQueryPlan(): ?ProfiledQueryPlan
69-
{
70-
return $this->profiledQueryPlan;
71-
}
7248
}

tests/Integration/BookmarksIntegrationTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Neo4j\QueryAPI\Tests\Integration;
44

5+
use Neo4j\QueryAPI\Results\ResultSet;
56
use Neo4j\QueryAPI\Tests\CreatesQueryAPI;
67
use PHPUnit\Framework\TestCase;
78
use Neo4j\QueryAPI\Objects\Bookmarks;
@@ -23,13 +24,13 @@ public function testCreateBookmarks(): void
2324
{
2425
$result = $this->api->run('CREATE (x:Node {hello: "world"})');
2526

26-
$bookmarks = $result->getBookmarks() ?? new Bookmarks([]);
27+
$bookmarks = $result->bookmarks ?? new Bookmarks([]);
2728

2829
$result = $this->api->run('CREATE (x:Node {hello: "world2"})');
29-
$bookmarks->addBookmarks($result->getBookmarks());
30+
$bookmarks->addBookmarks($result->bookmarks);
3031

3132
$result = $this->api->run('MATCH (x:Node {hello: "world2"}) RETURN x');
32-
$bookmarks->addBookmarks($result->getBookmarks());
33+
$bookmarks->addBookmarks($result->bookmarks);
3334

3435
$this->assertCount(1, $result);
3536
}

tests/Integration/DataTypesIntegrationTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public function testWithExactNames(): void
4343
'names' => ['bob1', 'alicy']
4444
]);
4545

46-
$this->assertEquals($expected->getQueryCounters(), $results->getQueryCounters());
47-
$bookmarks = $results->getBookmarks() ?? new Bookmarks([]);
46+
$this->assertEquals($expected->counters, $results->counters);
47+
$bookmarks = $results->bookmarks ?? new Bookmarks([]);
4848
$this->assertCount(1, $bookmarks);
4949
}
5050
public function testWithSingleName(): void
@@ -63,8 +63,8 @@ public function testWithSingleName(): void
6363
'name' => 'bob1'
6464
]);
6565

66-
$this->assertEquals($expected->getQueryCounters(), $results->getQueryCounters());
67-
$bookmarks = $results->getBookmarks() ?: [];
66+
$this->assertEquals($expected->counters, $results->counters);
67+
$bookmarks = $results->bookmarks ?: [];
6868
$this->assertCount(1, $bookmarks);
6969
}
7070

@@ -228,8 +228,8 @@ public function testWithArray(): void
228228
['names' => ['bob1', 'alicy']]
229229
);
230230

231-
$this->assertEquals($expected->getQueryCounters(), $results->getQueryCounters());
232-
$bookmarks = $results->getBookmarks() ?: [];
231+
$this->assertEquals($expected->counters, $results->counters);
232+
$bookmarks = $results->bookmarks ?: [];
233233
$this->assertCount(1, $bookmarks);
234234
}
235235

0 commit comments

Comments
 (0)