Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix phan #29514

Merged
merged 14 commits into from
Apr 28, 2024
7 changes: 4 additions & 3 deletions htdocs/core/db/Database.interface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2014-2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -49,7 +50,7 @@ public function stddevpop($nameoffield);
* 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 mysqli_result|resource $resultset Resultset of request
* @param mysqli_result|resource|SQLite3Result $resultset Resultset of request
* @return array Array
*/
public function fetch_row($resultset);
Expand Down Expand Up @@ -114,7 +115,7 @@ public function convertSQLFromMysql($line, $type = 'ddl');
/**
* Return the number of lines in the result of a request INSERT, DELETE or UPDATE
*
* @param mysqli_result|resource $resultset Cursor of the desired request
* @param mysqli_result|resource|SQLite3Result $resultset Cursor of the desired request
* @return int Number of lines
* @see num_rows()
*/
Expand Down Expand Up @@ -413,7 +414,7 @@ public function getListOfCollation();
*
* @param string $table Name of table
* @param string $field Optional : Name of field if we want description of field
* @return resource Resource
* @return bool|resource|mysqli_result|SQLite3Result Resource
*/
public function DDLDescTable($table, $field = "");
// phpcs:enable
Expand Down
4 changes: 3 additions & 1 deletion htdocs/product/admin/product_lot.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,9 @@
$num_rows = $db->num_rows($resql);
while ($i < $num_rows) {
$array = $db->fetch_array($resql);
array_push($def, $array[0]);
if (is_array($array)) {
array_push($def, $array[0]);
}
$i++;
}
} else {
Expand Down
37 changes: 17 additions & 20 deletions htdocs/product/class/product.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2883,9 +2883,10 @@ public function fetch($id = 0, $ref = '', $ref_ext = '', $barcode = '', $ignore_
$sql .= " ORDER BY date_price DESC, rowid DESC";
$sql .= " LIMIT 1";
$resql = $this->db->query($sql);
if ($resql) {
$result = $this->db->fetch_array($resql);

if (!$resql) {
$this->error = $this->db->lasterror;
return -1;
} elseif ($result = $this->db->fetch_array($resql)) {
$this->multiprices[$i] = (!empty($result["price"]) ? $result["price"] : 0);
$this->multiprices_ttc[$i] = (!empty($result["price_ttc"]) ? $result["price_ttc"] : 0);
$this->multiprices_min[$i] = (!empty($result["price_min"]) ? $result["price_min"] : 0);
Expand Down Expand Up @@ -2926,9 +2927,6 @@ public function fetch($id = 0, $ref = '', $ref_ext = '', $barcode = '', $ignore_
return -1;
}
}
} else {
$this->error = $this->db->lasterror;
return -1;
}
}
}
Expand Down Expand Up @@ -5663,23 +5661,22 @@ public function getLibFinished()
{
global $langs;
$langs->load('products');
$label = '';

if (isset($this->finished) && $this->finished >= 0) {
$sql = "SELECT label, code FROM ".$this->db->prefix()."c_product_nature where code = ".((int) $this->finished)." AND active=1";
$resql = $this->db->query($sql);
if ($resql && $this->db->num_rows($resql) > 0) {
$res = $this->db->fetch_array($resql);
$label = $langs->trans($res['label']);
$this->db->free($resql);
return $label;
} else {
if (!$resql) {
$this->error = $this->db->error().' sql='.$sql;
dol_syslog(__METHOD__.' Error '.$this->error, LOG_ERR);
return -1;
} elseif ($this->db->num_rows($resql) > 0 && $res = $this->db->fetch_array($resql)) {
$label = $langs->trans($res['label']);
}
$this->db->free($resql);
}

return '';
return $label;
}


Expand Down Expand Up @@ -6445,7 +6442,7 @@ public function getLabelOfUnit($type = 'long')
}

$langs->load('products');

$label = '';
$label_type = 'label';
if ($type == 'short') {
$label_type = 'short_label';
Expand All @@ -6454,16 +6451,16 @@ public function getLabelOfUnit($type = 'long')
$sql = "SELECT ".$label_type.", code from ".$this->db->prefix()."c_units where rowid = ".((int) $this->fk_unit);

$resql = $this->db->query($sql);
if ($resql && $this->db->num_rows($resql) > 0) {
$res = $this->db->fetch_array($resql);
$label = ($label_type == 'short_label' ? $res[$label_type] : 'unit'.$res['code']);
$this->db->free($resql);
return $label;
} else {
if (!$resql) {
$this->error = $this->db->error();
dol_syslog(get_class($this)."::getLabelOfUnit Error ".$this->error, LOG_ERR);
return -1;
} elseif ($this->db->num_rows($resql) > 0 && $res = $this->db->fetch_array($resql)) {
$label = ($label_type == 'short_label' ? $res[$label_type] : 'unit'.$res['code']);
}
$this->db->free($resql);

return $label;
}

// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
Expand Down
3 changes: 1 addition & 2 deletions htdocs/product/stock/lib/replenishment.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ function ordered($product_id)
$resql = $db->query($sql);
if ($resql) {
$exists = $db->num_rows($resql);
if ($exists) {
$obj = $db->fetch_array($resql);
if ($exists && $obj = $db->fetch_array($resql)) {
return $obj['qty']; //. ' ' . img_picto('','tick');
} else {
return null; //img_picto('', 'stcomm-1');
Expand Down