Skip to content

Commit

Permalink
Merge pull request #32994 from mdeweerd/phan/fix2025.2.8.product-2
Browse files Browse the repository at this point in the history
Qual: Fix phan (product-2)
  • Loading branch information
eldy authored Feb 10, 2025
2 parents d1d5815 + 1a2d4ed commit 7a27235
Show file tree
Hide file tree
Showing 25 changed files with 200 additions and 197 deletions.
33 changes: 6 additions & 27 deletions dev/tools/phan/baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
*/
return [
// # Issue statistics:
// PhanTypeMismatchArgument : 2170+ occurrences
// PhanTypeMismatchArgument : 2090+ occurrences
// PhanUndeclaredProperty : 530+ occurrences
// PhanTypeMismatchArgumentNullable : 420+ occurrences
// PhanTypeMismatchArgumentNullable : 410+ occurrences
// PhanUndeclaredGlobalVariable : 190+ occurrences
// PhanPluginUnknownArrayMethodReturnType : 170+ occurrences
// PhanPossiblyUndeclaredGlobalVariable : 150+ occurrences
// PhanPossiblyUndeclaredGlobalVariable : 140+ occurrences
// PhanTypeMismatchProperty : 130+ occurrences
// PhanTypeMismatchArgumentProbablyReal : 120+ occurrences
// PhanPluginUnknownArrayMethodParamType : 110+ occurrences
Expand All @@ -24,18 +24,18 @@ return [
// PhanPluginUndeclaredVariableIsset : 20+ occurrences
// PhanTypeMismatchDimFetch : 20+ occurrences
// PhanUndeclaredConstant : 15+ occurrences
// PhanTypeComparisonFromArray : 10+ occurrences
// PhanTypeMismatchArgumentNullableInternal : 10+ occurrences
// PhanUndeclaredMethod : 10+ occurrences
// PhanTypeComparisonFromArray : 9 occurrences
// PhanPluginSuspiciousParamPosition : 7 occurrences
// PhanPluginUnknownObjectMethodCall : 7 occurrences
// PhanPluginDuplicateExpressionBinaryOp : 6 occurrences
// PhanTypeArraySuspiciousNull : 6 occurrences
// PhanParamTooMany : 5 occurrences
// PhanPluginEmptyStatementIf : 5 occurrences
// PhanEmptyForeach : 4 occurrences
// PhanPluginBothLiteralsBinaryOp : 4 occurrences
// PhanPluginDuplicateArrayKey : 4 occurrences
// PhanPluginEmptyStatementIf : 4 occurrences
// PhanEmptyFQSENInClasslike : 3 occurrences
// PhanInvalidFQSENInClasslike : 3 occurrences
// PhanTypeMismatchDimAssignment : 2 occurrences
Expand Down Expand Up @@ -594,31 +594,10 @@ return [
'htdocs/partnership/partnership_list.php' => ['PhanUndeclaredProperty'],
'htdocs/product/class/api_products.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType', 'PhanTypeMismatchArgument', 'PhanUndeclaredProperty'],
'htdocs/product/class/html.formproduct.class.php' => ['PhanUndeclaredProperty'],
'htdocs/product/class/productcustomerprice.class.php' => ['PhanTypeMismatchArgument'],
'htdocs/product/class/productfournisseurprice.class.php' => ['PhanUndeclaredMethod', 'PhanUndeclaredProperty'],
'htdocs/product/composition/card.php' => ['PhanTypeMismatchArgument'],
'htdocs/product/document.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeMismatchArgumentNullable'],
'htdocs/product/dynamic_price/class/price_parser.class.php' => ['PhanTypeMismatchArgument'],
'htdocs/product/index.php' => ['PhanPluginUndeclaredVariableIsset', 'PhanTypeMismatchArgument'],
'htdocs/product/inventory/ajax/searchfrombarcode.php' => ['PhanTypeMismatchArgument'],
'htdocs/product/inventory/card.php' => ['PhanPluginEmptyStatementIf', 'PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeMismatchArgumentNullable'],
'htdocs/product/inventory/class/inventory.class.php' => ['PhanUndeclaredProperty'],
'htdocs/product/inventory/inventory.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal'],
'htdocs/product/inventory/list.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal'],
'htdocs/product/list.php' => ['PhanPluginUndeclaredVariableIsset', 'PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'],
'htdocs/product/price.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchArgumentProbablyReal', 'PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'],
'htdocs/product/price_suppliers.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'],
'htdocs/product/price.php' => ['PhanUndeclaredProperty'],
'htdocs/product/reassort.php' => ['PhanTypeExpectedObjectPropAccessButGotNull'],
'htdocs/product/stats/card.php' => ['PhanTypeComparisonFromArray', 'PhanTypeMismatchArgument'],
'htdocs/product/stats/commande.php' => ['PhanTypeMismatchArgument'],
'htdocs/product/stats/commande_fournisseur.php' => ['PhanTypeMismatchArgument'],
'htdocs/product/stats/expedition.php' => ['PhanTypeMismatchArgument'],
'htdocs/product/stats/facture_fournisseur.php' => ['PhanTypeMismatchArgument'],
'htdocs/product/stats/facturerec.php' => ['PhanTypeMismatchArgument'],
'htdocs/product/stats/mo.php' => ['PhanTypeMismatchArgument'],
'htdocs/product/stats/propal.php' => ['PhanTypeMismatchArgument'],
'htdocs/product/stats/reception.php' => ['PhanTypeMismatchArgument'],
'htdocs/product/stats/supplier_proposal.php' => ['PhanTypeMismatchArgument'],
'htdocs/product/stock/card.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchProperty'],
'htdocs/product/stock/class/api_stockmovements.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType', 'PhanTypeMismatchArgument'],
'htdocs/product/stock/class/api_warehouses.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType'],
Expand Down
19 changes: 10 additions & 9 deletions htdocs/core/class/html.form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class Form
public $cache_types_paiements = array();
public $cache_conditions_paiements = array();
public $cache_transport_mode = array();
/** @var array<int,array{code:string,label:string,position:int}> */
public $cache_availability = array();
public $cache_demand_reason = array();
public $cache_types_fees = array();
Expand Down Expand Up @@ -3734,7 +3735,7 @@ public function select_produits_fournisseurs($socid, $selected = '', $htmlname =
* @param int $socid Id of supplier thirdparty (0 = no filter)
* @param string $selected Product price preselected (must be 'id' in product_fournisseur_price or 'idprod_IDPROD')
* @param string $htmlname Name of HTML select
* @param string $filtertype Filter on product type (''=nofilter, 0=product, 1=service)
* @param ''|int<0,1> $filtertype Filter on product type (''=nofilter, 0=product, 1=service)
* @param string $filtre Generic filter. Data must not come from user input.
* @param string $filterkey Filter of produdts
* @param int $statut -1=Return all products, 0=Products not on buy, 1=Products on buy
Expand Down Expand Up @@ -4392,9 +4393,9 @@ public function load_cache_availability()

// Si traduction existe, on l'utilise, sinon on prend le libelle par default
$label = ($langs->trans("AvailabilityType" . $obj->code) != "AvailabilityType" . $obj->code ? $langs->trans("AvailabilityType" . $obj->code) : ($obj->label != '-' ? $obj->label : ''));
$this->cache_availability[$obj->rowid]['code'] = $obj->code;
$this->cache_availability[$obj->rowid]['label'] = $label;
$this->cache_availability[$obj->rowid]['position'] = $obj->position;
$this->cache_availability[$obj->rowid]['code'] = (string) $obj->code;
$this->cache_availability[$obj->rowid]['label'] = (string) $label;
$this->cache_availability[$obj->rowid]['position'] = (int) $obj->position;
$i++;
}

