Skip to content

Commit 5e00118

Browse files
committed
all the info errors were solved
1 parent 5bc2ad5 commit 5e00118

12 files changed

+200
-488
lines changed

src/Authentication/BasicAuthentication.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ class BasicAuthentication implements AuthenticateInterface
1414

1515
public function __construct(?string $username = null, ?string $password = null)
1616
{
17-
$this->username = $username ?? (getenv("NEO4J_USERNAME") !== false ? getenv("NEO4J_USERNAME") : '');
18-
$this->password = $password ?? (getenv("NEO4J_PASSWORD") !== false ? getenv("NEO4J_PASSWORD") : '');
17+
$this->username = $username ?? (is_string($envUser = getenv("NEO4J_USERNAME")) ? $envUser : '');
18+
$this->password = $password ?? (is_string($envPass = getenv("NEO4J_PASSWORD")) ? $envPass : '');
1919
}
2020

21+
2122
public function authenticate(RequestInterface $request): RequestInterface
2223
{
2324
$authHeader = $this->getHeader();

src/Objects/Authentication.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,18 @@ public static function basic(string $username, string $password): AuthenticateIn
2424

2525
public static function fromEnvironment(): AuthenticateInterface
2626
{
27-
$username = getenv("NEO4J_USERNAME") ?: '';
28-
$password = getenv("NEO4J_PASSWORD") ?: '';
27+
$username = getenv("NEO4J_USERNAME");
28+
$password = getenv("NEO4J_PASSWORD");
2929

30-
return new BasicAuthentication($username, $password);
30+
return new BasicAuthentication(
31+
$username !== false ? $username : null,
32+
$password !== false ? $password : null
33+
);
3134
}
3235

3336

3437

38+
3539
public static function noAuth(): AuthenticateInterface
3640
{
3741
return new NoAuth();

src/ResponseParser.php

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -90,44 +90,53 @@ private function getAccessMode(string $accessModeData): AccessMode
9090

9191
private function buildProfiledQueryPlan(?array $queryPlanData): ?ProfiledQueryPlan
9292
{
93-
9493
if ($queryPlanData === null || empty($queryPlanData)) {
9594
return null;
9695
}
9796

9897
/**
9998
* @var array<string, mixed> $mappedArguments
10099
*/
101-
$mappedArguments = array_map(function ($value): mixed {
102-
if (is_array($value) && array_key_exists('$type', $value) && array_key_exists('_value', $value)) {
103-
return $this->ogm->map($value);
100+
$mappedArguments = array_map(function (array $value): mixed {
101+
if (
102+
isset($value['$type'], $value['_value']) &&
103+
is_string($value['$type'])
104+
) {
105+
return $this->ogm->map([
106+
'$type' => $value['$type'],
107+
'_value' => $value['_value']
108+
]); // ✅ Pass only expected keys
104109
}
105110
return $value;
106111
}, $queryPlanData['arguments'] ?? []);
107112

108113
$queryArguments = new ProfiledQueryPlanArguments(
109114
globalMemory: $mappedArguments['GlobalMemory'] ?? null,
110-
plannerImpl: $mappedArguments['planner-impl'] ?? null, //('planner-impl', $mappedArguments) ? $mappedArguments['planner-impl'] : null,
111-
memory: array_key_exists('Memory', $mappedArguments) ? $mappedArguments['Memory'] : null,
112-
stringRepresentation: array_key_exists('string-representation', $mappedArguments) ? $mappedArguments['string-representation'] : null,
113-
runtime: array_key_exists('runtime', $mappedArguments) ? $mappedArguments['runtime'] : null,
114-
time: array_key_exists('Time', $mappedArguments) ? $mappedArguments['Time'] : null,
115-
pageCacheMisses: array_key_exists('PageCacheMisses', $mappedArguments) ? $mappedArguments['PageCacheMisses'] : null,
116-
pageCacheHits: array_key_exists('PageCacheHits', $mappedArguments) ? $mappedArguments['PageCacheHits'] : null,
117-
runtimeImpl: array_key_exists('runtime-impl', $mappedArguments) ? $mappedArguments['runtime-impl'] : null,
118-
version: array_key_exists('version', $mappedArguments) ? $mappedArguments['version'] : null,
119-
dbHits: array_key_exists('DbHits', $mappedArguments) ? $mappedArguments['DbHits'] : null,
120-
batchSize: array_key_exists('batch-size', $mappedArguments) ? $mappedArguments['batch-size'] : null,
121-
details: array_key_exists('Details', $mappedArguments) ? $mappedArguments['Details'] : null,
122-
plannerVersion: array_key_exists('planner-version', $mappedArguments) ? $mappedArguments['planner-version'] : null,
123-
pipelineInfo: array_key_exists('PipelineInfo', $mappedArguments) ? $mappedArguments['PipelineInfo'] : null,
124-
runtimeVersion: array_key_exists('runtime-version', $mappedArguments) ? $mappedArguments['runtime-version'] : null,
125-
id: array_key_exists('Id', $mappedArguments) ? $mappedArguments['Id'] : null,
126-
estimatedRows: array_key_exists('EstimatedRows', $mappedArguments) ? $mappedArguments['EstimatedRows'] : null,
127-
planner: array_key_exists('planner', $mappedArguments) ? $mappedArguments['planner'] : null,
128-
rows: array_key_exists('Rows', $mappedArguments) ? $mappedArguments['Rows'] : null
115+
plannerImpl: $mappedArguments['planner-impl'] ?? null,
116+
memory: $mappedArguments['Memory'] ?? null,
117+
stringRepresentation: $mappedArguments['string-representation'] ?? null,
118+
runtime: $mappedArguments['runtime'] ?? null,
119+
time: $mappedArguments['Time'] ?? null,
120+
pageCacheMisses: $mappedArguments['PageCacheMisses'] ?? null,
121+
pageCacheHits: $mappedArguments['PageCacheHits'] ?? null,
122+
runtimeImpl: $mappedArguments['runtime-impl'] ?? null,
123+
version: $mappedArguments['version'] ?? null,
124+
dbHits: $mappedArguments['DbHits'] ?? null,
125+
batchSize: $mappedArguments['batch-size'] ?? null,
126+
details: $mappedArguments['Details'] ?? null,
127+
plannerVersion: $mappedArguments['planner-version'] ?? null,
128+
pipelineInfo: $mappedArguments['PipelineInfo'] ?? null,
129+
runtimeVersion: $mappedArguments['runtime-version'] ?? null,
130+
id: $mappedArguments['Id'] ?? null,
131+
estimatedRows: $mappedArguments['EstimatedRows'] ?? null,
132+
planner: $mappedArguments['planner'] ?? null,
133+
rows: $mappedArguments['Rows'] ?? null
134+
);
135+
136+
$children = array_map(
137+
fn (array $child): ?ProfiledQueryPlan => $this->buildProfiledQueryPlan($child),
138+
$queryPlanData['children'] ?? []
129139
);
130-
$children = array_map(fn ($child) => $this->buildProfiledQueryPlan($child), $queryPlanData['children'] ?? []);
131140

132141
return new ProfiledQueryPlan(
133142
$queryPlanData['dbHits'] ?? 0,
@@ -143,4 +152,5 @@ private function buildProfiledQueryPlan(?array $queryPlanData): ?ProfiledQueryPl
143152
$queryPlanData['identifiers'] ?? []
144153
);
145154
}
155+
146156
}

src/Results/ResultRow.php

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,41 @@
99
use OutOfBoundsException;
1010
use ArrayAccess;
1111
use Traversable;
12-
1312
/**
14-
* @template TKey of array-key
1513
* @template TValue
16-
* @implements ArrayAccess<TKey, TValue>
17-
* @implements IteratorAggregate<TKey, TValue>
14+
* @implements ArrayAccess<string, TValue>
15+
* @implements IteratorAggregate<string, TValue>
1816
*/
1917
class ResultRow implements ArrayAccess, Countable, IteratorAggregate
2018
{
21-
public function __construct(private array $data)
22-
{
23-
24-
}
25-
19+
/** @var array<string, TValue> */
20+
private array $data;
2621

27-
public function offsetExists($offset): bool
22+
public function __construct(array $data)
2823
{
29-
return isset($this->data[$offset]);
24+
$this->data = $data;
3025
}
3126

32-
public function offsetGet($offset): mixed
27+
public function offsetGet(mixed $offset): mixed
3328
{
3429
if (!$this->offsetExists($offset)) {
3530
throw new OutOfBoundsException("Column {$offset} not found.");
3631
}
3732
return $this->data[$offset];
3833
}
3934

35+
public function get(string $row): mixed
36+
{
37+
return $this->offsetGet($row);
38+
}
39+
40+
41+
42+
public function offsetExists($offset): bool
43+
{
44+
return isset($this->data[$offset]);
45+
}
46+
4047
public function offsetSet($offset, $value): void
4148
{
4249
throw new BadMethodCallException("You can't set the value of column {$offset}.");
@@ -47,11 +54,6 @@ public function offsetUnset($offset): void
4754

4855
}
4956

50-
public function get(string $row): mixed
51-
{
52-
return $this->offsetGet($row);
53-
}
54-
5557
public function count(): int
5658
{
5759
return count($this->data);
@@ -61,4 +63,4 @@ public function getIterator(): Traversable
6163
{
6264
return new ArrayIterator($this->data);
6365
}
64-
}
66+
}

src/Results/ResultSet.php

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,23 @@
1111
use Neo4j\QueryAPI\Objects\ResultCounters;
1212
use Traversable;
1313

14-
// Make sure to include the Bookmarks class
15-
1614
/**
1715
* @api
18-
* @template TKey of array-key
1916
* @template TValue
20-
* @implements IteratorAggregate<TKey, TValue>
17+
* @implements IteratorAggregate<int, ResultRow>
2118
*/
2219
class ResultSet implements IteratorAggregate, Countable
2320
{
2421
/**
2522
* @param list<ResultRow> $rows
2623
*/
2724
public function __construct(
28-
private readonly array $rows,
29-
private readonly ?ResultCounters $counters = null,
30-
private readonly Bookmarks $bookmarks,
25+
private readonly array $rows,
26+
private readonly ?ResultCounters $counters = null,
27+
private readonly Bookmarks $bookmarks ,
3128
private readonly ?ProfiledQueryPlan $profiledQueryPlan,
32-
private readonly AccessMode $accessMode
29+
private readonly AccessMode $accessMode
3330
) {
34-
35-
3631
}
3732

3833
/**
@@ -42,6 +37,7 @@ public function getIterator(): Traversable
4237
{
4338
return new ArrayIterator($this->rows);
4439
}
40+
4541
public function getQueryCounters(): ?ResultCounters
4642
{
4743
return $this->counters;
@@ -69,18 +65,9 @@ public function getAccessMode(): ?AccessMode
6965
{
7066
return $this->accessMode;
7167
}
68+
7269
public function getData(): array
7370
{
7471
return $this->rows;
7572
}
76-
77-
78-
// public function getImpersonatedUser(): ?ImpersonatedUser
79-
// {
80-
//
81-
// }
82-
83-
84-
85-
8673
}

src/Transaction.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public function __construct(
2020
private Neo4jRequestFactory $requestFactory,
2121
private string $clusterAffinity,
2222
private string $transactionId
23-
2423
) {
2524
}
2625

@@ -36,12 +35,18 @@ public function run(string $query, array $parameters): ResultSet
3635
{
3736
$request = $this->requestFactory->buildTransactionRunRequest($query, $parameters, $this->transactionId, $this->clusterAffinity);
3837

38+
$response = null; // ✅ Ensures response is always defined
39+
3940
try {
4041
$response = $this->client->sendRequest($request);
4142
} catch (RequestExceptionInterface $e) {
4243
$this->handleRequestException($e);
4344
}
4445

46+
if (!$response instanceof ResponseInterface) {
47+
throw new Neo4jException(['message' => 'Failed to receive a valid response from Neo4j'], 500);
48+
}
49+
4550
return $this->responseParser->parseRunQueryResponse($response);
4651
}
4752

@@ -51,7 +56,6 @@ public function run(string $query, array $parameters): ResultSet
5156
public function commit(): void
5257
{
5358
$request = $this->requestFactory->buildCommitRequest($this->transactionId, $this->clusterAffinity);
54-
5559
$this->client->sendRequest($request);
5660
}
5761

@@ -61,7 +65,6 @@ public function commit(): void
6165
public function rollback(): void
6266
{
6367
$request = $this->requestFactory->buildRollbackRequest($this->transactionId, $this->clusterAffinity);
64-
6568
$this->client->sendRequest($request);
6669
}
6770

@@ -72,7 +75,9 @@ public function rollback(): void
7275
*/
7376
private function handleRequestException(RequestExceptionInterface $e): void
7477
{
75-
$response = $e->getResponse();
78+
// ✅ Corrected: Check if exception has a response
79+
$response = method_exists($e, 'getResponse') ? $e->getResponse() : null;
80+
7681
if ($response instanceof ResponseInterface) {
7782
$errorResponse = json_decode((string)$response->getBody(), true);
7883
throw Neo4jException::fromNeo4jResponse($errorResponse, $e);

0 commit comments

Comments
 (0)