Skip to content

Commit 7b43d5f

Browse files
author
Wout Gevaert
committed
Change typehints of CREATE/MERGE/etc clauses
1 parent 0ff1f98 commit 7b43d5f

File tree

10 files changed

+60
-55
lines changed

10 files changed

+60
-55
lines changed

src/Clauses/CreateClause.php

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

2424
use WikibaseSolutions\CypherDSL\Traits\ErrorTrait;
25-
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\StructuralType;
25+
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\NodeType;
26+
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\PathType;
2627

2728
/**
2829
* This class represents a CREATE clause.
@@ -34,18 +35,19 @@ class CreateClause extends Clause
3435
use ErrorTrait;
3536

3637
/**
37-
* @var StructuralType[] The patterns to create
38+
* @var (PathType|NodeType)[] The patterns to create
3839
*/
3940
private array $patterns = [];
4041

4142
/**
4243
* Add a pattern to create.
4344
*
44-
* @param StructuralType $pattern The pattern to create
45+
* @param PathType|NodeType $pattern The pattern to create
4546
* @return CreateClause
4647
*/
47-
public function addPattern(StructuralType $pattern): self
48+
public function addPattern($pattern): self
4849
{
50+
$this->assertClass('pattern', [PathType::class, NodeType::class], $pattern);
4951
$this->patterns[] = $pattern;
5052

5153
return $this;
@@ -54,7 +56,7 @@ public function addPattern(StructuralType $pattern): self
5456
/**
5557
* Returns the patterns of the create clause.
5658
*
57-
* @return StructuralType[]
59+
* @return (PathType|NodeType)[]
5860
*/
5961
public function getPatterns(): array
6062
{

src/Clauses/MatchClause.php

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

2424
use WikibaseSolutions\CypherDSL\Traits\ErrorTrait;
25-
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\StructuralType;
25+
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\NodeType;
26+
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\PathType;
2627

2728
/**
2829
* This class represents a MATCH clause.
@@ -34,14 +35,14 @@ class MatchClause extends Clause
3435
use ErrorTrait;
3536

3637
/**
37-
* @var StructuralType[] List of patterns
38+
* @var (PathType|NodeType)[] List of patterns
3839
*/
3940
private array $patterns = [];
4041

4142
/**
4243
* Returns the patterns to match.
4344
*
44-
* @return StructuralType[]
45+
* @return (PathType|NodeType)[]
4546
*/
4647
public function getPatterns(): array
4748
{
@@ -51,11 +52,12 @@ public function getPatterns(): array
5152
/**
5253
* Add a pattern to the match clause.
5354
*
54-
* @param StructuralType $pattern
55+
* @param PathType|NodeType $pattern
5556
* @return MatchClause
5657
*/
57-
public function addPattern(StructuralType $pattern): self
58+
public function addPattern($pattern): self
5859
{
60+
$this->assertClass('pattern', [PathType::class, NodeType::class], $pattern);
5961
$this->patterns[] = $pattern;
6062

6163
return $this;

src/Clauses/MergeClause.php

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

2424
use WikibaseSolutions\CypherDSL\Traits\ErrorTrait;
25+
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\NodeType;
26+
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\PathType;
2527
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\StructuralType;
2628

2729
/**
@@ -34,7 +36,7 @@ class MergeClause extends Clause
3436
use ErrorTrait;
3537

3638
/**
37-
* @var StructuralType|null $pattern The pattern to merge
39+
* @var PathType|NodeType|null $pattern The pattern to merge
3840
*/
3941
private ?StructuralType $pattern = null;
4042

@@ -71,7 +73,7 @@ public function getOnMatchClause(): ?Clause
7173
/**
7274
* Returns the pattern to MERGE.
7375
*
74-
* @return StructuralType|null
76+
* @return PathType|NodeType|null
7577
*/
7678
public function getPattern(): ?StructuralType
7779
{
@@ -81,11 +83,12 @@ public function getPattern(): ?StructuralType
8183
/**
8284
* Sets the pattern to merge.
8385
*
84-
* @param StructuralType $pattern The pattern to merge
86+
* @param PathType|NodeType $pattern The pattern to merge
8587
* @return MergeClause
8688
*/
87-
public function setPattern(StructuralType $pattern): self
89+
public function setPattern($pattern): self
8890
{
91+
$this->assertClass('pattern', [PathType::class, NodeType::class], $pattern);
8992
$this->pattern = $pattern;
9093

9194
return $this;

src/Clauses/OptionalMatchClause.php

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

2424
use WikibaseSolutions\CypherDSL\Traits\ErrorTrait;
25-
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\StructuralType;
25+
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\NodeType;
26+
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\PathType;
2627

2728
/**
2829
* This class represents an OPTIONAL MATCH clause.
@@ -34,14 +35,14 @@ class OptionalMatchClause extends Clause
3435
use ErrorTrait;
3536

3637
/**
37-
* @var StructuralType[] List of patterns
38+
* @var (PathType|NodeType)[] List of patterns
3839
*/
3940
private array $patterns = [];
4041

4142
/**
4243
* Returns the patterns to optionally match.
4344
*
44-
* @return StructuralType[]
45+
* @return (PathType|NodeType)[]
4546
*/
4647
public function getPatterns(): array
4748
{
@@ -51,11 +52,12 @@ public function getPatterns(): array
5152
/**
5253
* Add a pattern to the optional match clause.
5354
*
54-
* @param StructuralType $pattern
55+
* @param PathType|NodeType $pattern
5556
* @return OptionalMatchClause
5657
*/
57-
public function addPattern(StructuralType $pattern): self
58+
public function addPattern($pattern): self
5859
{
60+
$this->assertClass('pattern', [NodeType::class, PathType::class], $pattern);
5961
$this->patterns[] = $pattern;
6062

6163
return $this;

src/Patterns/Path.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
use WikibaseSolutions\CypherDSL\Traits\ErrorTrait;
99
use WikibaseSolutions\CypherDSL\Traits\PathTrait;
1010
use WikibaseSolutions\CypherDSL\Types\AnyType;
11+
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\HasRelationshipsType;
1112
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\PathType;
1213
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\RelationshipType;
13-
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\StructuralType;
1414
use WikibaseSolutions\CypherDSL\Variable;
1515

1616
class Path implements PathType
@@ -106,7 +106,7 @@ public function getRelationships(): array
106106
/**
107107
* @inheritDoc
108108
*/
109-
public function relationship(RelationshipType $relationship, StructuralType $nodeOrPath): Path
109+
public function relationship(RelationshipType $relationship, HasRelationshipsType $nodeOrPath): Path
110110
{
111111
self::assertClass('nodeOrPath', [__CLASS__, Node::class], $nodeOrPath);
112112

@@ -124,7 +124,7 @@ public function relationship(RelationshipType $relationship, StructuralType $nod
124124
/**
125125
* @inheritDoc
126126
*/
127-
public function relationshipTo(StructuralType $nodeOrPath, ?string $type = null, $properties = null, $name = null): Path
127+
public function relationshipTo(HasRelationshipsType $nodeOrPath, ?string $type = null, $properties = null, $name = null): Path
128128
{
129129
$relationship = $this->buildRelationship(Relationship::DIR_RIGHT, $type, $properties, $name);
130130

@@ -134,7 +134,7 @@ public function relationshipTo(StructuralType $nodeOrPath, ?string $type = null,
134134
/**
135135
* @inheritDoc
136136
*/
137-
public function relationshipFrom(StructuralType $nodeOrPath, ?string $type = null, $properties = null, $name = null): Path
137+
public function relationshipFrom(HasRelationshipsType $nodeOrPath, ?string $type = null, $properties = null, $name = null): Path
138138
{
139139
$relationship = $this->buildRelationship(Relationship::DIR_LEFT, $type, $properties, $name);
140140

@@ -144,7 +144,7 @@ public function relationshipFrom(StructuralType $nodeOrPath, ?string $type = nul
144144
/**
145145
* @inheritDoc
146146
*/
147-
public function relationshipUni(StructuralType $nodeOrPath, ?string $type = null, $properties = null, $name = null): Path
147+
public function relationshipUni(HasRelationshipsType $nodeOrPath, ?string $type = null, $properties = null, $name = null): Path
148148
{
149149
$relationship = $this->buildRelationship(Relationship::DIR_UNI, $type, $properties, $name);
150150

src/Query.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\StringType;
5555
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\NodeType;
5656
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\PathType;
57-
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\StructuralType;
5857

5958
/**
6059
* Builder class for building complex Cypher queries.
@@ -217,7 +216,7 @@ public static function rawExpression(string $expression): AnyType
217216
/**
218217
* Creates the MATCH clause.
219218
*
220-
* @param StructuralType|StructuralType[] $patterns A single pattern or a list of patterns
219+
* @param PathType|NodeType|(PathType|NodeType)[] $patterns A single pattern or a list of patterns
221220
*
222221
* @return $this
223222
* @see https://neo4j.com/docs/cypher-manual/current/clauses/match/
@@ -232,7 +231,7 @@ public function match($patterns): self
232231
}
233232

234233
foreach ($patterns as $pattern) {
235-
$this->assertClass('pattern', StructuralType::class, $pattern);
234+
$this->assertClass('pattern', [PathType::class, NodeType::class], $pattern);
236235

237236
$matchClause->addPattern($pattern);
238237
}
@@ -283,7 +282,7 @@ public function returning($expressions, bool $distinct = false): self
283282
/**
284283
* Creates the CREATE clause.
285284
*
286-
* @param StructuralType|StructuralType[] $patterns A single pattern or a list of patterns
285+
* @param PathType|NodeType|(PathType|NodeType)[] $patterns A single pattern or a list of patterns
287286
*
288287
* @return $this
289288
* @see https://neo4j.com/docs/cypher-manual/current/clauses/create/
@@ -298,7 +297,7 @@ public function create($patterns): self
298297
}
299298

300299
foreach ($patterns as $pattern) {
301-
$this->assertClass('pattern', StructuralType::class, $pattern);
300+
$this->assertClass('pattern', [PathType::class, NodeType::class], $pattern);
302301

303302
$createClause->addPattern($pattern);
304303
}
@@ -405,16 +404,17 @@ public function skip(NumeralType $limit): self
405404
/**
406405
* Creates the MERGE clause.
407406
*
408-
* @param StructuralType $pattern The pattern to merge
407+
* @param PathType|NodeType $pattern The pattern to merge
409408
* @param Clause|null $createClause The clause to execute when the pattern is created
410409
* @param Clause|null $matchClause The clause to execute when the pattern is matched
411410
*
412411
* @return $this
413412
* @see https://neo4j.com/docs/cypher-manual/current/clauses/merge/
414413
*
415414
*/
416-
public function merge(StructuralType $pattern, Clause $createClause = null, Clause $matchClause = null): self
415+
public function merge($pattern, Clause $createClause = null, Clause $matchClause = null): self
417416
{
417+
$this->assertClass('pattern', [PathType::class, NodeType::class], $pattern);
418418
$mergeClause = new MergeClause();
419419
$mergeClause->setPattern($pattern);
420420

@@ -434,7 +434,7 @@ public function merge(StructuralType $pattern, Clause $createClause = null, Clau
434434
/**
435435
* Creates the OPTIONAL MATCH clause.
436436
*
437-
* @param StructuralType|StructuralType[] $patterns A single pattern or a list of patterns
437+
* @param PathType|NodeType|(PathType|NodeType)[] $patterns A single pattern or a list of patterns
438438
*
439439
* @return $this
440440
* @see https://neo4j.com/docs/cypher-manual/current/clauses/optional-match/
@@ -449,7 +449,7 @@ public function optionalMatch($patterns): self
449449
}
450450

451451
foreach ($patterns as $pattern) {
452-
$this->assertClass('pattern', StructuralType::class, $pattern);
452+
$this->assertClass('pattern', [PathType::class, NodeType::class], $pattern);
453453

454454
$optionalMatchClause->addPattern($pattern);
455455
}

tests/Unit/Clauses/CreateClauseTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
use WikibaseSolutions\CypherDSL\Types\AnyType;
2929
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\NodeType;
3030
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\PathType;
31-
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\StructuralType;
3231

3332
/**
3433
* @covers \WikibaseSolutions\CypherDSL\Clauses\CreateClause
@@ -48,7 +47,7 @@ public function testEmptyClause(): void
4847
public function testSinglePattern(): void
4948
{
5049
$createClause = new CreateClause();
51-
$pattern = $this->getQueryConvertableMock(StructuralType::class, "(a)");
50+
$pattern = $this->getQueryConvertableMock(NodeType::class, "(a)");
5251

5352
$createClause->addPattern($pattern);
5453

@@ -60,13 +59,13 @@ public function testMultiplePatterns(): void
6059
{
6160
$createClause = new CreateClause();
6261

63-
$patternA = $this->getQueryConvertableMock(StructuralType::class, "(a)");
64-
$patternB = $this->getQueryConvertableMock(StructuralType::class, "(b)");
62+
$patternA = $this->getQueryConvertableMock(NodeType::class, "(a)");
63+
$patternB = $this->getQueryConvertableMock(PathType::class, "(b)-->(c)");
6564

6665
$createClause->addPattern($patternA);
6766
$createClause->addPattern($patternB);
6867

69-
$this->assertSame("CREATE (a), (b)", $createClause->toQuery());
68+
$this->assertSame("CREATE (a), (b)-->(c)", $createClause->toQuery());
7069
$this->assertEquals([$patternA, $patternB], $createClause->getPatterns());
7170
}
7271

tests/Unit/Clauses/MatchClauseTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
use WikibaseSolutions\CypherDSL\Types\AnyType;
2929
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\NodeType;
3030
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\PathType;
31-
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\StructuralType;
3231

3332
/**
3433
* @covers \WikibaseSolutions\CypherDSL\Clauses\MatchClause
@@ -48,7 +47,7 @@ public function testEmptyClause(): void
4847
public function testSinglePattern(): void
4948
{
5049
$match = new MatchClause();
51-
$pattern = $this->getQueryConvertableMock(StructuralType::class, "(a)");
50+
$pattern = $this->getQueryConvertableMock(NodeType::class, "(a)");
5251
$match->addPattern($pattern);
5352

5453
$this->assertSame("MATCH (a)", $match->toQuery());
@@ -58,13 +57,13 @@ public function testSinglePattern(): void
5857
public function testMultiplePatterns(): void
5958
{
6059
$match = new MatchClause();
61-
$patternA = $this->getQueryConvertableMock(StructuralType::class, "(a)");
62-
$patternB = $this->getQueryConvertableMock(StructuralType::class, "(b)");
60+
$patternA = $this->getQueryConvertableMock(NodeType::class, "(a)");
61+
$patternB = $this->getQueryConvertableMock(PathType::class, "(b)-->(c)");
6362

6463
$match->addPattern($patternA);
6564
$match->addPattern($patternB);
6665

67-
$this->assertSame("MATCH (a), (b)", $match->toQuery());
66+
$this->assertSame("MATCH (a), (b)-->(c)", $match->toQuery());
6867
$this->assertEquals([$patternA, $patternB], $match->getPatterns());
6968
}
7069

0 commit comments

Comments
 (0)