Skip to content

Commit d04ecbd

Browse files
committed
fixed all tests for php 8.1
1 parent 2dc7414 commit d04ecbd

File tree

13 files changed

+209
-314
lines changed

13 files changed

+209
-314
lines changed

src/Functions/RawFunction.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,13 @@ class RawFunction extends FunctionCall implements
4646
MapType,
4747
BooleanType,
4848
NumeralType,
49-
StringType,
50-
NodeType,
51-
PathType
49+
StringType
5250
{
5351
use BooleanTypeTrait;
5452
use ListTypeTrait;
5553
use MapTypeTrait;
5654
use NumeralTypeTrait;
5755
use StringTypeTrait;
58-
use StructuralTypeTrait;
5956
use ErrorTrait;
6057

6158
/**

src/Patterns/Node.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -112,24 +112,4 @@ public function property(string $property): Property
112112
{
113113
return new Property($this->getName(), $property);
114114
}
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-
}
135115
}

src/Patterns/Path.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use WikibaseSolutions\CypherDSL\PropertyMap;
66
use WikibaseSolutions\CypherDSL\Traits\ErrorTrait;
77
use WikibaseSolutions\CypherDSL\Traits\PathTrait;
8+
use WikibaseSolutions\CypherDSL\Types\AnyType;
89
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\NodeType;
910
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\PathType;
1011
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\RelationshipType;
@@ -23,13 +24,13 @@ class Path implements PathType
2324
private array $nodes;
2425

2526
/**
26-
* @param Node|Node[]|null $nodes
27+
* @param AnyType|AnyType[]|null $nodes
2728
* @param Relationship|Relationship[]|null $relationships
2829
*/
2930
public function __construct($nodes = null, $relationships = null)
3031
{
3132
self::assertClass('relationships', [Relationship::class, 'array', 'null'], $relationships);
32-
self::assertClass('nodes', [Node::class, 'array', 'null'], $nodes);
33+
self::assertClass('nodes', [AnyType::class, 'array', 'null'], $nodes);
3334

3435
$nodes ??= [];
3536
$relationships ??= [];
@@ -91,46 +92,54 @@ public function relationship(RelationshipType $relationship, NodeType $node): Pa
9192
return $this;
9293
}
9394

94-
public function relationshipTo(NodeType $node, $properties = null, $name = null): Path
95+
public function relationshipTo(NodeType $node, ?string $type = null, $properties = null, $name = null): Path
9596
{
96-
$relationship = $this->buildRelationship(Relationship::DIR_RIGHT, $properties, $name);
97+
$relationship = $this->buildRelationship(Relationship::DIR_RIGHT, $type, $properties, $name);
9798

9899
return $this->relationship($relationship, $node);
99100
}
100101

101-
public function relationshipFrom(NodeType $node, $properties = null, $name = null): Path
102+
public function relationshipFrom(NodeType $node, ?string $type = null, $properties = null, $name = null): Path
102103
{
103-
$relationship = $this->buildRelationship(Relationship::DIR_LEFT, $properties, $name);
104+
$relationship = $this->buildRelationship(Relationship::DIR_LEFT, $type, $properties, $name);
104105

105106
return $this->relationship($relationship, $node);
106107
}
107108

108-
public function relationshipUni(NodeType $node, $properties = null, $name = null): Path
109+
public function relationshipUni(NodeType $node, ?string $type = null, $properties = null, $name = null): Path
109110
{
110-
$relationship = $this->buildRelationship(Relationship::DIR_UNI, $properties, $name);
111+
$relationship = $this->buildRelationship(Relationship::DIR_UNI, $type, $properties, $name);
111112

112113
return $this->relationship($relationship, $node);
113114
}
114115

115116
/**
116117
* @param array $direction
118+
* @param string|null $type
117119
* @param mixed $properties
118120
* @param mixed $name
119121
*
120122
* @return Relationship
121123
*/
122-
private function buildRelationship(array $direction, $properties, $name): Relationship
124+
private function buildRelationship(array $direction, ?string $type, $properties, $name): Relationship
123125
{
124126
self::assertClass('properties', ['array', PropertyMap::class, 'null'], $properties);
125127
self::assertClass('name', ['string', Variable::class, 'null'], $name);
126128

127129
$relationship = new Relationship($direction);
130+
131+
if ($type !== null) {
132+
$relationship->withType($type);
133+
}
134+
128135
if ($properties !== null) {
129136
$relationship->withProperties($properties);
130137
}
138+
131139
if ($name !== null) {
132140
$relationship->named($name);
133141
}
142+
134143
return $relationship;
135144
}
136145
}