Expand All @@ -4410,11 +4411,11 @@ public function load_cache_availability()
/**
* Return the list of type of delay available.
*
* @param string $selected Id du type de delais pre-selectionne
* @param string $htmlname Nom de la zone select
* @param string $filtertype To add a filter
* @param int $addempty Add empty entry
* @param string $morecss More CSS
* @param ''|int $selected Id du type de delais pre-selectionne
* @param string $htmlname Nom de la zone select
* @param string|int<0,1> $filtertype To add a filter
* @param int<0,1> $addempty Add empty entry
* @param string $morecss More CSS
* @return void
*/
public function selectAvailabilityDelay($selected = '', $htmlname = 'availid', $filtertype = '', $addempty = 0, $morecss = '')
Expand Down
36 changes: 18 additions & 18 deletions htdocs/core/lib/date.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright (C) 2011-2015 Juanjo Menent <[email protected]>
* Copyright (C) 2017 Ferran Marcet <[email protected]>
* Copyright (C) 2018-2024 Charlene Benke <[email protected]>
* Copyright (C) 2024 MDW <[email protected]>
* Copyright (C) 2024-2025 MDW <[email protected]>
* Copyright (C) 2024 Frédéric France <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -373,8 +373,8 @@ function convertDurationtoHour($duration_value, $duration_unit)
* @param int|string $month_date Month date (Can be 0 or '' for filter on a year)
* @param int|string $year_date Year date
* @param int $excludefirstand Exclude first and
* @param mixed $gm False or 0 or 'tzserver' = Input date fields are date info in the server TZ. True or 1 or 'gmt' = Input are date info in GMT TZ.
* Note: In database, dates are always for the server TZ.
* @param bool|int<0,1>|'gmt'|'tzserver'|'tzref'|'tzuser'|'tzuserrel' $gm False or 0 or 'tzserver' = Input date fields are date info in the server TZ. True or 1 or 'gmt' = Input are date info in GMT TZ.
* Note: In database, dates are always for the server TZ.
* @return string $sqldate String with SQL filter
* @see forgeSQLFromUniversalSearchCriteria()
* @see natural_search()
Expand Down Expand Up @@ -420,8 +420,8 @@ function dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $exclu
* YYYY-MM-DDTHH:MM:SSZ (RFC3339)
* DD/MM/YY or DD/MM/YYYY (deprecated)
* DD/MM/YY HH:MM:SS or DD/MM/YYYY HH:MM:SS (deprecated)
* @param int|string $gm 'gmt' or 1 =Input date is GM date,
* 'tzserver' or 0 =Input date is date using PHP server timezone
* @param int<0,1>|'gmt'|'tzserver'|'tzref'|'tzuser'|'tzuserrel'|'dayrfc' $gm 'gmt' or 1 =Input date is GM date,
* 'tzserver' or 0 =Input date is date using PHP server timezone
* @return int Date as a timestamp
* 19700101020000 -> 7200 with gm=1
* 19700101000000 -> 0 with gm=1
Expand Down Expand Up @@ -589,12 +589,12 @@ function dol_get_next_week($day, $week, $month, $year)
/**
* Return GMT time for first day of a month or year
*
* @param int $year Year
* @param int $month Month
* @param bool|int|string $gm False or 0 or 'tzserver' = Return date to compare with server TZ,
* True or 1 or 'gmt' to compare with GMT date.
* Example: dol_get_first_day(1970,1,false) will return -3600 with TZ+1, a dol_print_date on it will return 1970-01-01 00:00:00
* Example: dol_get_first_day(1970,1,true) will return 0 whatever is TZ, a dol_print_date on it will return 1970-01-01 00:00:00
* @param int $year Year
* @param int $month Month
* @param bool|int<0,1>|'gmt'|'tzserver'|'tzref'|'tzuser'|'tzuserrel' $gm False or 0 or 'tzserver' = Return date to compare with server TZ,
* True or 1 or 'gmt' to compare with GMT date.
* Example: dol_get_first_day(1970,1,false) will return -3600 with TZ+1, a dol_print_date on it will return 1970-01-01 00:00:00
* Example: dol_get_first_day(1970,1,true) will return 0 whatever is TZ, a dol_print_date on it will return 1970-01-01 00:00:00
* @return int|string Date as a timestamp, '' if error
*/
function dol_get_first_day($year, $month = 1, $gm = false)
Expand All @@ -612,8 +612,8 @@ function dol_get_first_day($year, $month = 1, $gm = false)
*
* @param int $year Year
* @param int $month Month
* @param bool|int|string $gm False or 0 or 'tzserver' = Return date to compare with server TZ,
* True or 1 or 'gmt' to compare with GMT date.
* @param bool|int<0,1>|'gmt'|'tzserver'|'tzref'|'tzuser'|'tzuserrel' $gm False or 0 or 'tzserver' = Return date to compare with server TZ,
* True or 1 or 'gmt' to compare with GMT date.
* @return int|string Date as a timestamp, '' if error
*/
function dol_get_last_day($year, $month = 12, $gm = false)
Expand Down Expand Up @@ -665,11 +665,11 @@ function dol_get_first_hour($date, $gm = 'tzserver')

