Skip to content

Commit c05904d

Browse files
Merge branch 'main' into point-and-date-support
2 parents 0600c3e + 0a6e28d commit c05904d

File tree

3 files changed

+99
-51
lines changed

3 files changed

+99
-51
lines changed

src/Patterns/Node.php

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

2424
use InvalidArgumentException;
25+
use WikibaseSolutions\CypherDSL\PropertyMap;
2526
use WikibaseSolutions\CypherDSL\Traits\EscapeTrait;
2627
use WikibaseSolutions\CypherDSL\Traits\NodeTypeTrait;
28+
use WikibaseSolutions\CypherDSL\Types\AnyType;
29+
use WikibaseSolutions\CypherDSL\Types\CompositeTypes\MapType;
2730
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\NodeType;
2831
use WikibaseSolutions\CypherDSL\Variable;
2932

@@ -47,6 +50,11 @@ class Node implements NodeType
4750
*/
4851
private ?Variable $variable;
4952

53+
/**
54+
* @var MapType|null
55+
*/
56+
private ?MapType $properties;
57+
5058
/**
5159
* Node constructor.
5260
*
@@ -59,6 +67,47 @@ public function __construct(string $label = null)
5967
}
6068
}
6169

70+
/**
71+
* Add the given property to the properties of this node.
72+
*
73+
* @param string $key The name of the property
74+
* @param AnyType $value The value of the property
75+
* @return NodeType
76+
*/
77+
public function withProperty(string $key, AnyType $value): NodeType
78+
{
79+
if (!isset($this->properties)) {
80+
$this->properties = new PropertyMap();
81+
}
82+
83+
$this->properties->addProperty($key, $value);
84+
85+
return $this;
86+
}
87+
88+
/**
89+
* Add the given properties to the properties of this node.
90+
*
91+
* @param PropertyMap|array $properties
92+
* @return NodeType
93+
*/
94+
public function withProperties($properties): NodeType
95+
{
96+
if (!isset($this->properties)) {
97+
$this->properties = new PropertyMap();
98+
}
99+
100+
if (is_array($properties)) {
101+
$properties = new PropertyMap($properties);
102+
} elseif (!($properties instanceof PropertyMap)) {
103+
throw new InvalidArgumentException("\$properties must either be an array or a PropertyMap object");
104+
}
105+
106+
$this->properties = $this->properties->mergeWith($properties);
107+
108+
return $this;
109+
}
110+
62111
/**
63112
* @param Variable|string $variable
64113
* @return Node

src/Patterns/Path.php

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
use DomainException;
2525
use InvalidArgumentException;
2626
use LogicException;
27+
use WikibaseSolutions\CypherDSL\PropertyMap;
2728
use WikibaseSolutions\CypherDSL\Traits\EscapeTrait;
2829
use WikibaseSolutions\CypherDSL\Traits\PathTypeTrait;
2930
use WikibaseSolutions\CypherDSL\Types\AnyType;
31+
use WikibaseSolutions\CypherDSL\Types\CompositeTypes\MapType;
3032
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\PathType;
3133
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\StructuralType;
3234
use WikibaseSolutions\CypherDSL\Variable;
@@ -49,12 +51,12 @@ class Path implements PathType
4951
/**
5052
* @var StructuralType The pattern left of the relationship
5153
*/
52-
private AnyType $a;
54+
private StructuralType $a;
5355

5456
/**
5557
* @var StructuralType The pattern right of the relationship
5658
*/
57-
private AnyType $b;
59+
private StructuralType $b;
5860

5961
/**
6062
* @var string[] The direction of the relationship
@@ -86,6 +88,11 @@ class Path implements PathType
8688
*/
8789
private int $exactHops;
8890

91+
/**
92+
* @var MapType|null
93+
*/
94+
private ?MapType $properties;
95+
8996
/**
9097
* Path constructor.
9198
*
@@ -109,6 +116,47 @@ public function __construct(StructuralType $a, StructuralType $b, array $directi
109116
$this->direction = $direction;
110117
}
111118

119+
/**
120+
* Add the given property to the properties of this path.
121+
*
122+
* @param string $key The name of the property
123+
* @param AnyType $value The value of the property
124+
* @return PathType
125+
*/
126+
public function withProperty(string $key, AnyType $value): PathType
127+
{
128+
if (!isset($this->properties)) {
129+
$this->properties = new PropertyMap();
130+
}
131+
132+
$this->properties->addProperty($key, $value);
133+
134+
return $this;
135+
}
136+
137+
/**
138+
* Add the given properties to the properties of this path.
139+
*
140+
* @param PropertyMap|array $properties
141+
* @return PathType
142+
*/
143+
public function withProperties($properties): PathType
144+
{
145+
if (!isset($this->properties)) {
146+
$this->properties = new PropertyMap();
147+
}
148+
149+
if (is_array($properties)) {
150+
$properties = new PropertyMap($properties);
151+
} elseif (!($properties instanceof PropertyMap)) {
152+
throw new InvalidArgumentException("\$properties must either be an array or a PropertyMap object");
153+
}
154+
155+
$this->properties = $this->properties->mergeWith($properties);
156+
157+
return $this;
158+
}
159+
112160
/**
113161
* @param Variable|string $variable
114162
* @return Path

src/Traits/StructuralTypeTrait.php

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

2424
use WikibaseSolutions\CypherDSL\Patterns\Path;
25-
use WikibaseSolutions\CypherDSL\PropertyMap;
26-
use WikibaseSolutions\CypherDSL\Types\AnyType;
27-
use WikibaseSolutions\CypherDSL\Types\CompositeTypes\MapType;
2825
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\StructuralType;
2926

3027
/**
@@ -35,52 +32,6 @@
3532
*/
3633
trait StructuralTypeTrait
3734
{
38-
/**
39-
* @var MapType|null
40-
*/
41-
private ?MapType $properties;
42-
43-
/**
44-
* Add the given property to the properties of this node.
45-
*
46-
* @param string $key The name of the property
47-
* @param AnyType $value The value of the property
48-
* @return Node
49-
*/
50-
public function withProperty(string $key, AnyType $value): self
51-
{
52-
if (!isset($this->properties)) {
53-
$this->properties = new PropertyMap();
54-
}
55-
56-
$this->properties->addProperty($key, $value);
57-
58-
return $this;
59-
}
60-
61-
/**
62-
* Add the given properties to the properties of this node.
63-
*
64-
* @param PropertyMap|array $properties
65-
* @return Node
66-
*/
67-
public function withProperties($properties): self
68-
{
69-
if (!isset($this->properties)) {
70-
$this->properties = new PropertyMap();
71-
}
72-
73-
if (is_array($properties)) {
74-
$properties = new PropertyMap($properties);
75-
} elseif (!($properties instanceof PropertyMap)) {
76-
throw new InvalidArgumentException("\$properties must either be an array or a PropertyMap object");
77-
}
78-
79-
$this->properties = $this->properties->mergeWith($properties);
80-
81-
return $this;
82-
}
83-
8435
/**
8536
* Creates a new relationship from this node to the given pattern.
8637
*

0 commit comments

Comments
 (0)