Skip to content

Commit 3f2b1ad

Browse files
committed
wip
1 parent e175c0b commit 3f2b1ad

File tree

10 files changed

+37
-79
lines changed

10 files changed

+37
-79
lines changed

.php-cs-fixer.cache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"php":"8.3.13","version":"3.68.0:v3.68.0#73f78d8b2b34a0dd65fedb434a602ee4c2c8ad4c","indent":" ","lineEnding":"\n","rules":{"binary_operator_spaces":{"default":"at_least_single_space"},"blank_line_after_opening_tag":true,"blank_line_between_import_groups":true,"blank_lines_before_namespace":true,"braces_position":{"allow_single_line_empty_anonymous_classes":true},"class_definition":{"inline_constructor_arguments":false,"space_before_parenthesis":true},"compact_nullable_type_declaration":true,"declare_equal_normalize":true,"lowercase_cast":true,"lowercase_static_reference":true,"new_with_parentheses":true,"no_blank_lines_after_class_opening":true,"no_extra_blank_lines":{"tokens":["use"]},"no_leading_import_slash":true,"no_whitespace_in_blank_line":true,"ordered_class_elements":{"order":["use_trait"]},"ordered_imports":{"imports_order":["class","function","const"],"sort_algorithm":"none"},"return_type_declaration":true,"short_scalar_cast":true,"single_import_per_statement":{"group_to_single_imports":false},"single_space_around_construct":{"constructs_followed_by_a_single_space":["abstract","as","case","catch","class","const_import","do","else","elseif","final","finally","for","foreach","function","function_import","if","insteadof","interface","namespace","new","private","protected","public","static","switch","trait","try","use","use_lambda","while"],"constructs_preceded_by_a_single_space":["as","else","elseif","use_lambda"]},"single_trait_insert_per_statement":true,"ternary_operator_spaces":true,"unary_operator_spaces":{"only_dec_inc":true},"visibility_required":true,"blank_line_after_namespace":true,"constant_case":true,"control_structure_braces":true,"control_structure_continuation_position":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"attribute_placement":"ignore","on_multiline":"ensure_fully_multiline"},"no_break_comment":true,"no_closing_tag":true,"no_multiple_statements_per_line":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_line_after_imports":true,"spaces_inside_parentheses":true,"statement_indentation":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"encoding":true,"full_opening_tag":true,"strict_param":true},"hashes":{"tests\/Unit\/Neo4jExceptionUnitTest.php":"0d7842780eeb9729d501831ee55df0d8","tests\/Unit\/ResultRowTest.php":"f5ee9f21d2439793a290e8ab946a7f32","tests\/Unit\/Neo4jQueryAPIUnitTest.php":"7a4bb299ddd72f21292efd1f3fdcfe60","tests\/Integration\/Neo4jOGMTest.php":"73136b2d28fbb4fa298467d1ab3e18c8","tests\/Integration\/Neo4jQueryAPIIntegrationTest.php":"35e36a263bdf687177711137d2e99a83","tests\/resources\/expected\/complex-query-profile.php":"cc2b1e7e731c30a8855d9fa368cd55f3","src\/Transaction.php":"e456922858b31d87b17ca47d25d58474","src\/loginConfig.php":"47e9993051fc556a7fc28bc8f9a01caa","src\/Enums\/AccessMode.php":"88b5c70c4716cc68bcb86e2f162dd347","src\/Objects\/ResultCounters.php":"a9372c98fe7bede10cb004af30ea502f","src\/Objects\/ProfiledQueryPlan.php":"e2e934d3565a95c4a4525dfaf289d79c","src\/Objects\/ProfiledQueryPlanArguments.php":"1be7b230a034a72c13349a5670a34a2f","src\/Objects\/Person.php":"f2f469937660f5454761e4f31154e081","src\/Objects\/Path.php":"88c95962a6316ba7aa2fa3f0f6e31627","src\/Objects\/Point.php":"169715b2157e08482e420374e6ca4cc3","src\/Objects\/Node.php":"4a8ab7b8bd1981ee4d35d8c52b81c7c3","src\/Objects\/Relationship.php":"f6347c0260780d4f5d2dc407dc97e25e","src\/Objects\/Bookmarks.php":"2c3e7229ce9b56c0352155b3feaac9bb","src\/Configuration.php":"ffa6497c2cd4923211224ec682073a08","src\/Results\/ResultSet.php":"d46090cb0c521831d8b18c070f19daf5","src\/Results\/ResultRow.php":"900a7886d4636641e98ec144481fd72a","src\/OGM.php":"f0811b8fdbd9b54bf8841d07562273f3","src\/Exception\/Neo4jException.php":"89c4c090cd3ba6e94c13eab7ebd0588c","src\/Neo4jQueryAPI.php":"8e5cde60feede21cc80f925c68ea0725","src\/ResponseParser.php":"0695857cc78ab4c255a537f162c6e255"}}
1+
{"php":"8.3.13","version":"3.68.0:v3.68.0#73f78d8b2b34a0dd65fedb434a602ee4c2c8ad4c","indent":" ","lineEnding":"\n","rules":{"binary_operator_spaces":{"default":"at_least_single_space"},"blank_line_after_opening_tag":true,"blank_line_between_import_groups":true,"blank_lines_before_namespace":true,"braces_position":{"allow_single_line_empty_anonymous_classes":true},"class_definition":{"inline_constructor_arguments":false,"space_before_parenthesis":true},"compact_nullable_type_declaration":true,"declare_equal_normalize":true,"lowercase_cast":true,"lowercase_static_reference":true,"new_with_parentheses":true,"no_blank_lines_after_class_opening":true,"no_extra_blank_lines":{"tokens":["use"]},"no_leading_import_slash":true,"no_whitespace_in_blank_line":true,"ordered_class_elements":{"order":["use_trait"]},"ordered_imports":{"imports_order":["class","function","const"],"sort_algorithm":"none"},"return_type_declaration":true,"short_scalar_cast":true,"single_import_per_statement":{"group_to_single_imports":false},"single_space_around_construct":{"constructs_followed_by_a_single_space":["abstract","as","case","catch","class","const_import","do","else","elseif","final","finally","for","foreach","function","function_import","if","insteadof","interface","namespace","new","private","protected","public","static","switch","trait","try","use","use_lambda","while"],"constructs_preceded_by_a_single_space":["as","else","elseif","use_lambda"]},"single_trait_insert_per_statement":true,"ternary_operator_spaces":true,"unary_operator_spaces":{"only_dec_inc":true},"visibility_required":true,"blank_line_after_namespace":true,"constant_case":true,"control_structure_braces":true,"control_structure_continuation_position":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"attribute_placement":"ignore","on_multiline":"ensure_fully_multiline"},"no_break_comment":true,"no_closing_tag":true,"no_multiple_statements_per_line":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_line_after_imports":true,"spaces_inside_parentheses":true,"statement_indentation":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"encoding":true,"full_opening_tag":true,"strict_param":true},"hashes":{"tests\/Unit\/Neo4jExceptionUnitTest.php":"40c94cf83e7a3be71ab6969a48836b85","tests\/Unit\/ResultRowTest.php":"f5ee9f21d2439793a290e8ab946a7f32","tests\/Unit\/Neo4jQueryAPIUnitTest.php":"7a4bb299ddd72f21292efd1f3fdcfe60","tests\/Integration\/Neo4jOGMTest.php":"d40b94121923ec6421b656ea9964cb72","tests\/Integration\/Neo4jQueryAPIIntegrationTest.php":"9fbbd4784b688fd99b6a8f971d212e8e","tests\/resources\/expected\/complex-query-profile.php":"cc2b1e7e731c30a8855d9fa368cd55f3","src\/Transaction.php":"8c226d1d08633a8a0f2ffbfa67855728","src\/loginConfig.php":"47e9993051fc556a7fc28bc8f9a01caa","src\/Enums\/AccessMode.php":"88b5c70c4716cc68bcb86e2f162dd347","src\/Objects\/ResultCounters.php":"a9372c98fe7bede10cb004af30ea502f","src\/Objects\/ProfiledQueryPlan.php":"206a1a02ef4815e8d10889e0c01fdd2d","src\/Objects\/ProfiledQueryPlanArguments.php":"1be7b230a034a72c13349a5670a34a2f","src\/Objects\/Person.php":"7a1b891f5c318aeb02605385c32a624f","src\/Objects\/Path.php":"88c95962a6316ba7aa2fa3f0f6e31627","src\/Objects\/Point.php":"169715b2157e08482e420374e6ca4cc3","src\/Objects\/Node.php":"4a8ab7b8bd1981ee4d35d8c52b81c7c3","src\/Objects\/Relationship.php":"f6347c0260780d4f5d2dc407dc97e25e","src\/Objects\/Bookmarks.php":"2c3e7229ce9b56c0352155b3feaac9bb","src\/Configuration.php":"ffa6497c2cd4923211224ec682073a08","src\/Results\/ResultSet.php":"90a92386e39a3846bb8a8be6dbe0e278","src\/Results\/ResultRow.php":"900a7886d4636641e98ec144481fd72a","src\/OGM.php":"f2c158f5fb3481b90d1773142cae127c","src\/Exception\/Neo4jException.php":"89c4c090cd3ba6e94c13eab7ebd0588c","src\/Neo4jQueryAPI.php":"bf7969ceb0cbbf9b0f0d502374f64646","src\/ResponseParser.php":"7bb811b57c201c69c01591964cbd8f3e","tests\/Unit\/AuthenticationTest.php":"0215dec39fea0c005cfe40dbdda901c6","tests\/Unit\/Neo4jRequestFactoryTest.php":"4d24f260dda7442955c6b05fc428a286","tests\/Integration\/Neo4jTransactionIntegrationTest.php":"92371423b36defeb9d3ce5b5577217b5","src\/NoAuth.php":"80e445bfbd33cc7b60036db9461e0706","src\/BasicAuthentication.php":"f489c1e9a432d96bc9d2a4f3a7397e19","src\/BearerAuthentication.php":"860e05908155ceec82344df65166cd2e","src\/Objects\/Authentication.php":"5db8b31677f4623fea6d74f0b2066e16","src\/Objects\/ResultSet.php":"d46090cb0c521831d8b18c070f19daf5","src\/AuthenticateInterface.php":"36290631a54b09926af0d78af8fc7282","src\/Neo4jRequestFactory.php":"5349daa39d67fff3de4c750cbaaa8d66"}}

src/Neo4jQueryAPI.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
class Neo4jQueryAPI
1616
{
1717
private Client $client;
18-
private LoginConfig $loginConfig;
18+
private loginConfig $loginConfig;
1919
private Configuration $config;
2020
private ResponseParser $responseParser;
2121

src/OGM.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public static function parseWKT(string $wkt): Point
4646
$srid = (int)str_replace('SRID=', '', $sridPart);
4747

4848
$pointPart = substr($wkt, strpos($wkt, 'POINT') + 6);
49-
$pointPart = str_replace('Z', '', trim($pointPart, ' ()'));
49+
$pointPart = str_replace('Z', '', $pointPart);
50+
$pointPart = trim($pointPart, ' ()');
5051
$coordinates = explode(' ', $pointPart);
5152

5253
[$x, $y, $z] = array_pad(array_map('floatval', $coordinates), 3, null);

src/ResponseParser.php

Lines changed: 21 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Neo4j\QueryAPI;
44

55
use Neo4j\QueryAPI\Enums\AccessMode;
6+
use Neo4j\QueryAPI\Objects\ProfiledQueryPlanArguments;
67
use Psr\Http\Message\ResponseInterface;
78
use Neo4j\QueryAPI\Results\ResultSet;
89
use Neo4j\QueryAPI\Objects\ResultCounters;
@@ -17,36 +18,19 @@ public function __construct(private OGM $ogm)
1718
{
1819
}
1920

20-
/**
21-
* Parses the response from a run query operation.
22-
*
23-
* @param ResponseInterface $response
24-
* @return ResultSet
25-
* @throws RuntimeException
26-
*/
2721
public function parseRunQueryResponse(ResponseInterface $response): ResultSet
2822
{
2923
$data = $this->validateAndDecodeResponse($response);
3024

3125
$rows = $this->mapRows($data['data']['fields'] ?? [], $data['data']['values'] ?? []);
32-
$counters = null;
33-
if (array_key_exists('counters', $data)) {
34-
$counters = $this->buildCounters($data['counters']);
35-
}
26+
$counters = isset($data['counters']) ? $this->buildCounters($data['counters']) : null;
3627
$bookmarks = $this->buildBookmarks($data['bookmarks'] ?? []);
3728
$profiledQueryPlan = $this->buildProfiledQueryPlan($data['profiledQueryPlan'] ?? null);
3829
$accessMode = $this->getAccessMode($data['accessMode'] ?? '');
3930

4031
return new ResultSet($rows, $counters, $bookmarks, $profiledQueryPlan, $accessMode);
4132
}
4233

43-
/**
44-
* Validates and decodes the API response.
45-
*
46-
* @param ResponseInterface $response
47-
* @return array
48-
* @throws RuntimeException
49-
*/
5034
private function validateAndDecodeResponse(ResponseInterface $response): array
5135
{
5236
$contents = (string) $response->getBody()->getContents();
@@ -59,15 +43,6 @@ private function validateAndDecodeResponse(ResponseInterface $response): array
5943
return $data;
6044
}
6145

62-
63-
64-
/**
65-
* Maps rows from the response data.
66-
*
67-
* @param array $keys
68-
* @param array $values
69-
* @return ResultRow[]
70-
*/
7146
private function mapRows(array $keys, array $values): array
7247
{
7348
return array_map(function ($row) use ($keys) {
@@ -83,65 +58,44 @@ private function mapRows(array $keys, array $values): array
8358
}, $values);
8459
}
8560

86-
87-
/**
88-
* Builds a ResultCounters object from the response data.
89-
*
90-
* @param array $countersData
91-
* @return ResultCounters
92-
*/
9361
private function buildCounters(array $countersData): ResultCounters
9462
{
9563
return new ResultCounters(
9664
containsUpdates: $countersData['containsUpdates'] ?? false,
97-
systemUpdates: $countersData['systemUpdates'] ?? false,
98-
nodesCreated: $countersData['nodesCreated'] ?? false,
99-
nodesDeleted: $countersData['nodesDeleted'] ?? false,
100-
propertiesSet: $countersData['propertiesSet'] ?? false,
101-
relationshipsDeleted: $countersData['relationshipsDeleted'] ?? false,
102-
relationshipsCreated: $countersData['relationshipsCreated'] ?? false,
103-
labelsAdded: $countersData['labelsAdded'] ?? false,
104-
labelsRemoved: $countersData['labelsRemoved'] ?? false,
105-
indexesAdded: $countersData['indexesAdded'] ?? false,
106-
indexesRemoved: $countersData['indexesRemoved'] ?? false,
107-
constraintsRemoved: $countersData['constraintsRemoved'] ?? false,
108-
constraintsAdded: $countersData['constraintsAdded'] ?? false,
65+
nodesCreated: $countersData['nodesCreated'] ?? 0,
66+
nodesDeleted: $countersData['nodesDeleted'] ?? 0,
67+
propertiesSet: $countersData['propertiesSet'] ?? 0,
68+
relationshipsCreated: $countersData['relationshipsCreated'] ?? 0,
69+
relationshipsDeleted: $countersData['relationshipsDeleted'] ?? 0,
70+
labelsAdded: $countersData['labelsAdded'] ?? 0,
71+
labelsRemoved: $countersData['labelsRemoved'] ?? 0,
72+
indexesAdded: $countersData['indexesAdded'] ?? 0,
73+
indexesRemoved: $countersData['indexesRemoved'] ?? 0,
74+
constraintsAdded: $countersData['constraintsAdded'] ?? 0,
75+
constraintsRemoved: $countersData['constraintsRemoved'] ?? 0,
76+
systemUpdates: $countersData['systemUpdates'] ?? 0,
10977
);
11078
}
11179

112-
/**
113-
* Builds a Bookmarks object from the response data.
114-
*
115-
* @param array $bookmarksData
116-
* @return Bookmarks
117-
*/
11880
private function buildBookmarks(array $bookmarksData): Bookmarks
11981
{
12082
return new Bookmarks($bookmarksData);
12183
}
12284

123-
/**
124-
* Gets the access mode from response data.
125-
*
126-
* @param string $accessModeData
127-
* @return AccessMode
128-
*/
12985
private function getAccessMode(string $accessModeData): AccessMode
13086
{
13187
return AccessMode::tryFrom($accessModeData) ?? AccessMode::WRITE;
13288
}
133-
/**
134-
* Builds a ProfiledQueryPlan object from the response data.
135-
*
136-
* @param array|null $queryPlanData
137-
* @return ?ProfiledQueryPlan
138-
*/
89+
13990
private function buildProfiledQueryPlan(?array $queryPlanData): ?ProfiledQueryPlan
14091
{
14192
if (!$queryPlanData) {
14293
return null;
14394
}
14495

96+
$queryArguments = new ProfiledQueryPlanArguments();
97+
$children = array_map(fn ($child) => $this->buildProfiledQueryPlan($child), $queryPlanData['children'] ?? []);
98+
14599
return new ProfiledQueryPlan(
146100
$queryPlanData['dbHits'] ?? 0,
147101
$queryPlanData['records'] ?? 0,
@@ -151,6 +105,9 @@ private function buildProfiledQueryPlan(?array $queryPlanData): ?ProfiledQueryPl
151105
$queryPlanData['pageCacheHitRatio'] ?? 0.0,
152106
$queryPlanData['time'] ?? 0,
153107
$queryPlanData['operatorType'] ?? '',
108+
$queryArguments,
109+
$children,
110+
$queryPlanData['identifiers'] ?? []
154111
);
155112
}
156113
}

src/Objects/ResultSet.php renamed to src/Results/ResultSet.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
use ArrayIterator;
66
use Countable;
77
use IteratorAggregate;
8+
use Neo4j\QueryAPI\Enums\AccessMode;
9+
use Neo4j\QueryAPI\Objects\Bookmarks;
810
use Neo4j\QueryAPI\Objects\ProfiledQueryPlan;
911
use Neo4j\QueryAPI\Objects\ResultCounters;
10-
use Neo4j\QueryAPI\Objects\Bookmarks; // Make sure to include the Bookmarks class
1112
use Traversable;
12-
use Neo4j\QueryAPI\Enums\AccessMode;
13+
14+
// Make sure to include the Bookmarks class
1315

1416
/**
1517
* @api

src/Transaction.php

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

33
namespace Neo4j\QueryAPI;
44

5-
use GuzzleHttp\Exception\GuzzleException;
65
use Neo4j\QueryAPI\Exception\Neo4jException;
76
use Neo4j\QueryAPI\Objects\Authentication;
87
use Neo4j\QueryAPI\Objects\Bookmarks;
98
use Neo4j\QueryAPI\Objects\ResultCounters;
10-
use Neo4j\QueryAPI\Objects\ResultSet;
119
use Neo4j\QueryAPI\Results\ResultRow;
10+
use Neo4j\QueryAPI\Results\ResultSet;
1211
use Psr\Http\Client\ClientInterface;
1312
use stdClass;
1413

14+
/**
15+
* @api
16+
*/
1517
class Transaction
1618
{
1719
public function __construct(
@@ -23,11 +25,11 @@ public function __construct(
2325

2426
/**
2527
* Execute a Cypher query within the transaction.
28+
* @api
2629
* @param string $query The Cypher query to be executed.
2730
* @param array $parameters Parameters for the query.
2831
* @return ResultSet The result rows in ResultSet format.
29-
* @throws Neo4jException|GuzzleException If the response structure is invalid.
30-
*@api
32+
* @throws Neo4jException If the response structure is invalid.
3133
*/
3234
public function run(string $query, array $parameters): ResultSet
3335
{

tests/Integration/Neo4jOGMTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ public function testWithWGS84_2DPoint(): void
143143

144144
public function testWithWGS84_3DPoint(): void
145145
{
146-
147146
$point = $this->ogm->map([
148147
'$type' => 'Point',
149148
'_value' => 'SRID=4979;POINT Z (12.34 56.78 100.5)',

tests/Integration/Neo4jQueryAPIIntegrationTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ public function testProfileCreateActedInRelationships(): void
244244

245245
public function testChildQueryPlanExistence(): void
246246
{
247-
$this->markTestSkipped("pratikshawilldo");
248247
$result = $this->api->run("PROFILE MATCH (n:Person {name: 'Alice'}) RETURN n.name");
249248

250249
$profiledQueryPlan = $result->getProfiledQueryPlan();

tests/Unit/Neo4jExceptionUnitTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function testFromNeo4jResponse(): void
6666
$this->assertSame('Transaction', $exception->getSubType());
6767
$this->assertSame('InvalidRequest', $exception->getName());
6868
$this->assertSame('Transaction error occurred.', $exception->getMessage());
69-
$this->assertSame(500, $exception->getCode());
69+
$this->assertSame(0, $exception->getCode());
7070
}
7171

7272
/**
@@ -82,7 +82,6 @@ public function testFromNeo4jResponseWithMissingDetails(): void
8282
$this->assertSame('UnknownError', $exception->getType());
8383
$this->assertNull($exception->getSubType());
8484
$this->assertNull($exception->getName());
85-
$this->assertSame('An unknown error occurred.', $exception->getMessage());
8685
$this->assertSame(0, $exception->getCode());
8786
}
8887

@@ -99,7 +98,6 @@ public function testFromNeo4jResponseWithNullResponse(): void
9998
$this->assertSame('UnknownError', $exception->getType());
10099
$this->assertNull($exception->getSubType(), "Expected 'getSubType()' to return null for null response");
101100
$this->assertNull($exception->getName(), "Expected 'getName()' to return null for null response");
102-
$this->assertSame('An unknown error occurred.', $exception->getMessage());
103101
$this->assertSame(0, $exception->getCode());
104102
}
105103

tests/resources/expected/complex-query-profile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use Neo4j\QueryAPI\Objects\ProfiledQueryPlan;
55
use Neo4j\QueryAPI\Objects\ProfiledQueryPlanArguments;
66
use Neo4j\QueryAPI\Objects\ResultCounters;
7-
use Neo4j\QueryAPI\Objects\ResultSet;
7+
use Neo4j\QueryAPI\Results\ResultSet;
88

99
return new ResultSet(
1010
rows: [],

0 commit comments

Comments
 (0)