/** Return first day of week for a date. First day of week may be monday if option MAIN_START_WEEK is 1.
*
* @param int $day Day
* @param int $month Month
* @param int $year Year
* @param bool|int|'tzserver' $gm False or 0 or 'tzserver' = Return date to compare with server TZ,
* True or 1 or 'gmt' to compare with GMT date.
* @param int $day Day
* @param int $month Month
* @param int $year Year
* @param bool|int<0,1>|'gmt'|'tzserver'|'tzref'|'tzuser'|'tzuserrel' $gm False or 0 or 'tzserver' = Return date to compare with server TZ,
* True or 1 or 'gmt' to compare with GMT date.
* @return array{year:int,month:int,week:string,first_day:int,first_month:int,first_year:int,prev_year:int,prev_month:int,prev_day:int}
*/
function dol_get_first_day_week($day, $month, $year, $gm = false)
Expand Down
8 changes: 4 additions & 4 deletions htdocs/product/class/productcustomerprice.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* Copyright (C) 2007-2012 Laurent Destailleur <[email protected]>
* Copyright (C) 2014 Florian Henry <[email protected]>
* Copyright (C) 2024 Frédéric France <[email protected]>
* Copyright (C) 2024 MDW <[email protected]>
* Copyright (C) 2024-2025 MDW <[email protected]>
*
* 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 @@ -282,8 +282,8 @@ public function create($user, $notrigger = 0, $forceupdateaffiliate = 0)
$sql .= ") VALUES (";
$sql .= " ".((int) $conf->entity).",";
$sql .= " '".$this->db->idate(dol_now())."',";
$sql .= " ".(!isset($this->fk_product) ? 'NULL' : "'".$this->db->escape($this->fk_product)."'").",";
$sql .= " ".(!isset($this->fk_soc) ? 'NULL' : "'".$this->db->escape($this->fk_soc)."'").",";
$sql .= " ".(!isset($this->fk_product) ? 'NULL' : ((int) $this->fk_product)).",";
$sql .= " ".(!isset($this->fk_soc) ? 'NULL' : ((int) $this->fk_soc)).",";
$sql .= " ".(!isset($this->ref_customer) ? 'NULL' : "'".$this->db->escape($this->ref_customer)."'").",";
$sql .= " ".(empty($this->price) ? '0' : "'".$this->db->escape($this->price)."'").",";
$sql .= " ".(empty($this->price_ttc) ? '0' : "'".$this->db->escape($this->price_ttc)."'").",";
Expand Down Expand Up @@ -918,7 +918,7 @@ public function setPriceOnAffiliateThirdparty($user, $forceupdateaffiliate)
$prodsocprice = new ProductCustomerPrice($this->db);

