23
23
24
24
use WikibaseSolutions \CypherDSL \Expressions \Variable ;
25
25
use WikibaseSolutions \CypherDSL \Query ;
26
+ use WikibaseSolutions \CypherDSL \Traits \CastTrait ;
26
27
use WikibaseSolutions \CypherDSL \Traits \ErrorTrait ;
27
28
28
29
/**
34
35
* @see https://neo4j.com/docs/cypher-manual/current/clauses/call-subquery/
35
36
* @see Query::call() for a more convenient method to construct this class
36
37
*/
37
- class CallClause extends Clause
38
+ final class CallClause extends Clause
38
39
{
40
+ use CastTrait;
39
41
use ErrorTrait;
40
42
41
43
/**
@@ -61,47 +63,30 @@ public function withSubQuery(Query $subQuery): self
61
63
return $ this ;
62
64
}
63
65
64
- /**
65
- * Sets the variables to include in the WITH clause. This overwrites any previously set variables .
66
- *
67
- * @param Variable[] |string[] $variables A list of variable objects, or strings to cast to variables
68
- * @return $this
69
- *
70
- * @see https://neo4j.com/docs/cypher-manual/current/clauses/call-subquery/#subquery-correlated-importing
71
- */
72
- public function withVariables (...$ variables ): self
73
- {
74
- $ res = [];
66
+ /**
67
+ * Add one or more variables to include in the WITH clause.
68
+ *
69
+ * @param Variable|string ...$ variables
70
+ * @return $this
71
+ *
72
+ * @see https://neo4j.com/docs/cypher-manual/current/clauses/call-subquery/#subquery-correlated-importing
73
+ */
74
+ public function addVariable (...$ variables ): self
75
+ {
76
+ $ res = [];
75
77
76
78
foreach ($ variables as $ variable ) {
77
- $ this ->assertClass ('variables ' , [Variable::class, 'string ' ], $ variable );
78
- $ res [] = is_string ($ variable ) ? new Variable ($ variable ) : $ variable ;
79
+ $ res [] = self ::toVariable ($ variable );
79
80
}
80
81
81
- $ this ->withVariables = $ res ;
82
+ $ this ->withVariables = array_merge ( $ this -> withVariables , $ res) ;
82
83
83
84
return $ this ;
84
85
}
85
86
86
- /**
87
- * Add a variable to include in the WITH clause.
88
- *
89
- * @param Variable|string $variable A variable or a string to cast to a variable
90
- * @return $this
91
- *
92
- * @see https://neo4j.com/docs/cypher-manual/current/clauses/call-subquery/#subquery-correlated-importing
93
- */
94
- public function addVariable ($ variable ): self
95
- {
96
- $ this ->assertClass ('variable ' , [Variable::class, 'string ' ], $ variable );
97
- $ this ->withVariables [] = is_string ($ variable ) ? new Variable ($ variable ) : $ variable ;
98
-
99
- return $ this ;
100
- }
101
-
102
87
/**
103
88
* Returns the query that is being called. This query does not include the WITH clause that is inserted
104
- * if there are any correlated variables.
89
+ * if there are any correlated variables.
105
90
*
106
91
* @return Query|null
107
92
*/
@@ -110,15 +95,15 @@ public function getSubQuery(): ?Query
110
95
return $ this ->subQuery ;
111
96
}
112
97
113
- /**
114
- * Returns the variables that will be included in the WITH clause.
115
- *
116
- * @return Variable[]
117
- */
118
- public function getWithVariables (): array
119
- {
120
- return $ this ->withVariables ;
121
- }
98
+ /**
99
+ * Returns the variables that will be included in the WITH clause.
100
+ *
101
+ * @return Variable[]
102
+ */
103
+ public function getWithVariables (): array
104
+ {
105
+ return $ this ->withVariables ;
106
+ }
122
107
123
108
/**
124
109
* @inheritDoc
@@ -138,7 +123,6 @@ protected function getSubject(): string
138
123
if ($ this ->withVariables !== []) {
139
124
$ withClause = new WithClause ();
140
125
$ withClause ->setEntries ($ this ->withVariables );
141
-
142
126
$ subQuery = $ withClause ->toQuery () . ' ' . $ subQuery ;
143
127
}
144
128
0 commit comments