Skip to content

Commit fa80c09

Browse files
committed
implemented structural types to contain path factory methods
1 parent 8d17d72 commit fa80c09

File tree

7 files changed

+60
-86
lines changed

7 files changed

+60
-86
lines changed

src/Patterns/Node.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@
2222
namespace WikibaseSolutions\CypherDSL\Patterns;
2323

2424
use WikibaseSolutions\CypherDSL\Property;
25+
use WikibaseSolutions\CypherDSL\PropertyMap;
2526
use WikibaseSolutions\CypherDSL\Traits\EscapeTrait;
2627
use WikibaseSolutions\CypherDSL\Traits\NodeTypeTrait;
2728
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\NodeType;
29+
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\RelationshipType;
30+
use WikibaseSolutions\CypherDSL\Variable;
2831

2932
/**
3033
* This class represents a node.
@@ -109,4 +112,24 @@ public function property(string $property): Property
109112
{
110113
return new Property($this->getName(), $property);
111114
}
115+
116+
public function relationship(RelationshipType $relationship, NodeType $node): Path
117+
{
118+
return (new Path($this))->relationship($relationship, $node);
119+
}
120+
121+
public function relationshipTo(NodeType $node, $properties = null, $name = null): Path
122+
{
123+
return (new Path($this))->relationshipTo($node, $properties, $name);
124+
}
125+
126+
public function relationshipFrom(NodeType $node, $properties = null, $name = null): Path
127+
{
128+
return (new Path($this))->relationshipFrom($node, $properties, $name);
129+
}
130+
131+
public function relationshipUni(NodeType $node, $properties = null, $name = null): Path
132+
{
133+
return (new Path($this))->relationshipUni($node, $properties, $name);
134+
}
112135
}

src/Traits/NodeTypeTrait.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
*/
2727
trait NodeTypeTrait
2828
{
29-
use StructuralTypeTrait;
3029
use HasPropertiesTrait;
3130
use HasVariableTrait;
3231
}

src/Traits/StructuralTypeTrait.php

Lines changed: 0 additions & 67 deletions
This file was deleted.

src/Types/StructuralTypes/PathType.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@
2121

2222
namespace WikibaseSolutions\CypherDSL\Types\StructuralTypes;
2323

24-
use WikibaseSolutions\CypherDSL\Types\AnyType;
25-
2624
/**
2725
* Represents the type "node".
2826
*/
29-
interface PathType extends AnyType
27+
interface PathType extends StructuralType
3028
{
3129
}

src/Types/StructuralTypes/RelationshipType.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace WikibaseSolutions\CypherDSL\Types\StructuralTypes;
44

5-
interface RelationshipType extends StructuralType
5+
use WikibaseSolutions\CypherDSL\Types\AnyType;
6+
7+
interface RelationshipType extends AnyType
68
{
79

810
}

src/Types/StructuralTypes/StructuralType.php

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121

2222
namespace WikibaseSolutions\CypherDSL\Types\StructuralTypes;
2323

24+
use WikibaseSolutions\CypherDSL\Patterns\Path;
2425
use WikibaseSolutions\CypherDSL\Patterns\Relationship;
26+
use WikibaseSolutions\CypherDSL\PropertyMap;
2527
use WikibaseSolutions\CypherDSL\Types\AnyType;
28+
use WikibaseSolutions\CypherDSL\Variable;
2629

2730
/**
2831
* Represents any structural type in Cypher.
@@ -40,32 +43,48 @@
4043
* - relationship
4144
* - path
4245
*
43-
* @note This interface should not be implemented by any class directly.
4446
* @see https://neo4j.com/docs/cypher-manual/current/syntax/values/#structural-types
4547
*/
4648
interface StructuralType extends AnyType
4749
{
4850
/**
49-
* Creates a new relationship from this node to the given pattern.
51+
* Adds a new relationship from the end of the structural type to the node pattern.
52+
* @param RelationshipType $relationship
53+
* @param NodeType $node
54+
* @return Path
55+
*/
56+
public function relationship(RelationshipType $relationship, NodeType $node): Path;
57+
58+
/**
59+
* Adds a new relationship to the node pattern at the end of the structural type to form a path.
5060
*
51-
* @param StructuralType $pattern
52-
* @return Relationship
61+
* @param NodeType $node The node to attach to the end of the structural type.
62+
* @param array|PropertyMap|null $properties The properties to attach to the relationship
63+
* @param string|Variable|null $name The name fo the relationship
64+
*
65+
* @return Path
5366
*/
54-
public function relationshipTo(StructuralType $pattern): Relationship;
67+
public function relationshipTo(NodeType $node, $properties = null, $name = null): Path;
5568

5669
/**
57-
* Creates a new relationship from the given pattern to this node.
70+
* Adds a new relationship from the node pattern at the end of the structural type to form a path.
71+
*
72+
* @param NodeType $node The node to attach to the end of the structural type.
73+
* @param array|PropertyMap|null $properties The properties to attach to the relationship
74+
* @param string|Variable|null $name The name fo the relationship
5875
*
59-
* @param StructuralType $pattern
60-
* @return Relationship
76+
* @return Path
6177
*/
62-
public function relationshipFrom(StructuralType $pattern): Relationship;
78+
public function relationshipFrom(NodeType $node, $properties = null, $name = null): Path;
6379

6480
/**
65-
* Creates a new unidirectional relationship between this node and the given pattern.
81+
* Adds a new unidirectional relationship to the node pattern at the end of the structural type to form a path.
82+
*
83+
* @param NodeType $node The node to attach to the end of the structural type.
84+
* @param array|PropertyMap|null $properties The properties to attach to the relationship
85+
* @param string|Variable|null $name The name fo the relationship
6686
*
67-
* @param StructuralType $pattern
68-
* @return Relationship
87+
* @return Path
6988
*/
70-
public function relationshipUni(StructuralType $pattern): Relationship;
89+
public function relationshipUni(NodeType $node, $properties = null, $name = null): Path;
7190
}

tests/Unit/Patterns/PathTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
class PathTest
66
{
7-
7+
public function test
88
}

0 commit comments

Comments
 (0)