Skip to content

Commit

Permalink
Applied rules:
Browse files Browse the repository at this point in the history
 * 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)
  • Loading branch information
franzholz committed Jan 15, 2022
1 parent 9cba973 commit 3c5c27a
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 110 deletions.
52 changes: 24 additions & 28 deletions Classes/Database/DatabaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public function initialize()
* @param bool|array|string $no_quote_fields See fullQuoteArray()
* @return bool|\mysqli_result|object MySQLi result object / DBAL object
*/
public function exec_INSERTquery($table, $fields_values, $no_quote_fields = false)
public function exec_INSERTquery($table, $fields_values, array|bool|string $no_quote_fields = false): bool|\mysqli_result|object
{
$this->logDeprecation();
$res = $this->query($this->INSERTquery($table, $fields_values, $no_quote_fields));
Expand All @@ -235,7 +235,7 @@ public function exec_INSERTquery($table, $fields_values, $no_quote_fields = fals
* @param bool|array|string $no_quote_fields See fullQuoteArray()
* @return bool|\mysqli_result|object MySQLi result object / DBAL object
*/
public function exec_INSERTmultipleRows($table, array $fields, array $rows, $no_quote_fields = false)
public function exec_INSERTmultipleRows($table, array $fields, array $rows, array|bool|string $no_quote_fields = false): bool|\mysqli_result|object
{
$this->logDeprecation();
$res = $this->query($this->INSERTmultipleRows($table, $fields, $rows, $no_quote_fields));
Expand All @@ -259,7 +259,7 @@ public function exec_INSERTmultipleRows($table, array $fields, array $rows, $no_
* @param bool|array|string $no_quote_fields See fullQuoteArray()
* @return bool|\mysqli_result|object MySQLi result object / DBAL object
*/
public function exec_UPDATEquery($table, $where, $fields_values, $no_quote_fields = false)
public function exec_UPDATEquery($table, $where, $fields_values, array|bool|string $no_quote_fields = false): bool|\mysqli_result|object
{
$this->logDeprecation();
$res = $this->query($this->UPDATEquery($table, $where, $fields_values, $no_quote_fields));
Expand All @@ -280,7 +280,7 @@ public function exec_UPDATEquery($table, $where, $fields_values, $no_quote_field
* @param string $where WHERE clause, eg. "uid=1". NOTICE: You must escape values in this argument with $this->fullQuoteStr() yourself!
* @return bool|\mysqli_result|object MySQLi result object / DBAL object
*/
public function exec_DELETEquery($table, $where)
public function exec_DELETEquery($table, $where): bool|\mysqli_result|object
{
$this->logDeprecation();
$res = $this->query($this->DELETEquery($table, $where));
Expand All @@ -306,7 +306,7 @@ public function exec_DELETEquery($table, $where)
* @param string $limit Optional LIMIT value ([begin,]max), if none, supply blank string.
* @return bool|\mysqli_result|object MySQLi result object / DBAL object
*/
public function exec_SELECTquery($select_fields, $from_table, $where_clause, $groupBy = '', $orderBy = '', $limit = '')
public function exec_SELECTquery($select_fields, $from_table, $where_clause, $groupBy = '', $orderBy = '', $limit = ''): bool|\mysqli_result|object
{
$this->logDeprecation();
$query = $this->SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy, $limit);
Expand Down Expand Up @@ -341,7 +341,7 @@ public function exec_SELECTquery($select_fields, $from_table, $where_clause, $gr
* @return bool|\mysqli_result|object MySQLi result object / DBAL object
* @see exec_SELECTquery()
*/
public function exec_SELECT_mm_query($select, $local_table, $mm_table, $foreign_table, $whereClause = '', $groupBy = '', $orderBy = '', $limit = '')
public function exec_SELECT_mm_query($select, $local_table, $mm_table, $foreign_table, $whereClause = '', $groupBy = '', $orderBy = '', $limit = ''): bool|\mysqli_result|object
{
$this->logDeprecation();
$queryParts = $this->getSelectMmQueryParts($select, $local_table, $mm_table, $foreign_table, $whereClause, $groupBy, $orderBy, $limit);
Expand All @@ -355,7 +355,7 @@ public function exec_SELECT_mm_query($select, $local_table, $mm_table, $foreign_
* @return bool|\mysqli_result|object MySQLi result object / DBAL object
* @see exec_SELECTquery()
*/
public function exec_SELECT_queryArray($queryParts)
public function exec_SELECT_queryArray($queryParts): bool|\mysqli_result|object
{
$this->logDeprecation();
return $this->exec_SELECTquery($queryParts['SELECT'], $queryParts['FROM'], $queryParts['WHERE'], $queryParts['GROUPBY'], $queryParts['ORDERBY'], $queryParts['LIMIT']);
Expand Down Expand Up @@ -476,9 +476,8 @@ public function exec_TRUNCATEquery($table)
* Use this to execute database queries instead of directly calling $this->link->query()
*
* @param string $query The query to send to the database
* @return bool|\mysqli_result
*/
protected function query($query)
protected function query($query): bool|\mysqli_result
{
$this->logDeprecation();
if (!$this->isConnected) {
Expand All @@ -500,7 +499,7 @@ protected function query($query)
* @param bool|array|string $no_quote_fields See fullQuoteArray()
* @return string|NULL Full SQL query for INSERT, NULL if $fields_values is empty
*/
public function INSERTquery($table, $fields_values, $no_quote_fields = false)
public function INSERTquery($table, $fields_values, array|bool|string $no_quote_fields = false)
{
$this->logDeprecation();
// Table and fieldnames should be "SQL-injection-safe" when supplied to this
Expand Down Expand Up @@ -531,7 +530,7 @@ public function INSERTquery($table, $fields_values, $no_quote_fields = false)
* @param bool|array|string $no_quote_fields See fullQuoteArray()
* @return string|NULL Full SQL query for INSERT, NULL if $rows is empty
*/
public function INSERTmultipleRows($table, array $fields, array $rows, $no_quote_fields = false)
public function INSERTmultipleRows($table, array $fields, array $rows, array|bool|string $no_quote_fields = false)
{
$this->logDeprecation();
// Table and fieldnames should be "SQL-injection-safe" when supplied to this
Expand Down Expand Up @@ -570,7 +569,7 @@ public function INSERTmultipleRows($table, array $fields, array $rows, $no_quote
* @throws \InvalidArgumentException
* @return string Full SQL query for UPDATE
*/
public function UPDATEquery($table, $where, $fields_values, $no_quote_fields = false)
public function UPDATEquery($table, $where, $fields_values, array|bool|string $no_quote_fields = false)
{
$this->logDeprecation();
// Table and fieldnames should be "SQL-injection-safe" when supplied to this
Expand Down Expand Up @@ -748,7 +747,7 @@ public function listQuery($field, $value, $table)
{
$this->logDeprecation();
$value = (string)$value;
if (strpos($value, ',') !== false) {
if (str_contains($value, ',')) {
throw new \InvalidArgumentException('$value must not contain a comma (,) in $this->listQuery() !', 1294585862);
}
$pattern = $this->quoteStr($value, $table);
Expand All @@ -768,13 +767,10 @@ public function listQuery($field, $value, $table)
public function searchQuery($searchWords, $fields, $table, $constraint = self::AND_Constraint)
{
$this->logDeprecation();
switch ($constraint) {
case self::OR_Constraint:
$constraint = 'OR';
break;
default:
$constraint = 'AND';
}
$constraint = match ($constraint) {
self::OR_Constraint => 'OR',
default => 'AND',
};

$queryParts = [];
foreach ($searchWords as $sw) {
Expand Down Expand Up @@ -838,7 +834,7 @@ public function prepare_SELECTqueryArray(array $queryParts, array $input_paramet
* @return \mysqli_stmt|object MySQLi statement / DBAL object
* @internal This method may only be called by \TYPO3\CMS\Typo3DbLegacy\Database\PreparedStatement
*/
public function prepare_PREPAREDquery($query, array $queryComponents)
public function prepare_PREPAREDquery($query, array $queryComponents): \mysqli_stmt|object
{
$this->logDeprecation();
if (!$this->isConnected) {
Expand Down Expand Up @@ -897,7 +893,7 @@ public function fullQuoteStr($str, $table, $allowNull = false)
* @return array The input array with the values quoted
* @see cleanIntArray()
*/
public function fullQuoteArray($arr, $table, $noQuote = false, $allowNull = false)
public function fullQuoteArray($arr, $table, array|bool|string $noQuote = false, $allowNull = false)
{
$this->logDeprecation();
if (is_string($noQuote)) {
Expand Down Expand Up @@ -1070,7 +1066,7 @@ protected function getSelectMmQueryParts($select, $local_table, $mm_table, $fore
* @param string $query Query to execute
* @return bool|\mysqli_result|object MySQLi result object / DBAL object
*/
public function sql_query($query)
public function sql_query($query): bool|\mysqli_result|object
{
$this->logDeprecation();
$res = $this->query($query);
Expand Down Expand Up @@ -1125,7 +1121,7 @@ public function sql_num_rows($res)
* @param bool|\mysqli_result|object $res MySQLi result object / DBAL object
* @return array|bool Associative array of result row.
*/
public function sql_fetch_assoc($res)
public function sql_fetch_assoc($res): array|bool
{
$this->logDeprecation();
if ($this->debug_check_recordset($res)) {
Expand All @@ -1148,7 +1144,7 @@ public function sql_fetch_assoc($res)
* @param bool|\mysqli_result|object $res MySQLi result object / DBAL object
* @return array|bool Array with result rows.
*/
public function sql_fetch_row($res)
public function sql_fetch_row($res): array|bool
{
$this->logDeprecation();
if ($this->debug_check_recordset($res)) {
Expand Down Expand Up @@ -1304,7 +1300,7 @@ public function sql_pconnect()
/** @var \Doctrine\DBAL\Driver\Mysqli\MysqliConnection $mysqliConnection */
$mysqliConnection = $connection->getWrappedConnection();
$this->link = $mysqliConnection->getWrappedResourceHandle();
} catch (\Doctrine\DBAL\Exception\ConnectionException $exception) {
} catch (\Doctrine\DBAL\Exception\ConnectionException) {
return false;
}

Expand Down Expand Up @@ -1380,7 +1376,7 @@ public function admin_get_dbs()
if ($this->sql_select_db()) {
$dbArr[] = $row->SCHEMA_NAME;
}
} catch (\RuntimeException $exception) {
} catch (\RuntimeException) {
// The exception happens if we cannot connect to the database
// (usually due to missing permissions). This is ok here.
// We catch the exception, skip the database and continue.
Expand Down Expand Up @@ -1489,7 +1485,7 @@ public function admin_get_charsets()
* @param string $query Query to execute
* @return bool|\mysqli_result|object MySQLi result object / DBAL object
*/
public function admin_query($query)
public function admin_query($query): bool|\mysqli_result|object
{
$this->logDeprecation();
$res = $this->query($query);
Expand Down
12 changes: 3 additions & 9 deletions Classes/Database/PostProcessQueryHookInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ interface PostProcessQueryHookInterface
* @param string $groupBy Group by statement
* @param string $orderBy Order by statement
* @param int $limit Database return limit
* @param \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject
*/
public function exec_SELECTquery_postProcessAction(&$select_fields, &$from_table, &$where_clause, &$groupBy, &$orderBy, &$limit, \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject);

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

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

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

/**
* Post-processor for the exec_DELETEquery method.
*
* @param string $table Database table name
* @param string $where WHERE clause
* @param \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject
*/
public function exec_DELETEquery_postProcessAction(&$table, &$where, \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject);

/**
* Post-processor for the exec_TRUNCATEquery method.
*
* @param string $table Database table name
* @param \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject
*/
public function exec_TRUNCATEquery_postProcessAction(&$table, \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject);
}
12 changes: 3 additions & 9 deletions Classes/Database/PreProcessQueryHookInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ interface PreProcessQueryHookInterface
* @param string $groupBy Group by statement
* @param string $orderBy Order by statement
* @param int $limit Database return limit
* @param \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject
*/
public function SELECTquery_preProcessAction(&$select_fields, &$from_table, &$where_clause, &$groupBy, &$orderBy, &$limit, \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject);

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

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

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

/**
* Pre-processor for the DELETEquery method.
*
* @param string $table Database table name
* @param string $where WHERE clause
* @param \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject
*/
public function DELETEquery_preProcessAction(&$table, &$where, \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject);

/**
* Pre-processor for the TRUNCATEquery method.
*
* @param string $table Database table name
* @param \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject
*/
public function TRUNCATEquery_preProcessAction(&$table, \TYPO3\CMS\Typo3DbLegacy\Database\DatabaseConnection $parentObject);
}
Loading

0 comments on commit 3c5c27a

Please sign in to comment.