src/Patterns/Relationship.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ public function __construct(array $direction)
8787
$this->direction = $direction;
8888
}
8989

90+
/**
91+
* @return string[]
92+
*/
93+
public function getDirection(): array
94+
{
95+
return $this->direction;
96+
}
97+
9098
/**
9199
* Set the minimum number of `relationship->node` hops away to search.
92100
*

src/Query.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,17 @@ public static function node(string $label = null): Node
102102
/**
103103
* Creates a relationship.
104104
*
105-
* @param StructuralType $a The node left of the relationship
106-
* @param StructuralType $b The node right of the relationship
107105
* @param array $direction The direction of the relationship, should be either:
108106
* - Path::DIR_RIGHT (for a relation of (a)-->(b))
109107
* - Path::DIR_LEFT (for a relation of (a)<--(b))
110108
* - Path::DIR_UNI (for a relation of (a)--(b))
111109
*
112110
* @return Relationship
113111
* @see https://neo4j.com/docs/cypher-manual/current/syntax/patterns/#cypher-pattern-relationship
114-
*
115112
*/
116-
public static function relationship(StructuralType $a, StructuralType $b, array $direction): Relationship
113+
public static function relationship(array $direction): Relationship
117114
{
118-
return new Relationship($a, $b, $direction);
115+
return new Relationship($direction);
119116
}
120117

121118
/**

src/RawExpression.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class RawExpression implements
9090

9191
/**
9292
* RawExpression constructor.
93-
*
93+
*\
9494
* @param string $expression The raw expression
9595
*/
9696
public function __construct(string $expression)

src/Traits/NodeTypeTrait.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,35 @@
2121

2222
namespace WikibaseSolutions\CypherDSL\Traits;
2323

24+
use WikibaseSolutions\CypherDSL\Patterns\Path;
25+
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\NodeType;
26+
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\RelationshipType;
27+
2428
/**
2529
* This trait should be used by any expression that returns a node.
2630
*/
2731
trait NodeTypeTrait
2832
{
2933
use HasPropertiesTrait;
3034
use HasVariableTrait;
35+
36+
public function relationship(RelationshipType $relationship, NodeType $node): Path
37+
{
38+
return (new Path($this))->relationship($relationship, $node);
39+
}
40+
41+
public function relationshipTo(NodeType $node, ?string $type = null, $properties = null, $name = null): Path
42+
{
43+
return (new Path($this))->relationshipTo($node, $type, $properties, $name);
44+
}
45+
46+
public function relationshipFrom(NodeType $node, ?string $type = null, $properties = null, $name = null): Path
47+
{
48+
return (new Path($this))->relationshipFrom($node, $type, $properties, $name);
49+
}
50+
51+
public function relationshipUni(NodeType $node, ?string $type = null, $properties = null, $name = null): Path
52+
{
53+
return (new Path($this))->relationshipUni($node, $type, $properties, $name);
54+
}
3155
}

src/Types/StructuralTypes/StructuralType.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,33 +58,36 @@ public function relationship(RelationshipType $relationship, NodeType $node): Pa
5858
/**
5959
* Adds a new relationship to the node pattern at the end of the structural type to form a path.
6060
*
61-
* @param NodeType $node The node to attach to the end of the structural type.
61+
* @param NodeType $node The node to attach to the end of the structural type
62+
* @param string|null $type The type of the relationship
6263
* @param array|PropertyMap|null $properties The properties to attach to the relationship
6364
* @param string|Variable|null $name The name fo the relationship
6465
*
6566
* @return Path
6667
*/
67-
public function relationshipTo(NodeType $node, $properties = null, $name = null): Path;
68+
public function relationshipTo(NodeType $node, ?string $type = null, $properties = null, $name = null): Path;
6869

