@@ -148,7 +148,7 @@ public function toInstanceDescriptor(MoufManager $moufManager)
148
148
}
149
149
150
150
/**
151
- * Renders the object as a SQL string.
151
+ * Renders the object as an SQL string.
152
152
*
153
153
* @param array $parameters
154
154
* @param AbstractPlatform $platform
@@ -160,52 +160,45 @@ public function toInstanceDescriptor(MoufManager $moufManager)
160
160
*/
161
161
public function toSql (array $ parameters , AbstractPlatform $ platform , int $ indent = 0 , $ conditionsMode = self ::CONDITION_APPLY , bool $ extrapolateParameters = true ): ?string
162
162
{
163
- $ minBypass = false ;
164
- $ maxBypass = false ;
165
-
166
- if ($ conditionsMode == self ::CONDITION_GUESS ) {
167
- if ($ this ->minValueOperand instanceof Parameter) {
168
- if ($ this ->minValueOperand ->isDiscardedOnNull () && !isset ($ parameters [$ this ->minValueOperand ->getName ()])) {
169
- $ minBypass = true ;
170
- }
171
- }
163
+ switch ($ conditionsMode ) {
164
+ case self ::CONDITION_APPLY :
165
+ $ minBypass = $ this ->minValueCondition && !$ this ->minValueCondition ->isOk ($ parameters );
166
+ $ maxBypass = $ this ->maxValueCondition && !$ this ->maxValueCondition ->isOk ($ parameters );
167
+ break ;
168
+ case self ::CONDITION_GUESS :
169
+ $ minBypass = $ this ->minValueOperand instanceof Parameter && $ this ->minValueOperand ->isDiscardedOnNull () && !isset ($ parameters [$ this ->minValueOperand ->getName ()]);
170
+ $ maxBypass = $ this ->maxValueOperand instanceof Parameter && $ this ->maxValueOperand ->isDiscardedOnNull () && !isset ($ parameters [$ this ->maxValueOperand ->getName ()]);
171
+ break ;
172
+ case self ::CONDITION_IGNORE :
173
+ $ minBypass = false ;
174
+ $ maxBypass = false ;
175
+ break ;
176
+ default :
177
+ throw new \InvalidArgumentException ('Invalid `$conditionsMode`: " ' . $ conditionsMode . '" ' );
178
+ }
172
179
173
- if ($ this ->maxValueOperand instanceof Parameter) {
174
- if ($ this ->maxValueOperand ->isDiscardedOnNull () && !isset ($ parameters [$ this ->maxValueOperand ->getName ()])) {
175
- $ maxBypass = true ;
176
- }
177
- }
178
- } elseif ($ conditionsMode == self ::CONDITION_IGNORE ) {
179
- $ minBypass = false ;
180
- $ maxBypass = false ;
181
- } else {
182
- if ($ this ->minValueCondition && !$ this ->minValueCondition ->isOk ($ parameters )) {
183
- $ minBypass = true ;
184
- }
185
- if ($ this ->maxValueCondition && !$ this ->maxValueCondition ->isOk ($ parameters )) {
186
- $ maxBypass = true ;
187
- }
180
+ if ($ maxBypass && $ minBypass ) {
181
+ return null ;
182
+ }
183
+
184
+ if ($ minBypass ) {
185
+ return sprintf ('%s <= %s ' ,
186
+ NodeFactory::toSql ($ this ->leftOperand , $ platform , $ parameters , ' ' , false , $ indent , $ conditionsMode , $ extrapolateParameters ),
187
+ NodeFactory::toSql ($ this ->maxValueOperand , $ platform , $ parameters , ' ' , false , $ indent , $ conditionsMode , $ extrapolateParameters )
188
+ );
188
189
}
189
190
190
- if (!$ minBypass && !$ maxBypass ) {
191
- $ sql = NodeFactory::toSql ($ this ->leftOperand , $ platform , $ parameters , ' ' , false , $ indent , $ conditionsMode , $ extrapolateParameters );
192
- $ sql .= ' BETWEEN ' ;
193
- $ sql .= NodeFactory::toSql ($ this ->minValueOperand , $ platform , $ parameters , ' ' , false , $ indent , $ conditionsMode , $ extrapolateParameters );
194
- $ sql .= ' AND ' ;
195
- $ sql .= NodeFactory::toSql ($ this ->maxValueOperand , $ platform , $ parameters , ' ' , false , $ indent , $ conditionsMode , $ extrapolateParameters );
196
- } elseif (!$ minBypass && $ maxBypass ) {
197
- $ sql = NodeFactory::toSql ($ this ->leftOperand , $ platform , $ parameters , ' ' , false , $ indent , $ conditionsMode , $ extrapolateParameters );
198
- $ sql .= ' >= ' ;
199
- $ sql .= NodeFactory::toSql ($ this ->minValueOperand , $ platform , $ parameters , ' ' , false , $ indent , $ conditionsMode , $ extrapolateParameters );
200
- } elseif ($ minBypass && !$ maxBypass ) {
201
- $ sql = NodeFactory::toSql ($ this ->leftOperand , $ platform , $ parameters , ' ' , false , $ indent , $ conditionsMode , $ extrapolateParameters );
202
- $ sql .= ' <= ' ;
203
- $ sql .= NodeFactory::toSql ($ this ->maxValueOperand , $ platform , $ parameters , ' ' , false , $ indent , $ conditionsMode , $ extrapolateParameters );
204
- } else {
205
- $ sql = null ;
191
+ if ($ maxBypass ) {
192
+ return sprintf ('%s >= %s ' ,
193
+ NodeFactory::toSql ($ this ->leftOperand , $ platform , $ parameters , ' ' , false , $ indent , $ conditionsMode , $ extrapolateParameters ),
194
+ NodeFactory::toSql ($ this ->minValueOperand , $ platform , $ parameters , ' ' , false , $ indent , $ conditionsMode , $ extrapolateParameters ));
206
195
}
207
196
208
- return $ sql ;
197
+ return sprintf ('%s BETWEEN %s AND %s ' ,
198
+ NodeFactory::toSql ($ this ->leftOperand , $ platform , $ parameters , ' ' , false , $ indent , $ conditionsMode , $ extrapolateParameters ),
199
+ NodeFactory::toSql ($ this ->minValueOperand , $ platform , $ parameters , ' ' , false , $ indent , $ conditionsMode , $ extrapolateParameters ),
200
+ NodeFactory::toSql ($ this ->maxValueOperand , $ platform , $ parameters , ' ' , false , $ indent , $ conditionsMode , $ extrapolateParameters )
201
+ );
209
202
}
210
203
211
204
/**
0 commit comments