Skip to content

Commit 75e4f34

Browse files
committed
upgrade to cypher datastructures 0.2.0 wip
1 parent 37cdbcc commit 75e4f34

20 files changed

+211
-209
lines changed

src/EventListener/Neo4j/NodeConstraintCreateToStatementEventListener.php

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,32 +41,29 @@ public function onActionCypherElementToStatementEvent(ActionCypherElementToState
4141

4242
public static function nodeConstraintStatement(NodeConstraintInterface $nodeConstraint): Statement
4343
{
44-
$constraintName = $nodeConstraint->getName();
45-
if (null === $constraintName) {
44+
$name = $nodeConstraint->getName();
45+
if (!$name) {
4646
throw InvalidArgumentException::createForConstraintNameIsNull();
4747
}
48-
$elementLabel = $nodeConstraint->getFor();
49-
if (null === $elementLabel) {
48+
$label = $nodeConstraint->getFor();
49+
if (!$label) {
5050
throw InvalidArgumentException::createForConstraintForIsNull();
5151
}
52-
$elementIdentifier = '(e:'.$elementLabel.')';
53-
$propertyIdentifier = '';
5452
$properties = [];
5553
foreach ($nodeConstraint->getProperties() as $propertyName) {
56-
$properties[] = 'e.'.((string) $propertyName);
57-
$propertyIdentifier = '('.join(', ', $properties).')';
54+
$properties[] = sprintf("e.%s", $propertyName);
5855
}
59-
$constraintType = $nodeConstraint->getType();
60-
if (null === $constraintType) {
56+
$type = $nodeConstraint->getType();
57+
if (!$type) {
6158
throw InvalidArgumentException::createForConstraintTypeIsNull();
6259
}
6360

6461
return new Statement(sprintf(
65-
"CREATE CONSTRAINT %s FOR %s REQUIRE %s IS %s",
66-
$constraintName,
67-
$elementIdentifier,
68-
$propertyIdentifier,
69-
$constraintType
62+
"CREATE CONSTRAINT %s FOR (e:%s) REQUIRE (%s) IS %s",
63+
$name,
64+
$label,
65+
join(', ', $properties),
66+
$type
7067
), []);
7168
}
7269
}

src/EventListener/Neo4j/NodeConstraintDeleteToStatementEventListener.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ public function onActionCypherElementToStatementEvent(ActionCypherElementToState
4141

4242
public static function nodeConstraintStatement(NodeConstraintInterface $nodeConstraint): Statement
4343
{
44-
$constraintName = $nodeConstraint->getName();
45-
if (null === $constraintName) {
44+
$name = $nodeConstraint->getName();
45+
if (!$name) {
4646
throw InvalidArgumentException::createForConstraintNameIsNull();
4747
}
4848

4949
return new Statement(sprintf(
5050
"DROP CONSTRAINT %s IF EXISTS",
51-
$constraintName
51+
$name
5252
), []);
5353
}
5454
}

src/EventListener/Neo4j/NodeIndexCreateToStatementEventListener.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,32 @@ public function onActionCypherElementToStatementEvent(ActionCypherElementToState
4141

4242
public static function nodeIndexStatement(NodeIndexInterface $nodeIndex): Statement
4343
{
44-
$propertyIdentifier = '';
45-
46-
$indexType = $nodeIndex->getType();
47-
if (!$indexType) {
44+
$type = $nodeIndex->getType();
45+
if (!$type) {
4846
throw InvalidArgumentException::createForIndexTypeIsNull();
4947
}
5048

51-
$elementLabel = $nodeIndex->getFor();
52-
if (!$elementLabel) {
49+
$name = $nodeIndex->getName();
50+
if (!$name) {
51+
throw InvalidArgumentException::createForIndexNameIsNull();
52+
}
53+
54+
$label = $nodeIndex->getFor();
55+
if (!$label) {
5356
throw InvalidArgumentException::createForIndexForIsNull();
5457
}
55-
$elementIdentifier = '(e:'.$elementLabel.')';
58+
5659
$properties = [];
57-
foreach ($nodeIndex->getProperties() as $propertyName) {
58-
$properties[] = 'e.'.$propertyName;
59-
$propertyIdentifier = '('.join(', ', $properties).')';
60+
foreach ($nodeIndex->getProperties() as $propertyName => $propertyValue) {
61+
$properties[] = sprintf("e.%s", $propertyName);
6062
}
6163

62-
return new Statement(sprintf(
63-
"CREATE %s INDEX %s IF NOT EXISTS FOR %s ON %s",
64-
$indexType,
65-
$nodeIndex->getName(),
66-
$elementIdentifier,
67-
$propertyIdentifier
68-
), []);
64+
return Statement::create(sprintf(
65+
"CREATE %s INDEX %s IF NOT EXISTS FOR (e:%s) ON (%s)",
66+
$type,
67+
$name,
68+
$label,
69+
join(', ', $properties)
70+
));
6971
}
7072
}

src/EventListener/Neo4j/NodeIndexDeleteToStatementEventListener.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ public function onActionCypherElementToStatementEvent(ActionCypherElementToState
4141

4242
public static function nodeIndexStatement(NodeIndexInterface $nodeIndex): Statement
4343
{
44-
$indexName = $nodeIndex->getName();
45-
if (null === $indexName) {
44+
$name = $nodeIndex->getName();
45+
if (!$name) {
4646
throw InvalidArgumentException::createForIndexNameIsNull();
4747
}
4848

49-
return new Statement(sprintf(
49+
return Statement::create(sprintf(
5050
"DROP INDEX %s IF EXISTS",
51-
$indexName
52-
), []);
51+
$name
52+
));
5353
}
5454
}

src/EventListener/Neo4j/RelationConstraintCreateToStatementEventListener.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,31 +41,28 @@ public function onActionCypherElementToStatementEvent(ActionCypherElementToState
4141

4242
public static function relationConstraintStatement(RelationConstraintInterface $relationConstraint): Statement
4343
{
44-
$constraintName = $relationConstraint->getName();
45-
if (null === $constraintName) {
44+
$name = $relationConstraint->getName();
45+
if (!$name) {
4646
throw InvalidArgumentException::createForConstraintNameIsNull();
4747
}
48-
$elementLabel = $relationConstraint->getFor();
49-
if (null === $elementLabel) {
48+
$relationType = $relationConstraint->getFor();
49+
if (!$relationType) {
5050
throw InvalidArgumentException::createForConstraintForIsNull();
5151
}
52-
$elementIdentifier = '()-[e:'.$elementLabel.']-()';
53-
$propertyIdentifier = '';
5452
$properties = [];
5553
foreach ($relationConstraint->getProperties() as $propertyName) {
56-
$properties[] = 'e.'.((string) $propertyName);
57-
$propertyIdentifier = '('.join(', ', $properties).')';
54+
$properties[] = sprintf("e.%s", $propertyName);
5855
}
5956
$constraintType = $relationConstraint->getType();
60-
if (null === $constraintType) {
57+
if (!$constraintType) {
6158
throw InvalidArgumentException::createForConstraintTypeIsNull();
6259
}
6360

6461
return new Statement(sprintf(
65-
"CREATE CONSTRAINT %s FOR %s REQUIRE %s IS %s",
66-
$constraintName,
67-
$elementIdentifier,
68-
$propertyIdentifier,
62+
"CREATE CONSTRAINT %s FOR ()-[e:%s]-() REQUIRE (%s) IS %s",
63+
$name,
64+
$relationType,
65+
join(', ', $properties),
6966
$constraintType
7067
), []);
7168
}

src/EventListener/Neo4j/RelationConstraintDeleteToStatementEventListener.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ public function onActionCypherElementToStatementEvent(ActionCypherElementToState
4141

4242
public static function relationConstraintStatement(RelationConstraintInterface $relationConstraint): Statement
4343
{
44-
$constraintName = $relationConstraint->getName();
45-
if (null === $constraintName) {
44+
$name = $relationConstraint->getName();
45+
if (!$name) {
4646
throw InvalidArgumentException::createForConstraintNameIsNull();
4747
}
4848

4949
return new Statement(sprintf(
5050
"DROP CONSTRAINT %s IF EXISTS",
51-
$constraintName
51+
$name
5252
), []);
5353
}
5454
}

src/EventListener/Neo4j/RelationIndexCreateToStatementEventListener.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,32 @@ public function onActionCypherElementToStatementEvent(ActionCypherElementToState
4141

4242
public static function relationIndexStatement(RelationIndexInterface $relationIndex): Statement
4343
{
44-
$propertyIdentifier = '';
45-
46-
$indexType = $relationIndex->getType();
47-
if (!$indexType) {
44+
$relationType = $relationIndex->getType();
45+
if (!$relationType) {
4846
throw InvalidArgumentException::createForIndexTypeIsNull();
4947
}
5048

51-
$elementLabel = $relationIndex->getFor();
52-
if (!$elementLabel) {
49+
$name = $relationIndex->getName();
50+
if (!$name) {
51+
throw InvalidArgumentException::createForIndexNameIsNull();
52+
}
53+
54+
$indexType = $relationIndex->getFor();
55+
if (!$indexType) {
5356
throw InvalidArgumentException::createForIndexForIsNull();
5457
}
55-
$elementIdentifier = '()-[e:'.$elementLabel.']-()';
58+
5659
$properties = [];
57-
foreach ($relationIndex->getProperties() as $propertyName) {
58-
$properties[] = 'e.'.$propertyName;
59-
$propertyIdentifier = '('.join(', ', $properties).')';
60+
foreach ($relationIndex->getProperties() as $propertyName => $propertyValue) {
61+
$properties[] = sprintf("e.%s", $propertyName);
6062
}
6163

62-
return new Statement(sprintf(
63-
"CREATE %s INDEX %s IF NOT EXISTS FOR %s ON %s",
64+
return Statement::create(sprintf(
65+
"CREATE %s INDEX %s IF NOT EXISTS FOR ()-[e:%s]-() ON (%s)",
66+
$relationType,
67+
$name,
6468
$indexType,
65-
$relationIndex->getName(),
66-
$elementIdentifier,
67-
$propertyIdentifier
68-
), []);
69+
join(', ', $properties)
70+
));
6971
}
7072
}

src/EventListener/Neo4j/RelationIndexDeleteToStatementEventListener.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ public function onActionCypherElementToStatementEvent(ActionCypherElementToState
4141

4242
public static function relationIndexStatement(RelationIndexInterface $relationIndex): Statement
4343
{
44-
$indexName = $relationIndex->getName();
45-
if (null === $indexName) {
44+
$name = $relationIndex->getName();
45+
if (!$name) {
4646
throw InvalidArgumentException::createForIndexNameIsNull();
4747
}
4848

49-
return new Statement(sprintf(
49+
return Statement::create(sprintf(
5050
"DROP INDEX %s IF EXISTS",
51-
$indexName
52-
), []);
51+
$name
52+
));
5353
}
5454
}

src/EventListener/OpenCypher/NodeDeleteToStatementEventListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ public static function nodeStatement(NodeInterface $node): Statement
4747
"MATCH (node%s {%s})\n".
4848
"DETACH DELETE node",
4949
ToStringHelper::labelsToString($node->getLabels()),
50-
StructureHelper::getIdentifiersFromElementAsCypherVariableString($node, '$identifier')
50+
StructureHelper::getPropertiesAsCypherVariableString($node->getIdentifiers(), '$identifier')
5151
),
5252
[
53-
'identifier' => StructureHelper::getIdentifiersFromElementAsArray($node),
53+
'identifier' => $node->getIdentifiers(),
5454
]
5555
);
5656
}

src/EventListener/OpenCypher/NodeMergeToStatementEventListener.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ public static function nodeStatement(NodeInterface $node): Statement
4747
"MERGE (node%s {%s})\n".
4848
"SET node += \$properties",
4949
ToStringHelper::labelsToString($node->getLabels()),
50-
StructureHelper::getIdentifiersFromElementAsCypherVariableString($node, '$identifier')
50+
StructureHelper::getPropertiesAsCypherVariableString($node->getIdentifiers(), '$identifier')
5151
),
5252
[
53-
'identifier' => StructureHelper::getIdentifiersFromElementAsArray($node),
54-
'properties' => StructureHelper::getPropertiesFromElementAsArray($node),
53+
'identifier' => $node->getIdentifiers(),
54+
'properties' => $node->getProperties(),
5555
]
5656
);
5757
}

0 commit comments

Comments
 (0)