Fix phan warnings

This commit is contained in:
Laurent Destailleur 2024-04-28 17:10:51 +02:00
parent 29b6d6b918
commit 6358f89c0d
5 changed files with 22 additions and 18 deletions

View file

@ -49,8 +49,8 @@ interface Database
* Return datas as an array
* @TODO deprecate this. Use fetch_object() so you can access a field with its name instead of using an index of position of field.
*
* @param resource $resultset Resultset of request
* @return array Array
* @param mysqli_result|resource $resultset Resultset of request
* @return array Array
*/
public function fetch_row($resultset);
// phpcs:enable
@ -89,7 +89,7 @@ interface Database
* @param string $charset Charset used to store data
* @param string $collation Charset used to sort data
* @param string $owner Username of database owner
* @return resource resource defined if OK, null if KO
* @return bool|SQLite3Result|mysqli_result|resource Resource result of the query to create database if OK, null if KO
*/
public function DDLCreateDb($database, $charset = '', $collation = '', $owner = '');
// phpcs:enable
@ -114,8 +114,8 @@ interface Database
/**
* Return the number of lines in the result of a request INSERT, DELETE or UPDATE
*
* @param resource $resultset Cursor of the desired request
* @return int Number of lines
* @param mysqli_result|resource $resultset Cursor of the desired request
* @return int Number of lines
* @see num_rows()
*/
public function affected_rows($resultset);
@ -303,8 +303,8 @@ interface Database
/**
* Return number of lines for result of a SELECT
*
* @param resource $resultset Resulset of requests
* @return int Nb of lines
* @param mysqli_result|resource $resultset Resulset of requests
* @return int Nb of lines
* @see affected_rows()
*/
public function num_rows($resultset);

View file

@ -26,6 +26,7 @@
require_once DOL_DOCUMENT_ROOT.'/core/db/Database.interface.php';
/**
* Class to manage Dolibarr database access
*/

View file

@ -316,11 +316,11 @@ class DoliDBMysqli extends DoliDB
* Note that with Mysql, this parameter is not used as Myssql can already commit a transaction even if one request is in error, without using savepoints.
* @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...)
* @param int $result_mode Result mode (Using 1=MYSQLI_USE_RESULT instead of 0=MYSQLI_STORE_RESULT will not buffer the result and save memory)
* @return bool|mysqli_result Resultset of answer
* @return false|mysqli_result Resultset of answer
*/
public function query($query, $usesavepoint = 0, $type = 'auto', $result_mode = 0)
{
global $conf, $dolibarr_main_db_readonly;
global $dolibarr_main_db_readonly;
$query = trim($query);
@ -692,7 +692,7 @@ class DoliDBMysqli extends DoliDB
* @param string $charset Charset used to store data
* @param string $collation Charset used to sort data
* @param string $owner Username of database owner
* @return bool|mysqli_result resource defined if OK, null if KO
* @return null|mysqli_result Resource defined if OK, null if KO
*/
public function DDLCreateDb($database, $charset = '', $collation = '', $owner = '')
{
@ -716,6 +716,7 @@ class DoliDBMysqli extends DoliDB
dol_syslog($sql, LOG_DEBUG);
$ret = $this->query($sql);
}
return $ret;
}

View file

@ -514,7 +514,7 @@ class DoliDBPgsql extends DoliDB
*/
public function query($query, $usesavepoint = 0, $type = 'auto', $result_mode = 0)
{
global $conf, $dolibarr_main_db_readonly;
global $dolibarr_main_db_readonly;
$query = trim($query);
@ -934,7 +934,7 @@ class DoliDBPgsql extends DoliDB
* @param string $charset Charset used to store data
* @param string $collation Charset used to sort data
* @param string $owner Username of database owner
* @return false|resource resource defined if OK, null if KO
* @return false|resource Resource defined if OK, null if KO
*/
public function DDLCreateDb($database, $charset = '', $collation = '', $owner = '')
{
@ -951,8 +951,10 @@ class DoliDBPgsql extends DoliDB
// NOTE: Do not use ' around the database name
$sql = "CREATE DATABASE ".$this->escape($database)." OWNER '".$this->escape($owner)."' ENCODING '".$this->escape($charset)."'";
dol_syslog($sql, LOG_DEBUG);
$ret = $this->query($sql);
return $ret;
}

View file

@ -45,6 +45,8 @@ class DoliDBSqlite3 extends DoliDB
*/
private $_results;
private $queryString;
const WEEK_MONDAY_FIRST = 1;
const WEEK_YEAR = 2;
const WEEK_FIRST_WEEKDAY = 4;
@ -396,7 +398,7 @@ class DoliDBSqlite3 extends DoliDB
* Note that with Mysql, this parameter is not used as Myssql can already commit a transaction even if one request is in error, without using savepoints.
* @param string $type Type of SQL order ('ddl' for insert, update, select, delete or 'dml' for create, alter...)
* @param int $result_mode Result mode (not used with sqlite)
* @return bool|SQLite3Result|null Resultset of answer
* @return false|SQLite3Result Resultset of answer
*/
public function query($query, $usesavepoint = 0, $type = 'auto', $result_mode = 0)
{
@ -473,7 +475,7 @@ class DoliDBSqlite3 extends DoliDB
//$ret = $this->db->exec($query);
$ret = $this->db->query($query); // $ret is a Sqlite3Result
if ($ret) {
$ret->queryString = $query;
$this->queryString = $query;
}
} catch (Exception $e) {
$this->error = $this->db->lastErrorMsg();
@ -581,7 +583,6 @@ class DoliDBSqlite3 extends DoliDB
public function num_rows($resultset)
{
// phpcs:enable
// FIXME: SQLite3Result does not have a queryString member
// If resultset not provided, we take the last used by connection
if (!is_object($resultset)) {
@ -604,13 +605,12 @@ class DoliDBSqlite3 extends DoliDB
public function affected_rows($resultset)
{
// phpcs:enable
// FIXME: SQLite3Result does not have a queryString member
// If resultset not provided, we take the last used by connection
if (!is_object($resultset)) {
$resultset = $this->_results;
}
if (preg_match("/^SELECT/i", $resultset->queryString)) {
if (preg_match("/^SELECT/i", $this->queryString)) {
return $this->num_rows($resultset);
}
// mysql necessite un link de base pour cette fonction contrairement
@ -841,7 +841,7 @@ class DoliDBSqlite3 extends DoliDB
* @param string $charset Charset used to store data
* @param string $collation Charset used to sort data
* @param string $owner Username of database owner
* @return SQLite3Result resource defined if OK, null if KO
* @return false|SQLite3Result Resource defined if OK, null if KO
*/
public function DDLCreateDb($database, $charset = '', $collation = '', $owner = '')
{