Skip to content

Commit c5509ef

Browse files
committed
groupStart() refactorization
1 parent 1fa1e10 commit c5509ef

File tree

1 file changed

+54
-51
lines changed

1 file changed

+54
-51
lines changed

system/Database/BaseBuilder.php

Lines changed: 54 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,25 +1237,11 @@ protected function _like_statement(string $prefix = null, string $column, string
12371237
/**
12381238
* Starts a query group.
12391239
*
1240-
* @param string $not (Internal use only)
1241-
* @param string $type (Internal use only)
1242-
*
12431240
* @return BaseBuilder
12441241
*/
1245-
public function groupStart(string $not = '', string $type = 'AND ')
1242+
public function groupStart()
12461243
{
1247-
$type = $this->groupGetType($type);
1248-
1249-
$this->QBWhereGroupStarted = true;
1250-
$prefix = empty($this->QBWhere) ? '' : $type;
1251-
$where = [
1252-
'condition' => $prefix . $not . str_repeat(' ', ++ $this->QBWhereGroupCount) . ' (',
1253-
'escape' => false,
1254-
];
1255-
1256-
$this->QBWhere[] = $where;
1257-
1258-
return $this;
1244+
return $this->groupStartPrepare('', 'AND ', 'QBWhere');
12591245
}
12601246

12611247
//--------------------------------------------------------------------
@@ -1267,7 +1253,7 @@ public function groupStart(string $not = '', string $type = 'AND ')
12671253
*/
12681254
public function orGroupStart()
12691255
{
1270-
return $this->groupStart('', 'OR ');
1256+
return $this->groupStartPrepare('', 'OR ', 'QBWhere');
12711257
}
12721258

12731259
//--------------------------------------------------------------------
@@ -1279,7 +1265,7 @@ public function orGroupStart()
12791265
*/
12801266
public function notGroupStart()
12811267
{
1282-
return $this->groupStart('NOT ', 'AND ');
1268+
return $this->groupStartPrepare('NOT ', 'AND ', 'QBWhere');
12831269
}
12841270

12851271
//--------------------------------------------------------------------
@@ -1291,7 +1277,7 @@ public function notGroupStart()
12911277
*/
12921278
public function orNotGroupStart()
12931279
{
1294-
return $this->groupStart('NOT ', 'OR ');
1280+
return $this->groupStartPrepare('NOT ', 'OR ', 'QBWhere');
12951281
}
12961282

12971283
//--------------------------------------------------------------------
@@ -1303,42 +1289,19 @@ public function orNotGroupStart()
13031289
*/
13041290
public function groupEnd()
13051291
{
1306-
$this->QBWhereGroupStarted = false;
1307-
$where = [
1308-
'condition' => str_repeat(' ', $this->QBWhereGroupCount -- ) . ')',
1309-
'escape' => false,
1310-
];
1311-
1312-
$this->QBWhere[] = $where;
1313-
1314-
return $this;
1292+
return $this->groupEndPrepare('QBWhere');
13151293
}
13161294

13171295
// --------------------------------------------------------------------
13181296

13191297
/**
13201298
* Starts a query group for HAVING clause.
13211299
*
1322-
* @param string $not (Internal use only)
1323-
* @param string $type (Internal use only)
1324-
*
13251300
* @return BaseBuilder
13261301
*/
1327-
public function havingGroupStart(string $not = '', string $type = 'AND ')
1302+
public function havingGroupStart()
13281303
{
1329-
$type = $this->groupGetType($type);
1330-
1331-
$this->QBWhereGroupStarted = true;
1332-
$prefix = empty($this->QBHaving) ? '' : $type;
1333-
$having = [
1334-
'condition' => $prefix . $not . str_repeat(' ', ++$this->QBWhereGroupCount) . ' (',
1335-
'value' => null,
1336-
'escape' => false,
1337-
];
1338-
1339-
$this->QBHaving[] = $having;
1340-
1341-
return $this;
1304+
return $this->groupStartPrepare('', 'AND ', 'QBHaving');
13421305
}
13431306

13441307
// --------------------------------------------------------------------
@@ -1350,7 +1313,7 @@ public function havingGroupStart(string $not = '', string $type = 'AND ')
13501313
*/
13511314
public function orHavingGroupStart()
13521315
{
1353-
return $this->havingGroupStart('', 'OR ');
1316+
return $this->groupStartPrepare('', 'OR ', 'QBHaving');
13541317
}
13551318

13561319
// --------------------------------------------------------------------
@@ -1362,7 +1325,7 @@ public function orHavingGroupStart()
13621325
*/
13631326
public function notHavingGroupStart()
13641327
{
1365-
return $this->havingGroupStart('NOT ', 'AND ');
1328+
return $this->groupStartPrepare('NOT ', 'AND ', 'QBHaving');
13661329
}
13671330

13681331
// --------------------------------------------------------------------
@@ -1374,7 +1337,7 @@ public function notHavingGroupStart()
13741337
*/
13751338
public function orNotHavingGroupStart()
13761339
{
1377-
return $this->havingGroupStart('NOT ', 'OR ');
1340+
return $this->groupStartPrepare('NOT ', 'OR ', 'QBHaving');
13781341
}
13791342

13801343
// --------------------------------------------------------------------
@@ -1385,15 +1348,55 @@ public function orNotHavingGroupStart()
13851348
* @return BaseBuilder
13861349
*/
13871350
public function havingGroupEnd()
1351+
{
1352+
return $this->groupEndPrepare('QBHaving');
1353+
}
1354+
1355+
//--------------------------------------------------------------------
1356+
1357+
/**
1358+
* Prepate a query group start.
1359+
*
1360+
* @param string $not
1361+
* @param string $type
1362+
* @param string $clause
1363+
*
1364+
* @return BaseBuilder
1365+
*/
1366+
protected function groupStartPrepare(string $not = '', string $type = 'AND ', string $clause = 'QBWhere')
1367+
{
1368+
$type = $this->groupGetType($type);
1369+
1370+
$this->QBWhereGroupStarted = true;
1371+
$prefix = empty($this->$clause) ? '' : $type;
1372+
$where = [
1373+
'condition' => $prefix . $not . str_repeat(' ', ++ $this->QBWhereGroupCount) . ' (',
1374+
'escape' => false,
1375+
];
1376+
1377+
$this->{$clause}[] = $where;
1378+
1379+
return $this;
1380+
}
1381+
1382+
//--------------------------------------------------------------------
1383+
1384+
/**
1385+
* Prepate a query group end.
1386+
*
1387+
* @param string $clause
1388+
*
1389+
* @return BaseBuilder
1390+
*/
1391+
protected function groupEndPrepare(string $clause = 'QBWhere')
13881392
{
13891393
$this->QBWhereGroupStarted = false;
1390-
$having = [
1394+
$where = [
13911395
'condition' => str_repeat(' ', $this->QBWhereGroupCount -- ) . ')',
1392-
'value' => null,
13931396
'escape' => false,
13941397
];
13951398

1396-
$this->QBHaving[] = $having;
1399+
$this->{$clause}[] = $where;
13971400

13981401
return $this;
13991402
}

0 commit comments

Comments
 (0)