Skip to content

Commit 3c5c27a

Browse files
committed
Applied rules:
* RemoveUnusedVariableInCatchRector (https://wiki.php.net/rfc/non-capturing_catches) * ClassPropertyAssignToConstructorPromotionRector (https://wiki.php.net/rfc/constructor_promotion php/php-src#5291) * StrContainsRector (https://externals.io/message/108562 php/php-src#5179)
1 parent 9cba973 commit 3c5c27a

File tree

6 files changed

+50
-110
lines changed

6 files changed

+50
-110
lines changed

Classes/Database/DatabaseConnection.php

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public function initialize()
212212
* @param bool|array|string $no_quote_fields See fullQuoteArray()
213213
* @return bool|\mysqli_result|object MySQLi result object / DBAL object
214214
*/
215-
public function exec_INSERTquery($table, $fields_values, $no_quote_fields = false)
215+
public function exec_INSERTquery($table, $fields_values, array|bool|string $no_quote_fields = false): bool|\mysqli_result|object
216216
{
217217
$this->logDeprecation();
218218
$res = $this->query($this->INSERTquery($table, $fields_values, $no_quote_fields));
@@ -235,7 +235,7 @@ public function exec_INSERTquery($table, $fields_values, $no_quote_fields = fals
235235
* @param bool|array|string $no_quote_fields See fullQuoteArray()
236236
* @return bool|\mysqli_result|object MySQLi result object / DBAL object
237237
*/
238-
public function exec_INSERTmultipleRows($table, array $fields, array $rows, $no_quote_fields = false)
238+
public function exec_INSERTmultipleRows($table, array $fields, array $rows, array|bool|string $no_quote_fields = false): bool|\mysqli_result|object
239239
{
240240
$this->logDeprecation();
241241
$res = $this->query($this->INSERTmultipleRows($table, $fields, $rows, $no_quote_fields));
@@ -259,7 +259,7 @@ public function exec_INSERTmultipleRows($table, array $fields, array $rows, $no_
259259
* @param bool|array|string $no_quote_fields See fullQuoteArray()
260260
* @return bool|\mysqli_result|object MySQLi result object / DBAL object
261261
*/
262-
public function exec_UPDATEquery($table, $where, $fields_values, $no_quote_fields = false)
262+
public function exec_UPDATEquery($table, $where, $fields_values, array|bool|string $no_quote_fields = false): bool|\mysqli_result|object
263263
{
264264
$this->logDeprecation();
265265
$res = $this->query($this->UPDATEquery($table, $where, $fields_values, $no_quote_fields));
@@ -280,7 +280,7 @@ public function exec_UPDATEquery($table, $where, $fields_values, $no_quote_field
280280
* @param string $where WHERE clause, eg. "uid=1". NOTICE: You must escape values in this argument with $this->fullQuoteStr() yourself!
281281
* @return bool|\mysqli_result|object MySQLi result object / DBAL object
282282
*/
283-
public function exec_DELETEquery($table, $where)
283+
public function exec_DELETEquery($table, $where): bool|\mysqli_result|object
284284
{
285285
$this->logDeprecation();
286286
$res = $this->query($this->DELETEquery($table, $where));
@@ -306,7 +306,7 @@ public function exec_DELETEquery($table, $where)
306306
* @param string $limit Optional LIMIT value ([begin,]max), if none, supply blank string.
307307
* @return bool|\mysqli_result|object MySQLi result object / DBAL object
308308
*/
309-
public function exec_SELECTquery($select_fields, $from_table, $where_clause, $groupBy = '', $orderBy = '', $limit = '')
309+
public function exec_SELECTquery($select_fields, $from_table, $where_clause, $groupBy = '', $orderBy = '', $limit = ''): bool|\mysqli_result|object
310310
{
311311
$this->logDeprecation();
312312
$query = $this->SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy, $limit);
@@ -341,7 +341,7 @@ public function exec_SELECTquery($select_fields, $from_table, $where_clause, $gr
341341
* @return bool|\mysqli_result|object MySQLi result object / DBAL object
342342
* @see exec_SELECTquery()
343343
*/
344-
public function exec_SELECT_mm_query($select, $local_table, $mm_table, $foreign_table, $whereClause = '', $groupBy = '', $orderBy = '', $limit = '')
344+
public function exec_SELECT_mm_query($select, $local_table, $mm_table, $foreign_table, $whereClause = '', $groupBy = '', $orderBy = '', $limit = ''): bool|\mysqli_result|object
345345
{
346346
$this->logDeprecation();
347347
$queryParts = $this->getSelectMmQueryParts($select, $local_table, $mm_table, $foreign_table, $whereClause, $groupBy, $orderBy, $limit);
@@ -355,7 +355,7 @@ public function exec_SELECT_mm_query($select, $local_table, $mm_table, $foreign_
355355
* @return bool|\mysqli_result|object MySQLi result object / DBAL object
356356
* @see exec_SELECTquery()
357357
*/
358-
public function exec_SELECT_queryArray($queryParts)
358+
public function exec_SELECT_queryArray($queryParts): bool|\mysqli_result|object
359359
{
360360
$this->logDeprecation();
361361
return $this->exec_SELECTquery($queryParts['SELECT'], $queryParts['FROM'], $queryParts['WHERE'], $queryParts['GROUPBY'], $queryParts['ORDERBY'], $queryParts['LIMIT']);
@@ -476,9 +476,8 @@ public function exec_TRUNCATEquery($table)
476476
* Use this to execute database queries instead of directly calling $this->link->query()
477477
*
478478
* @param string $query The query to send to the database
479-
* @return bool|\mysqli_result
480479
*/
481-
protected function query($query)
480+
protected function query($query): bool|\mysqli_result
482481
{
483482
$this->logDeprecation();
484483
if (!$this->isConnected) {
@@ -500,7 +499,7 @@ protected function query($query)
500499
* @param bool|array|string $no_quote_fields See fullQuoteArray()
501500
* @return string|NULL Full SQL query for INSERT, NULL if $fields_values is empty
502501
*/
503-
public function INSERTquery($table, $fields_values, $no_quote_fields = false)
502+
public function INSERTquery($table, $fields_values, array|bool|string $no_quote_fields = false)
504503
{
505504
$this->logDeprecation();
506505
// Table and fieldnames should be "SQL-injection-safe" when supplied to this
@@ -531,7 +530,7 @@ public function INSERTquery($table, $fields_values, $no_quote_fields = false)
531530
* @param bool|array|string $no_quote_fields See fullQuoteArray()
532531
* @return string|NULL Full SQL query for INSERT, NULL if $rows is empty
533532
*/
534-
public function INSERTmultipleRows($table, array $fields, array $rows, $no_quote_fields = false)
533+
public function INSERTmultipleRows($table, array $fields, array $rows, array|bool|string $no_quote_fields = false)
535534
{
536535
$this->logDeprecation();
537536
// Table and fieldnames should be "SQL-injection-safe" when supplied to this
@@ -570,7 +569,7 @@ public function INSERTmultipleRows($table, array $fields, array $rows, $no_quote
570569
* @throws \InvalidArgumentException
571570
* @return string Full SQL query for UPDATE
572571
*/
573-
public function UPDATEquery($table, $where, $fields_values, $no_quote_fields = false)
572+
public function UPDATEquery($table, $where, $fields_values, array|bool|string $no_quote_fields = false)
574573
{
575574
$this->logDeprecation();
576575
// Table and fieldnames should be "SQL-injection-safe" when supplied to this
@@ -748,7 +747,7 @@ public function listQuery($field, $value, $table)
748747
{
749748
$this->logDeprecation();
750749
$value = (string)$value;
751-
if (strpos($value, ',') !== false) {
750+
if (str_contains($value, ',')) {
752751
throw new \InvalidArgumentException('$value must not contain a comma (,) in $this->listQuery() !', 1294585862);
753752
}
754753
$pattern = $this->quoteStr($value, $table);
@@ -768,13 +767,10 @@ public function listQuery($field, $value, $table)
768767
public function searchQuery($searchWords, $fields, $table, $constraint = self::AND_Constraint)
769768
{
770769
$this->logDeprecation();
771-
switch ($constraint) {
772-
case self::OR_Constraint:
773-
$constraint = 'OR';
774-
break;
775-
default:
776-
$constraint = 'AND';
777-
}
770+
$constraint = match ($constraint) {
771+
self::OR_Constraint => 'OR',
772+
default => 'AND',
773+
};
778774

779775
$queryParts = [];
780776
foreach ($searchWords as $sw) {
@@ -838,7 +834,7 @@ public function prepare_SELECTqueryArray(array $queryParts, array $input_paramet
838834
* @return \mysqli_stmt|object MySQLi statement / DBAL object
839835
* @internal This method may only be called by \TYPO3\CMS\Typo3DbLegacy\Database\PreparedStatement
840836
*/
841-
public function prepare_PREPAREDquery($query, array $queryComponents)
837+
public function prepare_PREPAREDquery($query, array $queryComponents): \mysqli_stmt|object
842838
{
843839
$this->logDeprecation();
844840
if (!$this->isConnected) {
@@ -897,7 +893,7 @@ public function fullQuoteStr($str, $table, $allowNull = false)
897893
* @return array The input array with the values quoted
898894
* @see cleanIntArray()
899895
*/
900-
public function fullQuoteArray($arr, $table, $noQuote = false, $allowNull = false)
896+
public function fullQuoteArray($arr, $table, array|bool|string $noQuote = false, $allowNull = false)
901897
{
902898
$this->logDeprecation();
903899
if (is_string($noQuote)) {
@@ -1070,7 +1066,7 @@ protected function getSelectMmQueryParts($select, $local_table, $mm_table, $fore
10701066
* @param string $query Query to execute
10711067
* @return bool|\mysqli_result|object MySQLi result object / DBAL object
10721068
*/
1073-
public function sql_query($query)
1069+
public function sql_query($query): bool|\mysqli_result|object
10741070
{
10751071
$this->logDeprecation();
10761072
$res = $this->query($query);
@@ -1125,7 +1121,7 @@ public function sql_num_rows($res)
11251121
* @param bool|\mysqli_result|object $res MySQLi result object / DBAL object
11261122
* @return array|bool Associative array of result row.
11271123
*/
1128-
public function sql_fetch_assoc($res)
1124+
public function sql_fetch_assoc($res): array|bool
11291125
{
11301126
$this->logDeprecation();
11311127
if ($this->debug_check_recordset($res)) {
@@ -1148,7 +1144,7 @@ public function sql_fetch_assoc($res)
11481144
* @param bool|\mysqli_result|object $res MySQLi result object / DBAL object
11491145
* @return array|bool Array with result rows.
11501146
*/
1151-
public function sql_fetch_row($res)
1147+
public function sql_fetch_row($res): array|bool
11521148
{
11531149
$this->logDeprecation();
11541150
if ($this->debug_check_recordset($res)) {
@@ -1304,7 +1300,7 @@ public function sql_pconnect()
13041300
/** @var \Doctrine\DBAL\Driver\Mysqli\MysqliConnection $mysqliConnection */
13051301
$mysqliConnection = $connection->getWrappedConnection();
13061302
$this->link = $mysqliConnection->getWrappedResourceHandle();
1307-
} catch (\Doctrine\DBAL\Exception\ConnectionException $exception) {
1303+
} catch (\Doctrine\DBAL\Exception\ConnectionException) {
13081304
return false;
13091305
}
13101306

@@ -1380,7 +1376,7 @@ public function admin_get_dbs()
13801376
if ($this->sql_select_db()) {
13811377
$dbArr[] = $row->SCHEMA_NAME;
13821378
}
1383-
} catch (\RuntimeException $exception) {
1379+
} catch (\RuntimeException) {
13841380
// The exception happens if we cannot connect to the database
13851381
// (usually due to missing permissions). This is ok here.
13861382
// We catch the exception, skip the database and continue.
@@ -1489,7 +1485,7 @@ public function admin_get_charsets()
14891485
* @param string $query Query to execute
14901486
* @return bool|\mysqli_result|object MySQLi result object / DBAL object
14911487
*/
1492-
public function admin_query($query)
1488+
public function admin_query($query): bool|\mysqli_result|object
14931489
{
14941490
$this->logDeprecation();
14951491
$res = $this->query($query);

Classes/Database/PostProcessQueryHookInterface.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ interface PostProcessQueryHookInterface
2929
* @param string $groupBy Group by statement
3030
* @param string $orderBy Order by statement
3131
* @param int $limit Database return limit
32-
* @param \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject
3332
*/
3433
public function exec_SELECTquery_postProcessAction(&$select_fields, &$from_table, &$where_clause, &$groupBy, &$orderBy, &$limit, \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject);
3534

@@ -39,9 +38,8 @@ public function exec_SELECTquery_postProcessAction(&$select_fields, &$from_table
3938
* @param string $table Database table name
4039
* @param array $fieldsValues Field values as key => value pairs
4140
* @param string|array $noQuoteFields List/array of keys NOT to quote
42-
* @param \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject
4341
*/
44-
public function exec_INSERTquery_postProcessAction(&$table, array &$fieldsValues, &$noQuoteFields, \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject);
42+
public function exec_INSERTquery_postProcessAction(&$table, array &$fieldsValues, array|string &$noQuoteFields, \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject);
4543

4644
/**
4745
* Post-processor for the exec_INSERTmultipleRows method.
@@ -50,9 +48,8 @@ public function exec_INSERTquery_postProcessAction(&$table, array &$fieldsValues
5048
* @param array $fields Field names
5149
* @param array $rows Table rows
5250
* @param string|array $noQuoteFields List/array of keys NOT to quote
53-
* @param \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject
5451
*/
55-
public function exec_INSERTmultipleRows_postProcessAction(&$table, array &$fields, array &$rows, &$noQuoteFields, \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject);
52+
public function exec_INSERTmultipleRows_postProcessAction(&$table, array &$fields, array &$rows, array|string &$noQuoteFields, \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject);
5653

5754
/**
5855
* Post-processor for the exec_UPDATEquery method.
@@ -61,24 +58,21 @@ public function exec_INSERTmultipleRows_postProcessAction(&$table, array &$field
6158
* @param string $where WHERE clause
6259
* @param array $fieldsValues Field values as key => value pairs
6360
* @param string|array $noQuoteFields List/array of keys NOT to quote
64-
* @param \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject
6561
*/
66-
public function exec_UPDATEquery_postProcessAction(&$table, &$where, array &$fieldsValues, &$noQuoteFields, \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject);
62+
public function exec_UPDATEquery_postProcessAction(&$table, &$where, array &$fieldsValues, array|string &$noQuoteFields, \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject);
6763

6864
/**
6965
* Post-processor for the exec_DELETEquery method.
7066
*
7167
* @param string $table Database table name
7268
* @param string $where WHERE clause
73-
* @param \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject
7469
*/
7570
public function exec_DELETEquery_postProcessAction(&$table, &$where, \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject);
7671

7772
/**
7873
* Post-processor for the exec_TRUNCATEquery method.
7974
*
8075
* @param string $table Database table name
81-
* @param \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject
8276
*/
8377
public function exec_TRUNCATEquery_postProcessAction(&$table, \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject);
8478
}

Classes/Database/PreProcessQueryHookInterface.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ interface PreProcessQueryHookInterface
2929
* @param string $groupBy Group by statement
3030
* @param string $orderBy Order by statement
3131
* @param int $limit Database return limit
32-
* @param \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject
3332
*/
3433
public function SELECTquery_preProcessAction(&$select_fields, &$from_table, &$where_clause, &$groupBy, &$orderBy, &$limit, \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject);
3534

@@ -39,9 +38,8 @@ public function SELECTquery_preProcessAction(&$select_fields, &$from_table, &$wh
3938
* @param string $table Database table name
4039
* @param array $fieldsValues Field values as key => value pairs
4140
* @param string|array $noQuoteFields List/array of keys NOT to quote
42-
* @param \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject
4341
*/
44-
public function INSERTquery_preProcessAction(&$table, array &$fieldsValues, &$noQuoteFields, \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject);
42+
public function INSERTquery_preProcessAction(&$table, array &$fieldsValues, array|string &$noQuoteFields, \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject);
4543

4644
/**
4745
* Pre-processor for the INSERTmultipleRows method.
@@ -52,9 +50,8 @@ public function INSERTquery_preProcessAction(&$table, array &$fieldsValues, &$no
5250
* @param array $fields Field names
5351
* @param array $rows Table rows
5452
* @param string|array $noQuoteFields List/array of keys NOT to quote
55-
* @param \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject
5653
*/
57-
public function INSERTmultipleRows_preProcessAction(&$table, array &$fields, array &$rows, &$noQuoteFields, \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject);
54+
public function INSERTmultipleRows_preProcessAction(&$table, array &$fields, array &$rows, array|string &$noQuoteFields, \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject);
5855

5956
/**
6057
* Pre-processor for the UPDATEquery method.
@@ -63,24 +60,21 @@ public function INSERTmultipleRows_preProcessAction(&$table, array &$fields, arr
6360
* @param string $where WHERE clause
6461
* @param array $fieldsValues Field values as key => value pairs
6562
* @param string|array $noQuoteFields List/array of keys NOT to quote
66-
* @param \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject
6763
*/
68-
public function UPDATEquery_preProcessAction(&$table, &$where, array &$fieldsValues, &$noQuoteFields, \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject);
64+
public function UPDATEquery_preProcessAction(&$table, &$where, array &$fieldsValues, array|string &$noQuoteFields, \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject);
6965

7066
/**
7167
* Pre-processor for the DELETEquery method.
7268
*
7369
* @param string $table Database table name
7470
* @param string $where WHERE clause
75-
* @param \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject
7671
*/
7772
public function DELETEquery_preProcessAction(&$table, &$where, \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject);
7873

7974
/**
8075
* Pre-processor for the TRUNCATEquery method.
8176
*
8277
* @param string $table Database table name
83-
* @param \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject
8478
*/
8579
public function TRUNCATEquery_preProcessAction(&$table, \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject);
8680
}

0 commit comments

Comments
 (0)