Skip to content

Commit d2465a8

Browse files
authored
Merge pull request #1938 from atishamte/db_typos
Database typos changes
2 parents 5d49d2c + b3029fd commit d2465a8

28 files changed

+305
-252
lines changed

system/Database/BaseBuilder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,18 +1251,18 @@ public function orderBy(string $orderBy, string $direction = '', bool $escape =
12511251

12521252
if ($escape === false)
12531253
{
1254-
$qb_orderby[] = [
1254+
$qb_orderBy[] = [
12551255
'field' => $orderBy,
12561256
'direction' => $direction,
12571257
'escape' => false,
12581258
];
12591259
}
12601260
else
12611261
{
1262-
$qb_orderby = [];
1262+
$qb_orderBy = [];
12631263
foreach (explode(',', $orderBy) as $field)
12641264
{
1265-
$qb_orderby[] = ($direction === '' && preg_match('/\s+(ASC|DESC)$/i', rtrim($field), $match, PREG_OFFSET_CAPTURE))
1265+
$qb_orderBy[] = ($direction === '' && preg_match('/\s+(ASC|DESC)$/i', rtrim($field), $match, PREG_OFFSET_CAPTURE))
12661266
?
12671267
[
12681268
'field' => ltrim(substr($field, 0, $match[0][1])),
@@ -1278,7 +1278,7 @@ public function orderBy(string $orderBy, string $direction = '', bool $escape =
12781278
}
12791279
}
12801280

1281-
$this->QBOrderBy = array_merge($this->QBOrderBy, $qb_orderby);
1281+
$this->QBOrderBy = array_merge($this->QBOrderBy, $qb_orderBy);
12821282

12831283
return $this;
12841284
}

system/Database/BaseConnection.php

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -422,12 +422,14 @@ public function initialize()
422422
* @param boolean $persistent
423423
* @return mixed
424424
*/
425-
abstract public function connect($persistent = false);
425+
abstract public function connect(bool $persistent = false);
426426

427427
//--------------------------------------------------------------------
428428

429429
/**
430430
* Close the database connection.
431+
*
432+
* @return void
431433
*/
432434
public function close()
433435
{
@@ -526,9 +528,9 @@ public function getError()
526528
/**
527529
* The name of the platform in use (MySQLi, mssql, etc)
528530
*
529-
* @return mixed
531+
* @return string
530532
*/
531-
public function getPlatform()
533+
public function getPlatform(): string
532534
{
533535
return $this->DBDriver;
534536
}
@@ -538,9 +540,9 @@ public function getPlatform()
538540
/**
539541
* Returns a string containing the version of the database being used.
540542
*
541-
* @return mixed
543+
* @return string
542544
*/
543-
abstract public function getVersion();
545+
abstract public function getVersion(): string;
544546

545547
//--------------------------------------------------------------------
546548

@@ -586,7 +588,7 @@ public function addTableAlias(string $table)
586588
*
587589
* @return mixed
588590
*/
589-
abstract protected function execute($sql);
591+
abstract protected function execute(string $sql);
590592

591593
//--------------------------------------------------------------------
592594

@@ -599,13 +601,13 @@ abstract protected function execute($sql);
599601
* queries if needed.
600602
*
601603
* @param string $sql
602-
* @param array ...$binds
604+
* @param mixed ...$binds
603605
* @param boolean $setEscapeFlags
604606
* @param string $queryClass
605607
*
606608
* @return BaseResult|Query|false
607609
*/
608-
public function query(string $sql, $binds = null, bool $setEscapeFlags = true, $queryClass = 'CodeIgniter\\Database\\Query')
610+
public function query(string $sql, $binds = null, bool $setEscapeFlags = true, string $queryClass = 'CodeIgniter\\Database\\Query')
609611
{
610612
if (empty($this->connID))
611613
{
@@ -713,6 +715,8 @@ public function simpleQuery(string $sql)
713715
* Disable Transactions
714716
*
715717
* This permits transactions to be disabled at run-time.
718+
*
719+
* @return void
716720
*/
717721
public function transOff()
718722
{
@@ -750,7 +754,7 @@ public function transStrict(bool $mode = true)
750754
* @param boolean $test_mode = FALSE
751755
* @return boolean
752756
*/
753-
public function transStart($test_mode = false)
757+
public function transStart(bool $test_mode = false): bool
754758
{
755759
if (! $this->transEnabled)
756760
{
@@ -767,7 +771,7 @@ public function transStart($test_mode = false)
767771
*
768772
* @return boolean
769773
*/
770-
public function transComplete()
774+
public function transComplete(): bool
771775
{
772776
if (! $this->transEnabled)
773777
{
@@ -924,7 +928,7 @@ abstract protected function _transRollback(): bool;
924928
/**
925929
* Returns an instance of the query builder for this connection.
926930
*
927-
* @param string $tableName
931+
* @param string|array $tableName
928932
*
929933
* @return BaseBuilder
930934
* @throws DatabaseException
@@ -1008,7 +1012,7 @@ public function getLastQuery()
10081012
*
10091013
* @return string
10101014
*/
1011-
public function showLastQuery()
1015+
public function showLastQuery(): string
10121016
{
10131017
return (string) $this->lastQuery;
10141018
}
@@ -1023,7 +1027,7 @@ public function showLastQuery()
10231027
*
10241028
* @return float
10251029
*/
1026-
public function getConnectStart()
1030+
public function getConnectStart(): float
10271031
{
10281032
return $this->connectTime;
10291033
}
@@ -1038,9 +1042,9 @@ public function getConnectStart()
10381042
*
10391043
* @param integer $decimals
10401044
*
1041-
* @return mixed
1045+
* @return string
10421046
*/
1043-
public function getConnectDuration($decimals = 6)
1047+
public function getConnectDuration(int $decimals = 6): string
10441048
{
10451049
return number_format($this->connectDuration, $decimals);
10461050
}
@@ -1067,14 +1071,14 @@ public function getConnectDuration($decimals = 6)
10671071
* insert the table prefix (if it exists) in the proper position, and escape only
10681072
* the correct identifiers.
10691073
*
1070-
* @param string|array
1071-
* @param boolean
1072-
* @param mixed
1073-
* @param boolean
1074+
* @param string|array $item
1075+
* @param boolean $prefixSingle
1076+
* @param boolean $protectIdentifiers
1077+
* @param boolean $fieldExists
10741078
*
10751079
* @return string|array
10761080
*/
1077-
public function protectIdentifiers($item, $prefixSingle = false, $protectIdentifiers = null, $fieldExists = true)
1081+
public function protectIdentifiers($item, bool $prefixSingle = false, bool $protectIdentifiers = null, bool $fieldExists = true)
10781082
{
10791083
if (! is_bool($protectIdentifiers))
10801084
{
@@ -1313,7 +1317,7 @@ public function escapeIdentifiers($item)
13131317
* @return string
13141318
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
13151319
*/
1316-
public function prefixTable($table = '')
1320+
public function prefixTable(string $table = ''): string
13171321
{
13181322
if ($table === '')
13191323
{
@@ -1334,7 +1338,7 @@ public function prefixTable($table = '')
13341338
*
13351339
* @return string
13361340
*/
1337-
public function setPrefix($prefix = '')
1341+
public function setPrefix(string $prefix = ''): string
13381342
{
13391343
return $this->DBPrefix = $prefix;
13401344
}
@@ -1356,7 +1360,7 @@ abstract public function affectedRows(): int;
13561360
* Escapes data based on type.
13571361
* Sets boolean and null types
13581362
*
1359-
* @param $str
1363+
* @param mixed $str
13601364
*
13611365
* @return mixed
13621366
*/
@@ -1395,9 +1399,9 @@ public function escape($str)
13951399
*
13961400
* @param string|string[] $str Input string
13971401
* @param boolean $like Whether or not the string will be used in a LIKE condition
1398-
* @return string
1402+
* @return string|string[]
13991403
*/
1400-
public function escapeString($str, $like = false)
1404+
public function escapeString($str, bool $like = false)
14011405
{
14021406
if (is_array($str))
14031407
{
@@ -1473,7 +1477,7 @@ protected function _escapeString(string $str): string
14731477
* @return boolean
14741478
* @throws DatabaseException
14751479
*/
1476-
public function callFunction(string $functionName, ...$params)
1480+
public function callFunction(string $functionName, ...$params): bool
14771481
{
14781482
$driver = ($this->DBDriver === 'postgre' ? 'pg' : strtolower($this->DBDriver)) . '_';
14791483

@@ -1507,7 +1511,7 @@ public function callFunction(string $functionName, ...$params)
15071511
* @return boolean|array
15081512
* @throws \CodeIgniter\Database\Exceptions\DatabaseException
15091513
*/
1510-
public function listTables($constrain_by_prefix = false)
1514+
public function listTables(bool $constrain_by_prefix = false)
15111515
{
15121516
// Is there a cached result?
15131517
if (isset($this->dataCache['table_names']) && $this->dataCache['table_names'])
@@ -1566,7 +1570,7 @@ public function listTables($constrain_by_prefix = false)
15661570
* @param string $table_name
15671571
* @return boolean
15681572
*/
1569-
public function tableExists($table_name)
1573+
public function tableExists(string $table_name): bool
15701574
{
15711575
return in_array($this->protectIdentifiers($table_name, true, false, false), $this->listTables());
15721576
}
@@ -1581,7 +1585,7 @@ public function tableExists($table_name)
15811585
* @return array|false
15821586
* @throws DatabaseException
15831587
*/
1584-
public function getFieldNames($table)
1588+
public function getFieldNames(string $table)
15851589
{
15861590
// Is there a cached result?
15871591
if (isset($this->dataCache['field_names'][$table]))
@@ -1637,11 +1641,11 @@ public function getFieldNames($table)
16371641
/**
16381642
* Determine if a particular field exists
16391643
*
1640-
* @param string
1641-
* @param string
1644+
* @param string $fieldName
1645+
* @param string $tableName
16421646
* @return boolean
16431647
*/
1644-
public function fieldExists($fieldName, $tableName)
1648+
public function fieldExists(string $fieldName, string $tableName): bool
16451649
{
16461650
return in_array($fieldName, $this->getFieldNames($tableName));
16471651
}
@@ -1735,7 +1739,7 @@ public function resetDataCache()
17351739
*
17361740
* @return array
17371741
*/
1738-
abstract public function error();
1742+
abstract public function error(): array;
17391743

17401744
//--------------------------------------------------------------------
17411745

@@ -1744,7 +1748,7 @@ abstract public function error();
17441748
*
17451749
* @return integer
17461750
*/
1747-
abstract public function insertID();
1751+
abstract public function insertID(): int;
17481752

17491753
//--------------------------------------------------------------------
17501754

@@ -1755,7 +1759,7 @@ abstract public function insertID();
17551759
*
17561760
* @return string
17571761
*/
1758-
abstract protected function _listTables($constrainByPrefix = false): string;
1762+
abstract protected function _listTables(bool $constrainByPrefix = false): string;
17591763

17601764
//--------------------------------------------------------------------
17611765

@@ -1803,12 +1807,19 @@ abstract protected function _foreignKeyData(string $table): array;
18031807

18041808
//--------------------------------------------------------------------
18051809

1806-
public function __get($key)
1810+
/**
1811+
* @param string $key
1812+
*
1813+
* @return mixed
1814+
*/
1815+
public function __get(string $key)
18071816
{
18081817
if (property_exists($this, $key))
18091818
{
18101819
return $this->$key;
18111820
}
1821+
1822+
return null;
18121823
}
18131824

18141825
//--------------------------------------------------------------------

system/Database/BasePreparedQuery.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
namespace CodeIgniter\Database;
3939

40+
use CodeIgniter\Database\MySQLi\Connection;
4041
use CodeIgniter\Events\Events;
4142

4243
/**
@@ -85,7 +86,7 @@ abstract class BasePreparedQuery implements PreparedQueryInterface
8586

8687
public function __construct(ConnectionInterface $db)
8788
{
88-
$this->db = & $db;
89+
$this->db = &$db;
8990
}
9091

9192
//--------------------------------------------------------------------
@@ -103,7 +104,7 @@ public function __construct(ConnectionInterface $db)
103104
*
104105
* @return mixed
105106
*/
106-
public function prepare(string $sql, array $options = [], $queryClass = 'CodeIgniter\\Database\\Query')
107+
public function prepare(string $sql, array $options = [], string $queryClass = 'CodeIgniter\\Database\\Query')
107108
{
108109
// We only supports positional placeholders (?)
109110
// in order to work with the execute method below, so we
@@ -180,9 +181,9 @@ public function execute(...$data)
180181
*
181182
* @param array $data
182183
*
183-
* @return ResultInterface
184+
* @return boolean
184185
*/
185-
abstract public function _execute($data);
186+
abstract public function _execute(array $data): bool;
186187

187188
//--------------------------------------------------------------------
188189

@@ -196,7 +197,9 @@ abstract public function _getResult();
196197
//--------------------------------------------------------------------
197198

198199
/**
199-
* Explicity closes the statement.
200+
* Explicitly closes the statement.
201+
*
202+
* @return null|void
200203
*/
201204
public function close()
202205
{
@@ -232,7 +235,7 @@ public function getQueryString(): string
232235
*
233236
* @return boolean
234237
*/
235-
public function hasError()
238+
public function hasError(): bool
236239
{
237240
return ! empty($this->errorString);
238241
}

0 commit comments

Comments
 (0)