Skip to content

Commit 6f9250f

Browse files
committed
added insertParenthesis boolean to relevant factory methods in Traits
1 parent 75fe29f commit 6f9250f

File tree

5 files changed

+60
-40
lines changed

5 files changed

+60
-40
lines changed

src/Traits/BooleanTypeTrait.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,33 +38,36 @@ trait BooleanTypeTrait
3838
* Create a conjunction between this expression and the given expression.
3939
*
4040
* @param BooleanType $right
41+
* @param bool $insertParentheses
4142
* @return AndOperator
4243
*/
43-
public function and(BooleanType $right): AndOperator
44+
public function and(BooleanType $right, bool $insertParentheses = true): AndOperator
4445
{
45-
return new AndOperator($this, $right);
46+
return new AndOperator($this, $right, $insertParentheses);
4647
}
4748

4849
/**
4950
* Create a disjunction between this expression and the given expression.
5051
*
5152
* @param BooleanType $right
53+
* @param bool $insertParentheses
5254
* @return OrOperator
5355
*/
54-
public function or(BooleanType $right): OrOperator
56+
public function or(BooleanType $right, bool $insertParentheses = true): OrOperator
5557
{
56-
return new OrOperator($this, $right);
58+
return new OrOperator($this, $right, $insertParentheses);
5759
}
5860

5961
/**
6062
* Perform an XOR with the given expression.
6163
*
6264
* @param BooleanType $right
65+
* @param bool $insertParentheses
6366
* @return XorOperator
6467
*/
65-
public function xor(BooleanType $right): XorOperator
68+
public function xor(BooleanType $right, bool $insertParentheses = true): XorOperator
6669
{
67-
return new XorOperator($this, $right);
70+
return new XorOperator($this, $right, $insertParentheses);
6871
}
6972

7073
/**

src/Traits/ListTypeTrait.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ trait ListTypeTrait
3333
* Checks whether the given element exists in this list.
3434
*
3535
* @param PropertyType $left
36+
* @param bool $insertParentheses
3637
* @return In
3738
*/
38-
public function has(PropertyType $left): In
39+
public function has(PropertyType $left, bool $insertParentheses = true): In
3940
{
40-
return new In($left, $this);
41+
return new In($left, $this, $insertParentheses);
4142
}
4243
}

src/Traits/NumeralTypeTrait.php

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,110 +45,120 @@ trait NumeralTypeTrait
4545
* Add this expression to the given expression.
4646
*
4747
* @param NumeralType $right
48+
* @param bool $insertParentheses
4849
* @return Addition
4950
*/
50-
public function plus(NumeralType $right): Addition
51+
public function plus(NumeralType $right, bool $insertParentheses = true): Addition
5152
{
52-
return new Addition($this, $right);
53+
return new Addition($this, $right, $insertParentheses);
5354
}
5455

5556
/**
5657
* Divide this expression by the given expression.
5758
*
5859
* @param NumeralType $right
60+
* @param bool $insertParentheses
5961
* @return Division
6062
*/
61-
public function divide(NumeralType $right): Division
63+
public function divide(NumeralType $right, bool $insertParentheses = true): Division
6264
{
63-
return new Division($this, $right);
65+
return new Division($this, $right, $insertParentheses);
6466
}
6567

6668
/**
6769
* Perform an exponentiation with the given expression.
6870
*
6971
* @param NumeralType $right
72+
* @param bool $insertParentheses
7073
* @return Exponentiation
7174
*/
72-
public function exponentiate(NumeralType $right): Exponentiation
75+
public function exponentiate(NumeralType $right, bool $insertParentheses = true): Exponentiation
7376
{
74-
return new Exponentiation($this, $right);
77+
return new Exponentiation($this, $right, $insertParentheses);
7578
}
7679

7780
/**
7881
* Perform a greater than comparison against the given expression.
7982
*
8083
* @param NumeralType $right
84+
* @param bool $insertParentheses
8185
* @return GreaterThan
8286
*/
83-
public function gt(NumeralType $right): GreaterThan
87+
public function gt(NumeralType $right, bool $insertParentheses = true): GreaterThan
8488
{
85-
return new GreaterThan($this, $right);
89+
return new GreaterThan($this, $right, $insertParentheses);
8690
}
8791

8892
/**
8993
* Perform a greater than or equal comparison against the given expression.
9094
*
9195
* @param NumeralType $right
96+
* @param bool $insertParentheses
9297
* @return GreaterThanOrEqual
9398
*/
94-
public function gte(NumeralType $right): GreaterThanOrEqual
99+
public function gte(NumeralType $right, bool $insertParentheses = true): GreaterThanOrEqual
95100
{
96-
return new GreaterThanOrEqual($this, $right);
101+
return new GreaterThanOrEqual($this, $right, $insertParentheses);
97102
}
98103

99104
/**
100105
* Perform a less than comparison against the given expression.
101106
*
102107
* @param NumeralType $right
108+
* @param bool $insertParentheses
103109
* @return LessThan
104110
*/
105-
public function lt(NumeralType $right): LessThan
111+
public function lt(NumeralType $right, bool $insertParentheses = true): LessThan
106112
{
107-
return new LessThan($this, $right);
113+
return new LessThan($this, $right, $insertParentheses);
108114
}
109115