$filter = array(
't.fk_product' => $this->fk_product, 't.fk_soc' => $obj->rowid
't.fk_product' => (string) $this->fk_product, 't.fk_soc' => (string) $obj->rowid
);

$result = $prodsocprice->fetchAll('', '', 0, 0, $filter);
Expand Down
6 changes: 3 additions & 3 deletions htdocs/product/composition/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Copyright (C) 2015 Raphaël Doursenaud <[email protected]>
* Copyright (C) 2023 Benjamin Falière <[email protected]>
* Copyright (C) 2024 Frédéric France <[email protected]>
* Copyright (C) 2024 MDW <[email protected]>
* Copyright (C) 2024-2025 MDW <[email protected]>
*
* 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 @@ -113,7 +113,7 @@
for ($i = 0; $i < $maxprod; $i++) {
$qty = price2num(GETPOST("prod_qty_" . $i, 'alpha'), 'MS');
if ($qty > 0) {
if ($object->add_sousproduit($id, GETPOSTINT("prod_id_" . $i), $qty, GETPOSTINT("prod_incdec_" . $i)) > 0) {
if ($object->add_sousproduit($id, GETPOSTINT("prod_id_" . $i), (float) $qty, GETPOSTINT("prod_incdec_" . $i)) > 0) {
//var_dump($i.' '.GETPOST("prod_id_".$i, 'int'), $qty, GETPOST("prod_incdec_".$i, 'int'));
$action = 'edit';
} else {
Expand Down Expand Up @@ -262,7 +262,7 @@
if (isModEnabled("product") && isModEnabled("service")) {
$typeformat = 'select;0:'.$langs->trans("Product").',1:'.$langs->trans("Service");
print '<tr><td class="titlefield">';
print (!getDolGlobalString('PRODUCT_DENY_CHANGE_PRODUCT_TYPE')) ? $form->editfieldkey("Type", 'fk_product_type', $object->type, $object, $usercancreate, $typeformat) : $langs->trans('Type');
print (!getDolGlobalString('PRODUCT_DENY_CHANGE_PRODUCT_TYPE')) ? $form->editfieldkey("Type", 'fk_product_type', (string) $object->type, $object, (int) $usercancreate, $typeformat) : $langs->trans('Type');
print '</td><td>';
print $form->editfieldval("Type", 'fk_product_type', $object->type, $object, $usercancreate, $typeformat);
print '</td></tr>';
Expand Down
9 changes: 6 additions & 3 deletions htdocs/product/document.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Copyright (C) 2013 Cédric Salvador <[email protected]>
* Copyright (C) 2017 Ferran Marcet <[email protected]>
* Copyright (C) 2024 Frédéric France <[email protected]>
* Copyright (C) 2025 MDW <[email protected]>
* Copyright (C) 2025 MDW <[email protected]>
*
* 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 @@ -89,6 +89,8 @@
$sortfield = "position_name";
}

$upload_dir = '';
$upload_dirold = '';
// Initialize objects
$object = new Product($db);
if ($id > 0 || !empty($ref)) {
Expand Down Expand Up @@ -172,7 +174,7 @@
// Delete all file already associated
$filetomerge = new Propalmergepdfproduct($db);

if (getDolGlobalInt('MAIN_MULTILANGS')) {
if (getDolGlobalInt('MAIN_MULTILANGS') && $lang_id !== null) {
$result = $filetomerge->delete_by_product($user, $object->id, $lang_id);
} else {
$result = $filetomerge->delete_by_product($user, $object->id);
Expand Down Expand Up @@ -338,6 +340,7 @@

print '<table class="noborder">';

$default_lang = null;
// Get language
if (getDolGlobalInt('MAIN_MULTILANGS')) {
$langs->load("languages");
Expand All @@ -363,7 +366,7 @@
$checked = '';
$filename = $filetoadd['name'];

if (getDolGlobalInt('MAIN_MULTILANGS')) {
if (getDolGlobalInt('MAIN_MULTILANGS') && $default_lang !== null) {
if (array_key_exists($filetoadd['name'].'_'.$default_lang, $filetomerge->lines)) {
$filename = $filetoadd['name'].' - '.$langs->trans('Language_'.$default_lang);
$checked = ' checked ';
Expand Down
4 changes: 2 additions & 2 deletions htdocs/product/dynamic_price/class/price_parser.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2015 Ion Agorria <[email protected]>
* Copyright (C) 2024 MDW <[email protected]>
* Copyright (C) 2024-2025 MDW <[email protected]>
*
* 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 @@ -345,7 +345,7 @@ public function testExpression($product_id, $expression, $extra_values = array()
{
//Get the product data
$product = new Product($this->db);
$product->fetch($product_id, '', '', 1);
$product->fetch($product_id, '', '', '1');

//Values for product expressions
$extra_values = array_merge($extra_values, array(
Expand Down
Loading

0 comments on commit 7a27235

Please sign in to comment.