Skip to content

Commit f456026

Browse files
Further work on type system and consistency
1 parent 779eeb8 commit f456026

File tree

74 files changed

+921
-707
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+921
-707
lines changed

src/Clauses/SetClause.php

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

2222
namespace WikibaseSolutions\CypherDSL\Clauses;
2323

24-
use WikibaseSolutions\CypherDSL\Expressions\Assignment;
2524
use WikibaseSolutions\CypherDSL\Expressions\Label;
25+
use WikibaseSolutions\CypherDSL\PropertyReplacement;
2626
use WikibaseSolutions\CypherDSL\QueryConvertible;
2727
use WikibaseSolutions\CypherDSL\Traits\ErrorTrait;
2828

@@ -36,7 +36,7 @@ class SetClause extends Clause
3636
use ErrorTrait;
3737

3838
/**
39-
* @var Assignment[]|Label[] $expressions The expressions to set
39+
* @var PropertyReplacement[]|Label[] $expressions The expressions to set
4040
*/
4141
private array $expressions = [];
4242

@@ -49,7 +49,7 @@ class SetClause extends Clause
4949
public function setAssignments(array $expressions): self
5050
{
5151
foreach ($expressions as $expression) {
52-
$this->assertClass('expressions', [Assignment::class, Label::class], $expression);
52+
$this->assertClass('expressions', [PropertyReplacement::class, Label::class], $expression);
5353
}
5454

5555
$this->expressions = $expressions;
@@ -60,12 +60,12 @@ public function setAssignments(array $expressions): self
6060
/**
6161
* Add an assignment.
6262
*
63-
* @param Assignment|Label $expression The assignment to execute
63+
* @param PropertyReplacement|Label $expression The assignment to execute
6464
* @return SetClause
6565
*/
6666
public function addAssignment($expression): self
6767
{
68-
$this->assertClass('expression', [Assignment::class, Label::class], $expression);
68+
$this->assertClass('expression', [PropertyReplacement::class, Label::class], $expression);
6969
$this->expressions[] = $expression;
7070

7171
return $this;
@@ -74,7 +74,7 @@ public function addAssignment($expression): self
7474
/**
7575
* Returns the expressions to SET.
7676
*
77-
* @return Assignment[]|Label[]
77+
* @return PropertyReplacement[]|Label[]
7878
*/
7979
public function getExpressions(): array
8080
{

src/Expressions/Operators/Exists.php renamed to src/Expressions/Exists.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2020
*/
2121

22-
namespace WikibaseSolutions\CypherDSL\Expressions\Operators;
22+
namespace WikibaseSolutions\CypherDSL\Expressions;
2323

2424
use WikibaseSolutions\CypherDSL\Clauses\MatchClause;
2525
use WikibaseSolutions\CypherDSL\Clauses\WhereClause;

src/Expressions/Label.php

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,23 @@
2121

2222
namespace WikibaseSolutions\CypherDSL\Expressions;
2323

24-
use InvalidArgumentException;
2524
use WikibaseSolutions\CypherDSL\Traits\EscapeTrait;
2625
use WikibaseSolutions\CypherDSL\Traits\TypeTraits\PropertyTypeTraits\BooleanTypeTrait;
2726
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\BooleanType;
2827

2928
/**
30-
* Represents a label. A label in Cypher would be something like "n:German" or "n:German:Swedish".
29+
* Represents a label. A label in Cypher would be something like "n:German" or "n:German:Swedish". Label implements
30+
* BooleanType, since it can be used in a "WHERE" clause like so:
31+
*
32+
* MATCH (n) WHERE n:label1:label2 RETURN n
33+
*
34+
* @see https://s3.amazonaws.com/artifacts.opencypher.org/openCypher9.pdf (page 85)
35+
* @see https://neo4j.com/docs/cypher-manual/current/clauses/where/#filter-on-node-label
3136
*/
3237
class Label implements BooleanType
3338
{
34-
use EscapeTrait;
3539
use BooleanTypeTrait;
40+
use EscapeTrait;
3641

3742
/**
3843
* @var Variable The variable to which this label belongs
@@ -48,24 +53,40 @@ class Label implements BooleanType
4853
* Label constructor.
4954
*
5055
* @param Variable $variable
51-
* @param string[] $labels
56+
* @param string ...$labels
5257
*/
53-
public function __construct(Variable $variable, array $labels)
58+
public function __construct(Variable $variable, string ...$labels)
5459
{
55-
if (count($labels) === 0) {
56-
throw new InvalidArgumentException("\$labels must have at least one label");
57-
}
58-
59-
foreach ($labels as $label) {
60-
if (!is_string($label)) {
61-
throw new InvalidArgumentException("\$labels must consist of only strings");
62-
}
63-
}
64-
6560
$this->variable = $variable;
6661
$this->labels = $labels;
6762
}
6863

64+
/**
65+
* Overrides the labels of this class with the given labels.
66+
*
67+
* @param string ...$labels
68+
* @return $this
69+
*/
70+
public function withLabels(string ...$labels): self
71+
{
72+
$this->labels = $labels;
73+
74+
return $this;
75+
}
76+
77+
/**
78+
* Adds the given labels to this class.
79+
*
80+
* @param string ...$labels
81+
* @return $this
82+
*/
83+
public function addLabels(string ...$labels): self
84+
{
85+
$this->labels = array_merge($this->labels, $labels);
86+
87+
return $this;
88+
}
89+
6990
/**
7091
* Returns the labels.
7192
*

0 commit comments

Comments
 (0)