Skip to content

Commit 87abf67

Browse files
committed
Variadic function args.
1 parent eabedc3 commit 87abf67

File tree

3 files changed

+26
-29
lines changed

3 files changed

+26
-29
lines changed

src/RuleBuilder.php

+9-12
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,21 @@ public function registerOperatorNamespace(string $namespace): self
5656
/**
5757
* Create a logical AND operator proposition.
5858
*
59-
* @param Proposition $prop Initial Proposition
60-
* @param Proposition $prop2,... Optional unlimited number of additional Propositions
59+
* @param Proposition ...$props One or more Propositions
6160
*/
62-
public function logicalAnd(Proposition $prop, Proposition $prop2 = null): Operator\LogicalAnd
61+
public function logicalAnd(Proposition ...$props): Operator\LogicalAnd
6362
{
64-
return new Operator\LogicalAnd(\func_get_args());
63+
return new Operator\LogicalAnd($props);
6564
}
6665

6766
/**
6867
* Create a logical OR operator proposition.
6968
*
70-
* @param Proposition $prop Initial Proposition
71-
* @param Proposition $prop2,... Optional unlimited number of additional Propositions
69+
* @param Proposition ...$props One or more Propositions
7270
*/
73-
public function logicalOr(Proposition $prop, Proposition $prop2 = null): Operator\LogicalOr
71+
public function logicalOr(Proposition ...$props): Operator\LogicalOr
7472
{
75-
return new Operator\LogicalOr(\func_get_args());
73+
return new Operator\LogicalOr($props);
7674
}
7775

7876
/**
@@ -88,12 +86,11 @@ public function logicalNot(Proposition $prop): Operator\LogicalNot
8886
/**
8987
* Create a logical XOR operator proposition.
9088
*
91-
* @param Proposition $prop Initial Proposition
92-
* @param Proposition $prop2,... Optional unlimited number of additional Propositions
89+
* @param Proposition ...$props One or more Propositions
9390
*/
94-
public function logicalXor(Proposition $prop, Proposition $prop2 = null): Operator\LogicalXor
91+
public function logicalXor(Proposition ...$props): Operator\LogicalXor
9592
{
96-
return new Operator\LogicalXor(\func_get_args());
93+
return new Operator\LogicalXor($props);
9794
}
9895

9996
/**

src/RuleBuilder/Variable.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -227,24 +227,24 @@ public function notSameAs($variable): Operator\NotSameAs
227227
return new Operator\NotSameAs($this, $this->asVariable($variable));
228228
}
229229

230-
public function union($variable): self
230+
public function union(...$variables): self
231231
{
232-
return $this->applySetOperator('Union', \func_get_args());
232+
return $this->applySetOperator('Union', $variables);
233233
}
234234

235-
public function intersect($variable): self
235+
public function intersect(...$variables): self
236236
{
237-
return $this->applySetOperator('Intersect', \func_get_args());
237+
return $this->applySetOperator('Intersect', $variables);
238238
}
239239

240-
public function complement($variable): self
240+
public function complement(...$variables): self
241241
{
242-
return $this->applySetOperator('Complement', \func_get_args());
242+
return $this->applySetOperator('Complement', $variables);
243243
}
244244

245-
public function symmetricDifference($variable): self
245+
public function symmetricDifference(...$variables): self
246246
{
247-
return $this->applySetOperator('SymmetricDifference', \func_get_args());
247+
return $this->applySetOperator('SymmetricDifference', $variables);
248248
}
249249

250250
public function min(): self

src/Set.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ public function setContains(Value $value): bool
9393
*
9494
* Returns a Set which is the union of this Set with all passed Sets.
9595
*
96-
* @param Value $set,...
96+
* @param Value ...$sets One or more Sets
9797
*/
98-
public function union(Value $set): self
98+
public function union(Value ...$sets): self
9999
{
100100
$union = $this->value;
101101

102102
/** @var Value $arg */
103-
foreach (\func_get_args() as $arg) {
103+
foreach ($sets as $arg) {
104104
/** @var array $convertedArg */
105105
$convertedArg = $arg->getSet()->getValue();
106106
$union = \array_merge($union, \array_diff($convertedArg, $union));
@@ -114,14 +114,14 @@ public function union(Value $set): self
114114
*
115115
* Returns a Set which is the intersection of this Set with all passed sets.
116116
*
117-
* @param Value $set,...
117+
* @param Value ...$sets One or more Sets
118118
*/
119-
public function intersect(Value $set): self
119+
public function intersect(Value ...$sets): self
120120
{
121121
$intersect = $this->value;
122122

123123
/** @var Value $arg */
124-
foreach (\func_get_args() as $arg) {
124+
foreach ($sets as $arg) {
125125
/** @var array $convertedArg */
126126
$convertedArg = $arg->getSet()->getValue();
127127
// array_values is needed to make sure the indexes are ordered from 0
@@ -136,14 +136,14 @@ public function intersect(Value $set): self
136136
*
137137
* Returns a Set which is the complement of this Set with all passed Sets.
138138
*
139-
* @param Value $set,...
139+
* @param Value ...$sets One or more Sets
140140
*/
141-
public function complement(Value $set): self
141+
public function complement(Value ...$sets): self
142142
{
143143
$complement = $this->value;
144144

145145
/** @var Value $arg */
146-
foreach (\func_get_args() as $arg) {
146+
foreach ($sets as $arg) {
147147
/** @var array $convertedArg */
148148
$convertedArg = $arg->getSet()->getValue();
149149
// array_values is needed to make sure the indexes are ordered from 0

0 commit comments

Comments
 (0)