Skip to content

Commit a4acd18

Browse files
committed
if statement of str_starts_with is refactored
1 parent ac9a927 commit a4acd18

File tree

3 files changed

+3
-21
lines changed

3 files changed

+3
-21
lines changed

src/Exception/Neo4jException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public function __construct(
3939
public static function fromNeo4jResponse(array $response, ?\Throwable $exception = null): self
4040
{
4141
$errorDetails = $response['errors'][0] ?? ['message' => 'Unknown error', 'code' => 'Neo.UnknownError'];
42-
$statusCode = $response['statusCode'] ?? 0;
4342

44-
return new self($errorDetails, (int)$statusCode, $exception);
43+
44+
return new self($errorDetails, previous: $exception);
4545
}
4646

4747
public function getErrorCode(): string

src/Neo4jQueryAPI.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,14 @@ public static function login(string $address, string $username, string $password
5757
*/
5858
public function run(string $cypher, array $parameters = [], string $database = 'neo4j', Bookmarks $bookmark = null, ?string $impersonatedUser = null, AccessMode $accessMode = AccessMode::WRITE): ResultSet
5959
{
60-
$validAccessModes = ['READ', 'WRITE', 'ROUTE'];
61-
6260
try {
63-
// Create the payload for the request
6461
$payload = [
6562
'statement' => $cypher,
6663
'parameters' => empty($parameters) ? new stdClass() : $parameters,
6764
'includeCounters' => true,
6865
'accessMode' => $accessMode->value,
6966
];
7067

71-
error_log("Request Payload: " . json_encode($payload));
7268

7369
if ($bookmark !== null) {
7470
$payload['bookmarks'] = $bookmark->getBookmarks();
@@ -77,13 +73,6 @@ public function run(string $cypher, array $parameters = [], string $database = '
7773
$payload['impersonatedUser'] = $impersonatedUser;
7874
}
7975

80-
if ($accessMode === AccessMode::READ && str_starts_with(strtoupper($cypher), 'CREATE')) {
81-
throw new Neo4jException([
82-
'code' => 'Neo.ClientError.Statement.AccessMode',
83-
'message' => "Attempted write operation in READ access mode."
84-
]);
85-
}
86-
8776
$response = $this->client->post('/db/' . $database . '/query/v2', [
8877
'json' => $payload,
8978
]);
@@ -126,7 +115,6 @@ public function run(string $cypher, array $parameters = [], string $database = '
126115
systemUpdates: $data['counters']['systemUpdates'] ?? 0
127116
);
128117

129-
// Return the result set object
130118
return new ResultSet(
131119
$rows,
132120
$resultCounters,
@@ -139,10 +127,7 @@ public function run(string $cypher, array $parameters = [], string $database = '
139127

140128
$response = $e->getResponse();
141129
if ($response !== null) {
142-
// Log the error response details
143130
$contents = $response->getBody()->getContents();
144-
error_log("Error Response: " . $contents);
145-
146131
$errorResponse = json_decode($contents, true);
147132
throw Neo4jException::fromNeo4jResponse($errorResponse, $e);
148133
}

tests/Integration/Neo4jQueryAPIIntegrationTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,6 @@ public function testImpersonatedUserSuccess(): void
211211
$impersonatedUser = $result->getImpersonatedUser();
212212
$this->assertNotNull($impersonatedUser, "Impersonated user should not be null.");
213213

214-
//A user being impersonated (ImpersonatedUser) might have other users who are being impersonated through it, forming a chain or hierarchy.
215-
216214
}
217215

218216

@@ -256,14 +254,13 @@ public function testRunWithReadAccessMode(): void
256254
null,
257255
AccessMode::READ
258256
);
259-
//(unacceptance test)
260257
}
261258

262259

263260
public function testReadModeWithWriteQuery(): void
264261
{
265262
$this->expectException(Neo4jException::class);
266-
$this->expectExceptionMessage("Attempted write operation in READ access mode.");
263+
$this->expectExceptionMessage("Writing in read access mode not allowed. Attempted write to neo4j");
267264

268265
$this->api->run(
269266
"CREATE (n:Test {name: 'Test Node'})",

0 commit comments

Comments
 (0)