110116
/**
111117
* Perform a less than or equal comparison against the given expression.
112118
*
113119
* @param NumeralType $right
120+
* @param bool $insertParentheses
114121
* @return LessThanOrEqual
115122
*/
116-
public function lte(NumeralType $right): LessThanOrEqual
123+
public function lte(NumeralType $right, bool $insertParentheses = true): LessThanOrEqual
117124
{
118-
return new LessThanOrEqual($this, $right);
125+
return new LessThanOrEqual($this, $right, $insertParentheses);
119126
}
120127

121128
/**
122129
* Perform the modulo operation with the given expression.
123130
*
124131
* @param NumeralType $right
132+
* @param bool $insertParentheses
125133
* @return Modulo
126134
*/
127-
public function mod(NumeralType $right): Modulo
135+
public function mod(NumeralType $right, bool $insertParentheses = true): Modulo
128136
{
129-
return new Modulo($this, $right);
137+
return new Modulo($this, $right, $insertParentheses);
130138
}
131139

132140
/**
133141
* Perform a multiplication with the given expression.
134142
*
135143
* @param NumeralType $right
144+
* @param bool $insertParentheses
136145
* @return Multiplication
137146
*/
138-
public function times(NumeralType $right): Multiplication
147+
public function times(NumeralType $right, bool $insertParentheses = true): Multiplication
139148
{
140-
return new Multiplication($this, $right);
149+
return new Multiplication($this, $right, $insertParentheses);
141150
}
142151

143152
/**
144153
* Subtract the given expression from this expression.
145154
*
146155
* @param NumeralType $right
156+
* @param bool $insertParentheses
147157
* @return Subtraction
148158
*/
149-
public function minus(NumeralType $right): Subtraction
159+
public function minus(NumeralType $right, bool $insertParentheses = true): Subtraction
150160
{
151-
return new Subtraction($this, $right);
161+
return new Subtraction($this, $right, $insertParentheses);
152162
}
153163

154164
/**

src/Traits/PropertyTypeTrait.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,32 +39,35 @@ trait PropertyTypeTrait
3939
* Perform an equality check or an assignment with the given expression.
4040
*
4141
* @param PropertyType $right
42+
* @param bool $insertParentheses
4243
* @return Equality
4344
*/
44-
public function equals(PropertyType $right): Equality
45+
public function equals(PropertyType $right, bool $insertParentheses = true): Equality
4546
{
46-
return new Equality($this, $right);
47+
return new Equality($this, $right, $insertParentheses);
4748
}
4849

4950
/**
5051
* Perform an inequality comparison against the given expression.
5152
*
5253
* @param PropertyType $right
54+
* @param bool $insertParentheses
5355
* @return Inequality
5456
*/
55-
public function notEquals(PropertyType $right): Inequality
57+
public function notEquals(PropertyType $right, bool $insertParentheses = true): Inequality
5658
{
57-
return new Inequality($this, $right);
59+
return new Inequality($this, $right, $insertParentheses);
5860
}
5961

6062
/**
6163
* Checks whether the element exists in the given list.
6264
*
6365
* @param ListType $right
66+
* @param bool $insertParentheses
6467
* @return In
6568
*/
66-
public function in(ListType $right): In
69+
public function in(ListType $right, bool $insertParentheses = true): In
6770
{
68-
return new In($this, $right);
71+
return new In($this, $right, $insertParentheses);
6972
}
7073
}

src/Traits/StringTypeTrait.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,32 +37,35 @@ trait StringTypeTrait
3737
* Check whether this expression the given expression.
3838
*
3939
* @param StringType $right
40+
* @param bool $insertParentheses
4041
* @return Contains
4142
*/
42-
public function contains(StringType $right): Contains
43+
public function contains(StringType $right, bool $insertParentheses = true): Contains
4344
{
44-
return new Contains($this, $right);
45+
return new Contains($this, $right, $insertParentheses);
4546
}
4647

4748
/**
4849
* Perform a suffix string search with the given expression.
4950
*
5051
* @param StringType $right
52+
* @param bool $insertParentheses
5153
* @return EndsWith
5254
*/
53-
public function endsWith(StringType $right): EndsWith
55+
public function endsWith(StringType $right, bool $insertParentheses = true): EndsWith
5456
{
55-
return new EndsWith($this, $right);
57+
return new EndsWith($this, $right, $insertParentheses);
5658
}
5759

5860
/**
5961
* Perform a prefix string search with the given expression.
6062
*
6163
* @param StringType $right
64+
* @param bool $insertParentheses
6265
* @return StartsWith
6366
*/
64-
public function startsWith(StringType $right): StartsWith
67+
public function startsWith(StringType $right, bool $insertParentheses = true): StartsWith
6568
{
66-
return new StartsWith($this, $right);
69+
return new StartsWith($this, $right, $insertParentheses);
6770
}
6871
}

0 commit comments

Comments
 (0)