Skip to content

Commit c59ca55

Browse files
author
Wout Gevaert
committed
Change StructuralTypes things
1 parent 1d833ad commit c59ca55

File tree

8 files changed

+137
-85
lines changed

8 files changed

+137
-85
lines changed

src/Functions/RawFunction.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
use WikibaseSolutions\CypherDSL\Traits\MapTypeTrait;
2929
use WikibaseSolutions\CypherDSL\Traits\NumeralTypeTrait;
3030
use WikibaseSolutions\CypherDSL\Traits\StringTypeTrait;
31-
use WikibaseSolutions\CypherDSL\Traits\StructuralTypeTrait;
3231
use WikibaseSolutions\CypherDSL\Types\AnyType;
3332
use WikibaseSolutions\CypherDSL\Types\CompositeTypes\ListType;
3433
use WikibaseSolutions\CypherDSL\Types\CompositeTypes\MapType;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
/*
4+
* Cypher DSL
5+
* Copyright (C) 2021 Wikibase Solutions
6+
*
7+
* This program is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU General Public License
9+
* as published by the Free Software Foundation; either version 2
10+
* of the License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20+
*/
21+
22+
namespace WikibaseSolutions\CypherDSL\Types\StructuralTypes;
23+
24+
use WikibaseSolutions\CypherDSL\PropertyMap;
25+
use WikibaseSolutions\CypherDSL\Types\AnyType;
26+
use function is_array;
27+
28+
interface HasPropertiesType extends StructuralType
29+
{
30+
/**
31+
* Add the given property to the properties of this object.
32+
*
33+
* @param string $key The name of the property
34+
* @param AnyType $value The value of the property
35+
*
36+
* @return static
37+
*/
38+
public function withProperty(string $key, AnyType $value): self;
39+
40+
/**
41+
* Add the given properties to the properties of this object.
42+
*
43+
* @param PropertyMap|array $properties
44+
*
45+
* @return static
46+
*/
47+
public function withProperties($properties): self;
48+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
/*
4+
* Cypher DSL
5+
* Copyright (C) 2021 Wikibase Solutions
6+
*
7+
* This program is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU General Public License
9+
* as published by the Free Software Foundation; either version 2
10+
* of the License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20+
*/
21+
22+
namespace WikibaseSolutions\CypherDSL\Types\StructuralTypes;
23+
24+
use WikibaseSolutions\CypherDSL\Patterns\Node;
25+
use WikibaseSolutions\CypherDSL\Patterns\Path;
26+
use WikibaseSolutions\CypherDSL\PropertyMap;
27+
use WikibaseSolutions\CypherDSL\Types\AnyType;
28+
use WikibaseSolutions\CypherDSL\Variable;
29+
30+
/**
31+
* Represents a structural type in Cypher that can have relationships.
32+
*
33+
* Those are:
34+
*
35+
* - node
36+
* - path
37+
*
38+
* @see https://neo4j.com/docs/cypher-manual/current/syntax/values/#structural-types
39+
*/
40+
interface HasRelationshipsType extends StructuralType
41+
{
42+
/**
43+
* Adds a new relationship from the end of the structural type to the node pattern.
44+
*
45+
* @param RelationshipType $relationship
46+
* @param Node|Path $nodeOrPath
47+
* @return Path
48+
*/
49+
public function relationship(RelationshipType $relationship, StructuralType $nodeOrPath): Path;
50+
51+
/**
52+
* Adds a new relationship to the node pattern at the end of the structural type to form a path.
53+
*
54+
* @param NodeType|Path $nodeOrPath The node to attach to the end of the structural type
55+
* @param string|null $type The type of the relationship
56+
* @param array|PropertyMap|null $properties The properties to attach to the relationship
57+
* @param string|Variable|null $name The name fo the relationship
58+
*
59+
* @return Path
60+
*/
61+
public function relationshipTo(StructuralType $nodeOrPath, ?string $type = null, $properties = null, $name = null): Path;
62+
63+
/**
64+
* Adds a new relationship from the node pattern at the end of the structural type to form a path.
65+
*
66+
* @param NodeType|Path $nodeOrPath The node to attach to the end of the structural type.
67+
* @param string|null $type The type of the relationship
68+
* @param array|PropertyMap|null $properties The properties to attach to the relationship
69+
* @param string|Variable|null $name The name fo the relationship
70+
*
71+
* @return Path
72+
*/
73+
public function relationshipFrom(StructuralType $nodeOrPath, ?string $type = null, $properties = null, $name = null): Path;
74+
75+
/**
76+
* Adds a new unidirectional relationship to the node pattern at the end of the structural type to form a path.
77+
*
78+
* @param NodeType|Path $nodeOrPath The node to attach to the end of the structural type.
79+
* @param string|null $type The type of the relationship
80+
* @param array|PropertyMap|null $properties The properties to attach to the relationship
81+
* @param string|Variable|null $name The name fo the relationship
82+
*
83+
* @return Path
84+
*/
85+
public function relationshipUni(StructuralType $nodeOrPath, ?string $type = null, $properties = null, $name = null): Path;
86+
}

src/Types/StructuralTypes/NodeType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
/**
2525
* Represents the type "node".
2626
*/
27-
interface NodeType extends StructuralType
27+
interface NodeType extends HasRelationshipsType, HasPropertiesType
2828
{
2929
}

src/Types/StructuralTypes/PathType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
/**
2525
* Represents the type "path".
2626
*/
27-
interface PathType extends StructuralType
27+
interface PathType extends HasRelationshipsType
2828
{
2929
}

src/Types/StructuralTypes/RelationshipType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@
2626
/**
2727
* Represents the type "relationship".
2828
*/
29-
interface RelationshipType extends AnyType
29+
interface RelationshipType extends HasPropertiesType
3030
{
3131
}

src/Types/StructuralTypes/StructuralType.php

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -47,47 +47,4 @@
4747
*/
4848
interface StructuralType extends AnyType
4949
{
50-
/**
51-
* Adds a new relationship from the end of the structural type to the node pattern.
52-
* @param RelationshipType $relationship
53-
* @param Node|Path $nodeOrPath
54-
* @return Path
55-
*/
56-
public function relationship(RelationshipType $relationship, StructuralType $nodeOrPath): Path;
57-
58-
/**
59-
* Adds a new relationship to the node pattern at the end of the structural type to form a path.
60-
*
61-
* @param NodeType|Path $nodeOrPath The node to attach to the end of the structural type
62-
* @param string|null $type The type of the relationship
63-
* @param array|PropertyMap|null $properties The properties to attach to the relationship
64-
* @param string|Variable|null $name The name fo the relationship
65-
*
66-
* @return Path
67-
*/
68-
public function relationshipTo(StructuralType $nodeOrPath, ?string $type = null, $properties = null, $name = null): Path;
69-
70-
/**
71-
* Adds a new relationship from the node pattern at the end of the structural type to form a path.
72-
*
73-
* @param NodeType|Path $nodeOrPath The node to attach to the end of the structural type.
74-
* @param string|null $type The type of the relationship
75-
* @param array|PropertyMap|null $properties The properties to attach to the relationship
76-
* @param string|Variable|null $name The name fo the relationship
77-
*
78-
* @return Path
79-
*/
80-
public function relationshipFrom(StructuralType $nodeOrPath, ?string $type = null, $properties = null, $name = null): Path;
81-
82-
/**
83-
* Adds a new unidirectional relationship to the node pattern at the end of the structural type to form a path.
84-
*
85-
* @param NodeType|Path $nodeOrPath The node to attach to the end of the structural type.
86-
* @param string|null $type The type of the relationship
87-
* @param array|PropertyMap|null $properties The properties to attach to the relationship
88-
* @param string|Variable|null $name The name fo the relationship
89-
*
90-
* @return Path
91-
*/
92-
public function relationshipUni(StructuralType $nodeOrPath, ?string $type = null, $properties = null, $name = null): Path;
9350
}

src/Variable.php

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@
5050
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\PointType;
5151
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\StringType;
5252
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\TimeType;
53-
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\NodeType;
54-
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\PathType;
55-
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\RelationshipType;
56-
use WikibaseSolutions\CypherDSL\Types\StructuralTypes\StructuralType;
5753

5854
/**
5955
* Represents a variable.
@@ -68,9 +64,7 @@ class Variable implements
6864
LocalDateTimeType,
6965
LocalTimeType,
7066
MapType,
71-
NodeType,
7267
NumeralType,
73-
PathType,
7468
PointType,
7569
StringType,
7670
TimeType
@@ -146,36 +140,4 @@ public function toQuery(): string
146140
{
147141
return self::escape($this->getName());
148142
}
149-
150-
/**
151-
* @inheritDoc
152-
*/
153-
public function relationship(RelationshipType $relationship, StructuralType $nodeOrPath): Path
154-
{
155-
return (new Path((new Node())->named($this)))->relationship($relationship, $nodeOrPath);
156-
}
157-
158-
/**
159-
* @inheritDoc
160-
*/
161-
public function relationshipTo(StructuralType $nodeOrPath, ?string $type = null, $properties = null, $name = null): Path
162-
{
163-
return (new Path((new Node())->named($this)))->relationshipTo($nodeOrPath, $type, $properties, $name);
164-
}
165-
166-
/**
167-
* @inheritDoc
168-
*/
169-
public function relationshipFrom(StructuralType $nodeOrPath, ?string $type = null, $properties = null, $name = null): Path
170-
{
171-
return (new Path((new Node())->named($this)))->relationshipFrom($nodeOrPath, $type, $properties, $name);
172-
}
173-
174-
/**
175-
* @inheritDoc
176-
*/
177-
public function relationshipUni(StructuralType $nodeOrPath, ?string $type = null, $properties = null, $name = null): Path
178-
{
179-
return (new Path((new Node())->named($this)))->relationshipUni($nodeOrPath, $type, $properties, $name);
180-
}
181143
}

0 commit comments

Comments
 (0)