Skip to content

Commit 2a45374

Browse files
author
Wout Gevaert
committed
Do not allow deletion of Nodes, only of Variables
As per the documentation, https://neo4j.com/docs/cypher-manual/4.4/clauses/delete/ there is only variables in there.
1 parent 9b8ab6b commit 2a45374

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

src/Clauses/DeleteClause.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
namespace WikibaseSolutions\CypherDSL\Clauses;
2323

2424
use WikibaseSolutions\CypherDSL\Types\AnyType;
25-
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\NodeType;
25+
use WikibaseSolutions\CypherDSL\Variable;
2626

2727
/**
2828
* This class represents a DELETE clause.
@@ -39,11 +39,11 @@ class DeleteClause extends Clause
3939
private bool $detach = false;
4040

4141
/**
42-
* The nodes that needs to be deleted.
42+
* The variables that needs to be deleted.
4343
*
44-
* @var AnyType[] $nodes
44+
* @var Variable[] $variables
4545
*/
46-
private array $nodes = [];
46+
private array $variables = [];
4747

4848
/**
4949
* Sets the clause to DETACH DELETE. Without DETACH DELETE, all relationships need to be explicitly
@@ -60,14 +60,14 @@ public function setDetach(bool $detach = true): self
6060
}
6161

6262
/**
63-
* Add the node to be deleted. The expression must return a node when evaluated.
63+
* Add the variable to be deleted. The expression must return a node when evaluated.
6464
*
65-
* @param NodeType $node Expression that returns the node to be deleted
65+
* @param Variable $variable The name of the object that should be deleted
6666
* @return DeleteClause
6767
*/
68-
public function addNode(NodeType $node): self
68+
public function addVariable(Variable $variable): self
6969
{
70-
$this->nodes[] = $node;
70+
$this->variables[] = $variable;
7171

7272
return $this;
7373
}
@@ -83,13 +83,13 @@ public function detachesDeletion(): bool
8383
}
8484

8585
/**
86-
* Returns the nodes to delete.
86+
* Returns the variables to delete.
8787
*
88-
* @return AnyType[]
88+
* @return Variable[]
8989
*/
90-
public function getNodes(): array
90+
public function getVariables(): array
9191
{
92-
return $this->nodes;
92+
return $this->variables;
9393
}
9494

9595
/**
@@ -111,7 +111,7 @@ protected function getSubject(): string
111111
{
112112
return implode(
113113
", ",
114-
array_map(fn (NodeType $node) => $node->toQuery(), $this->nodes)
114+
array_map(fn (Variable $variable) => $variable->toQuery(), $this->variables)
115115
);
116116
}
117117
}

src/Query.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -311,24 +311,24 @@ public function create($patterns): self
311311
/**
312312
* Creates the DELETE clause.
313313
*
314-
* @param NodeType|NodeType[] $nodes The nodes to delete
314+
* @param Variable|Variable[] $nodes The nodes to delete
315315
*
316316
* @return $this
317317
* @see https://neo4j.com/docs/cypher-manual/current/clauses/delete/
318318
*
319319
*/
320-
public function delete($nodes): self
320+
public function delete($variables): self
321321
{
322322
$deleteClause = new DeleteClause();
323323

324-
if (!is_array($nodes)) {
325-
$nodes = [$nodes];
324+
if (!is_array($variables)) {
325+
$variables = [$variables];
326326
}
327327

328-
foreach ($nodes as $node) {
329-
$this->assertClass('node', NodeType::class, $node);
328+
foreach ($variables as $variable) {
329+
$this->assertClass('variable', Variable::class, $variable);
330330

331-
$deleteClause->addNode($node);
331+
$deleteClause->addVariable($variable);
332332
}
333333

334334
$this->clauses[] = $deleteClause;
@@ -339,25 +339,25 @@ public function delete($nodes): self
339339
/**
340340
* Creates the DETACH DELETE clause.
341341
*
342-
* @param NodeType|NodeType[] $nodes The nodes to delete
342+
* @param Variable|Variable[] $variables The variables to delete, including relationships
343343
*
344344
* @return $this
345345
* @see https://neo4j.com/docs/cypher-manual/current/clauses/delete/
346346
*
347347
*/
348-
public function detachDelete($nodes): self
348+
public function detachDelete($variables): self
349349
{
350350
$deleteClause = new DeleteClause();
351351
$deleteClause->setDetach(true);
352352

353-
if (!is_array($nodes)) {
354-
$nodes = [$nodes];
353+
if (!is_array($variables)) {
354+
$variables = [$variables];
355355
}
356356

357-
foreach ($nodes as $node) {
358-
$this->assertClass('node', NodeType::class, $node);
357+
foreach ($variables as $variable) {
358+
$this->assertClass('variable', Variable::class, $variable);
359359

360-
$deleteClause->addNode($node);
360+
$deleteClause->addVariable($variable);
361361
}
362362

363363
$this->clauses[] = $deleteClause;

0 commit comments

Comments
 (0)