Skip to content

Commit 8d17d72

Browse files
committed
Simplified relationship
1 parent 5b62dd8 commit 8d17d72

File tree

1 file changed

+2
-61
lines changed

1 file changed

+2
-61
lines changed

src/Patterns/Relationship.php

Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
use WikibaseSolutions\CypherDSL\Traits\EscapeTrait;
2929
use WikibaseSolutions\CypherDSL\Traits\RelationshipTrait;
3030
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\RelationshipType;
31-
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\StructuralType;
3231

3332
/**
3433
* This class represents an arbitrary relationship between two nodes, a node and a
@@ -45,16 +44,6 @@ class Relationship implements RelationshipType
4544
public const DIR_LEFT = ["<-", "-"];
4645
public const DIR_UNI = ["-", "-"];
4746

48-
/**
49-
* @var StructuralType The pattern left of the relationship
50-
*/
51-
private StructuralType $left;
52-
53-
/**
54-
* @var StructuralType The pattern right of the relationship
55-
*/
56-
private StructuralType $right;
57-
5847
/**
5948
* @var string[] The direction of the relationship
6049
*/
@@ -83,19 +72,14 @@ class Relationship implements RelationshipType
8372
/**
8473
* Path constructor.
8574
*
86-
* @param StructuralType $left The node left of the relationship
87-
* @param StructuralType $right The node right of the relationship
8875
* @param array $direction The direction of the relationship, should be either:
8976
* - Path::DIR_RIGHT (for a relation of
9077
* (a)-->(b)) - Path::DIR_LEFT (for a relation
9178
* of (a)<--(b)) - Path::DIR_UNI (for a
9279
* relation of (a)--(b))
9380
*/
94-
public function __construct(StructuralType $left, StructuralType $right, array $direction)
81+
public function __construct(array $direction)
9582
{
96-
$this->left = $left;
97-
$this->right = $right;
98-
9983
if ($direction !== self::DIR_RIGHT && $direction !== self::DIR_LEFT && $direction !== self::DIR_UNI) {
10084
throw new InvalidArgumentException("The direction must be either 'DIR_LEFT', 'DIR_RIGHT' or 'RELATED_TO'");
10185
}
@@ -199,10 +183,7 @@ public function withType(string $type): self
199183
*/
200184
public function toQuery(): string
201185
{
202-
$a = $this->left->toQuery();
203-
$b = $this->right->toQuery();
204-
205-
return $a . $this->toRelationshipQuery() . $b;
186+
return $this->direction[0] . $this->conditionToString() . $this->direction[1];
206187
}
207188

208189
/**
@@ -254,36 +235,6 @@ private function conditionToString(): string
254235
return sprintf("[%s]", $conditionInner);
255236
}
256237

257-
/**
258-
* Returns the left structure of the relationship.
259-
*
260-
* @return StructuralType
261-
*/
262-
public function getLeft(): StructuralType
263-
{
264-
return $this->left;
265-
}
266-
267-
/**
268-
* Returns the right structure of the relationship.
269-
*
270-
* @return StructuralType
271-
*/
272-
public function getRight(): StructuralType
273-
{
274-
return $this->right;
275-
}
276-
277-
/**
278-
* Returns the direction of the path.
279-
*
280-
* @return string[]
281-
*/
282-
public function getDirection(): array
283-
{
284-
return $this->direction;
285-
}
286-
287238
/**
288239
* Returns the exact amount of hops configured.
289240
*
@@ -328,14 +279,4 @@ public function property(string $property): Property
328279
{
329280
return new Property($this->getName(), $property);
330281
}
331-
332-
/**
333-
* Returns the relationship part of the pattern without the nodes.
334-
*
335-
* @return string
336-
*/
337-
public function toRelationshipQuery(): string
338-
{
339-
return $this->direction[0] . $this->conditionToString() . $this->direction[1];
340-
}
341282
}

0 commit comments

Comments
 (0)