6970
/**
7071
* Adds a new relationship from the node pattern at the end of the structural type to form a path.
7172
*
7273
* @param NodeType $node The node to attach to the end of the structural type.
74+
* @param string|null $type The type of the relationship
7375
* @param array|PropertyMap|null $properties The properties to attach to the relationship
7476
* @param string|Variable|null $name The name fo the relationship
7577
*
7678
* @return Path
7779
*/
78-
public function relationshipFrom(NodeType $node, $properties = null, $name = null): Path;
80+
public function relationshipFrom(NodeType $node, ?string $type = null, $properties = null, $name = null): Path;
7981

8082
/**
8183
* Adds a new unidirectional relationship to the node pattern at the end of the structural type to form a path.
8284
*
8385
* @param NodeType $node The node to attach to the end of the structural type.
86+
* @param string|null $type The type of the relationship
8487
* @param array|PropertyMap|null $properties The properties to attach to the relationship
8588
* @param string|Variable|null $name The name fo the relationship
8689
*
8790
* @return Path
8891
*/
89-
public function relationshipUni(NodeType $node, $properties = null, $name = null): Path;
92+
public function relationshipUni(NodeType $node, ?string $type = null, $properties = null, $name = null): Path;
9093
}

src/Variable.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,18 +153,18 @@ public function relationship(RelationshipType $relationship, NodeType $node): Pa
153153
return (new Path((new Node())->named($this)))->relationship($relationship, $node);
154154
}
155155

156-
public function relationshipTo(NodeType $node, $properties = null, $name = null): Path
156+
public function relationshipTo(NodeType $node, ?string $type = null, $properties = null, $name = null): Path
157157
{
158-
return (new Path((new Node())->named($this)))->relationshipTo($node, $properties, $name);
158+
return (new Path((new Node())->named($this)))->relationshipTo($node, $type, $properties, $name);
159159
}
160160

161-
public function relationshipFrom(NodeType $node, $properties = null, $name = null): Path
161+
public function relationshipFrom(NodeType $node, ?string $type = null, $properties = null, $name = null): Path
162162
{
163-
return (new Path((new Node())->named($this)))->relationshipFrom($node, $properties, $name);
163+
return (new Path((new Node())->named($this)))->relationshipFrom($node, $type, $properties, $name);
164164
}
165165

166-
public function relationshipUni(NodeType $node, $properties = null, $name = null): Path
166+
public function relationshipUni(NodeType $node, ?string $type = null, $properties = null, $name = null): Path
167167
{
168-
return (new Path((new Node())->named($this)))->relationshipUni($node, $properties, $name);
168+
return (new Path((new Node())->named($this)))->relationshipUni($node, $type, $properties, $name);
169169
}
170170
}

tests/Unit/Patterns/PathTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ public function testRelationshipLong(): void
5252
$path = new Path(new Node());
5353
$path->relationshipUni(new Node('Label'))
5454
->relationshipTo((new Node())->named('b'))
55-
->relationshipFrom(new Node(), ['x' => Query::literal('y')], 'c')
55+
->relationshipFrom(new Node(), 'TYPE', ['x' => Query::literal('y')], 'c')
5656
->relationship(new Relationship(Relationship::DIR_UNI), (new Node())->named('d'))
5757
->named('a');
5858

59-
self::assertEquals('a = ()-[]-(:Label)-[]->(b)<-[c {x: \'y\'}]-()-[]-(d)', $path->toQuery());
59+
self::assertEquals('a = ()-[]-(:Label)-[]->(b)<-[c:TYPE {x: \'y\'}]-()-[]-(d)', $path->toQuery());
6060
}
6161
}

0 commit comments

Comments
 (0)