Skip to content

Commit

Permalink
Merge pull request Dolibarr#28820 from mdeweerd/fix/PhanTypeInvalidUn…
Browse files Browse the repository at this point in the history
…aryOperandNumeric

Fix PhanTypeInvalidUnaryOperandNumeric & remove from exceptions
  • Loading branch information
eldy authored Mar 15, 2024
2 parents 4f766a6 + 470e688 commit f5a0255
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 40 deletions.
5 changes: 1 addition & 4 deletions dev/tools/phan/baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ return [
// PhanUndeclaredConstant : 15+ occurrences
// PhanPluginDuplicateExpressionBinaryOp : 10+ occurrences
// PhanTypeArraySuspiciousNull : 10+ occurrences
// PhanTypeInvalidUnaryOperandNumeric : 8 occurrences
// PhanRedefineFunctionInternal : 6 occurrences
// PhanPluginUnsafeEval : 5 occurrences
// PhanParamSuspiciousOrder : 4 occurrences
Expand All @@ -39,7 +38,7 @@ return [
'htdocs/categories/class/api_categories.class.php' => ['PhanAccessMethodProtected'],
'htdocs/categories/viewcat.php' => ['PhanPluginDuplicateExpressionBinaryOp'],
'htdocs/collab/index.php' => ['PhanParamTooMany'],
'htdocs/comm/action/index.php' => ['PhanTypeArraySuspiciousNull', 'PhanTypeInvalidUnaryOperandNumeric'],
'htdocs/comm/action/index.php' => ['PhanTypeArraySuspiciousNull'],
'htdocs/comm/mailing/card.php' => ['PhanPluginSuspiciousParamPosition'],
'htdocs/compta/accounting-files.php' => ['PhanTypeInvalidUnaryOperandNumeric'],
'htdocs/compta/cashcontrol/cashcontrol_card.php' => ['PhanPluginDuplicateExpressionBinaryOp'],
Expand Down Expand Up @@ -71,14 +70,12 @@ return [
'htdocs/core/modules/syslog/mod_syslog_file.php' => ['PhanParamSignatureMismatch', 'PhanParamSuspiciousOrder'],
'htdocs/core/modules/syslog/mod_syslog_syslog.php' => ['PhanParamSignatureMismatch'],
'htdocs/don/class/don.class.php' => ['PhanParamTooMany'],
'htdocs/expensereport/class/paymentexpensereport.class.php' => ['PhanTypeInvalidUnaryOperandNumeric'],
'htdocs/fourn/class/api_supplier_invoices.class.php' => ['PhanPluginSuspiciousParamOrder'],
'htdocs/intracommreport/list.php' => ['PhanAccessPropertyStaticAsNonStatic'],
'htdocs/loan/class/paymentloan.class.php' => ['PhanTypeInvalidUnaryOperandNumeric'],
'htdocs/mrp/class/mo.class.php' => ['PhanParamSignatureMismatch'],
'htdocs/product/admin/product_tools.php' => ['PhanNoopStringLiteral'],
'htdocs/projet/tasks/list.php' => ['PhanTypeArraySuspiciousNull'],
'htdocs/public/bookcal/index.php' => ['PhanTypeInvalidUnaryOperandNumeric'],
'htdocs/public/opensurvey/index.php' => ['PhanPluginSuspiciousParamOrder'],
'htdocs/public/payment/paymentok.php' => ['PhanPluginSuspiciousParamPosition'],
'htdocs/public/recruitment/index.php' => ['PhanPluginSuspiciousParamOrder'],
Expand Down
6 changes: 3 additions & 3 deletions htdocs/comm/action/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,10 @@
$next_year = $next['year'];
$next_month = $next['month'];

$max_day_in_prev_month = date("t", dol_mktime(12, 0, 0, $prev_month, 1, $prev_year, 'gmt')); // Nb of days in previous month
$max_day_in_month = date("t", dol_mktime(12, 0, 0, $month, 1, $year, 'gmt')); // Nb of days in next month
$max_day_in_prev_month = (int) date("t", dol_mktime(12, 0, 0, $prev_month, 1, $prev_year, 'gmt')); // Nb of days in previous month
$max_day_in_month = (int) date("t", dol_mktime(12, 0, 0, $month, 1, $year, 'gmt')); // Nb of days in next month
// tmpday is a negative or null cursor to know how many days before the 1st to show on month view (if tmpday=0, 1st is monday)
$tmpday = -date("w", dol_mktime(12, 0, 0, $month, 1, $year, 'gmt')) + 2; // date('w') is 0 for sunday
$tmpday = - (int) date("w", dol_mktime(12, 0, 0, $month, 1, $year, 'gmt')) + 2; // date('w') is 0 for sunday
$tmpday += ((isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1) - 1);
if ($tmpday >= 1) {
$tmpday -= 7; // If tmpday is 0 we start with sunday, if -6, we start with monday of previous week.
Expand Down
46 changes: 26 additions & 20 deletions htdocs/compta/accounting-files.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Copyright (C) 2020 Maxime DEMAREST <[email protected]>
* Copyright (C) 2021 Gauthier VERDOL <[email protected]>
* Copyright (C) 2022-2024 Alexandre Spangaro <[email protected]>
* Copyright (C) 2024 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 @@ -96,15 +97,15 @@


$arrayfields = array(
'type'=>array('label'=>"Type", 'checked'=>1),
'date'=>array('label'=>"Date", 'checked'=>1),
'date_due'=>array('label'=>"DateDue", 'checked'=>1),
'ref'=>array('label'=>"Ref", 'checked'=>1),
'documents'=>array('label'=>"Documents", 'checked'=>1),
'paid'=>array('label'=>"Paid", 'checked'=>1),
'total_ht'=>array('label'=>"TotalHT", 'checked'=>1),
'total_ttc'=>array('label'=>"TotalTTC", 'checked'=>1),
'total_vat'=>array('label'=>"TotalVAT", 'checked'=>1),
'type' => array('label' => "Type", 'checked' => 1),
'date' => array('label' => "Date", 'checked' => 1),
'date_due' => array('label' => "DateDue", 'checked' => 1),
'ref' => array('label' => "Ref", 'checked' => 1),
'documents' => array('label' => "Documents", 'checked' => 1),
'paid' => array('label' => "Paid", 'checked' => 1),
'total_ht' => array('label' => "TotalHT", 'checked' => 1),
'total_ttc' => array('label' => "TotalTTC", 'checked' => 1),
'total_vat' => array('label' => "TotalVAT", 'checked' => 1),
//...
);

Expand Down Expand Up @@ -135,14 +136,14 @@
$error = 0;

$listofchoices = array(
'selectinvoices'=>array('label'=>'Invoices', 'picto'=>'bill', 'lang'=>'bills', 'enabled' => isModEnabled('invoice'), 'perms' => $user->hasRight('facture', 'lire')),
'selectsupplierinvoices'=>array('label'=>'BillsSuppliers', 'picto'=>'supplier_invoice', 'lang'=>'bills', 'enabled' => isModEnabled('supplier_invoice'), 'perms' => $user->hasRight('fournisseur', 'facture', 'lire')),
'selectexpensereports'=>array('label'=>'ExpenseReports', 'picto'=>'expensereport', 'lang'=>'trips', 'enabled' => isModEnabled('expensereport'), 'perms' => $user->hasRight('expensereport', 'lire')),
'selectdonations'=>array('label'=>'Donations', 'picto'=>'donation', 'lang'=>'donation', 'enabled' => isModEnabled('don'), 'perms' => $user->hasRight('don', 'lire')),
'selectsocialcontributions'=>array('label'=>'SocialContributions', 'picto'=>'bill', 'enabled' => isModEnabled('tax'), 'perms' => $user->hasRight('tax', 'charges', 'lire')),
'selectpaymentsofsalaries'=>array('label'=>'SalariesPayments', 'picto'=>'salary', 'lang'=>'salaries', 'enabled' => isModEnabled('salaries'), 'perms' => $user->hasRight('salaries', 'read')),
'selectvariouspayment'=>array('label'=>'VariousPayment', 'picto'=>'payment', 'enabled' => isModEnabled('bank'), 'perms' => $user->hasRight('banque', 'lire')),
'selectloanspayment'=>array('label'=>'PaymentLoan','picto'=>'loan', 'enabled' => isModEnabled('don'), 'perms' => $user->hasRight('loan', 'read')),
'selectinvoices' => array('label' => 'Invoices', 'picto' => 'bill', 'lang' => 'bills', 'enabled' => isModEnabled('invoice'), 'perms' => $user->hasRight('facture', 'lire')),
'selectsupplierinvoices' => array('label' => 'BillsSuppliers', 'picto' => 'supplier_invoice', 'lang' => 'bills', 'enabled' => isModEnabled('supplier_invoice'), 'perms' => $user->hasRight('fournisseur', 'facture', 'lire')),
'selectexpensereports' => array('label' => 'ExpenseReports', 'picto' => 'expensereport', 'lang' => 'trips', 'enabled' => isModEnabled('expensereport'), 'perms' => $user->hasRight('expensereport', 'lire')),
'selectdonations' => array('label' => 'Donations', 'picto' => 'donation', 'lang' => 'donation', 'enabled' => isModEnabled('don'), 'perms' => $user->hasRight('don', 'lire')),
'selectsocialcontributions' => array('label' => 'SocialContributions', 'picto' => 'bill', 'enabled' => isModEnabled('tax'), 'perms' => $user->hasRight('tax', 'charges', 'lire')),
'selectpaymentsofsalaries' => array('label' => 'SalariesPayments', 'picto' => 'salary', 'lang' => 'salaries', 'enabled' => isModEnabled('salaries'), 'perms' => $user->hasRight('salaries', 'read')),
'selectvariouspayment' => array('label' => 'VariousPayment', 'picto' => 'payment', 'enabled' => isModEnabled('bank'), 'perms' => $user->hasRight('banque', 'lire')),
'selectloanspayment' => array('label' => 'PaymentLoan','picto' => 'loan', 'enabled' => isModEnabled('don'), 'perms' => $user->hasRight('loan', 'read')),
);


Expand All @@ -157,6 +158,9 @@
//if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');

$filesarray = array();

'@phan-var-force array<string,array{id:string,entity:string,date:string,date_due:string,paid:float|int,amount_ht:float|int,amount_ttc:float|int,amount_vat:float|int,amount_localtax1:float|int,amount_localtax2:float|int,amount_revenuestamp:float|int,ref:string,fk:string,item:string,thirdparty_name:string,thirdparty_code:string,country_code:string,vatnum:string,sens:string,currency:string,line?:string,name?:string,files?:mixed}> $filesarray';

$result = false;
if (($action == 'searchfiles' || $action == 'dl')) {
if (empty($date_start)) {
Expand Down Expand Up @@ -411,6 +415,7 @@
$nofile['link'] = '';
$nofile['name'] = '';


$filesarray[$nofile['item'].'_'.$nofile['id']] = $nofile;
} else {
foreach ($files as $key => $file) {
Expand Down Expand Up @@ -446,8 +451,8 @@
}
$filesarray[$file['item'].'_'.$file['id']]['files'][] = array(
'link' => $link.urlencode($file['name']),
'name'=>$file['name'],
'ref'=>$file['ref'],
'name' => $file['name'],
'ref' => $file['ref'],
'fullname' => $file['fullname'],
'relpath' => '/'.$file['name'],
'relpathnamelang' => $langs->trans($file['item']).'/'.$file['name'],
Expand Down Expand Up @@ -522,7 +527,7 @@
$zipname .= '_'.$project->ref;
}
}
$zipname .='_export.zip';
$zipname .= '_export.zip';

dol_delete_file($zipname);

Expand Down Expand Up @@ -689,6 +694,7 @@
}

$TData = dol_sort_array($filesarray, $sortfield, $sortorder);
'@phan-var-force array<string,array{id:string,entity:string,date:string,date_due:string,paid:float|int,amount_ht:float|int,amount_ttc:float|int,amount_vat:float|int,amount_localtax1:float|int,amount_localtax2:float|int,amount_revenuestamp:float|int,ref:string,fk:string,item:string,thirdparty_name:string,thirdparty_code:string,country_code:string,vatnum:string,sens:string,currency:string,line?:string,name?:string,files?:mixed}> $TData';


$filename = dol_print_date($date_start, 'dayrfc', 'tzuserrel')."-".dol_print_date($date_stop, 'dayrfc', 'tzuserrel').'_export.zip';
Expand Down
16 changes: 13 additions & 3 deletions htdocs/compta/sociales/class/paymentsocialcontribution.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright (C) 2004-2007 Laurent Destailleur <[email protected]>
* Copyright (C) 2022 Alexandre Spangaro <[email protected]>
* Copyright (C) 2024 Frédéric France <[email protected]>
* Copyright (C) 2024 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 @@ -82,12 +83,19 @@ class PaymentSocialContribution extends CommonObject
public $bank_line;

/**
* @deprecated
* @deprecated Use $amount instead.
* @see $amount
* @var float|int
*/
public $total;

/**
* @var float|int
*/
public $amount; // Total amount of payment
/**
* @var array<float|int>
*/
public $amounts = array(); // Array of amounts

/**
Expand All @@ -97,7 +105,7 @@ class PaymentSocialContribution extends CommonObject

/**
* @var string
* @deprecated
* @deprecated Use $num_payment instead
* @see $num_payment
*/
public $num_paiement;
Expand Down Expand Up @@ -318,8 +326,10 @@ public function fetch($id)
$this->tms = $this->db->jdate($obj->tms);
$this->datep = $this->db->jdate($obj->datep);
$this->amount = $obj->amount;
$this->total = $obj->amount;
$this->fk_typepaiement = $obj->fk_typepaiement;
$this->num_payment = $obj->num_payment;
$this->num_paiement = $obj->num_payment;
$this->note_private = $obj->note;
$this->fk_bank = $obj->fk_bank;
$this->fk_user_creat = $obj->fk_user_creat;
Expand Down Expand Up @@ -577,7 +587,7 @@ public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom
$acc = new Account($this->db);
$acc->fetch($accountid);

$total = $this->total;
$total = $this->amount;
if ($mode == 'payment_sc') {
$total = -$total;
}
Expand Down
15 changes: 12 additions & 3 deletions htdocs/compta/tva/class/paymentvat.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright (C) 2004-2007 Laurent Destailleur <[email protected]>
* Copyright (C) 2021 Gauthier VERDOL <[email protected]>
* Copyright (C) 2024 Frédéric France <[email protected]>
* Copyright (C) 2024 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 @@ -58,12 +59,20 @@ class PaymentVAT extends CommonObject
public $datep = '';

/**
* @deprecated
* @deprecated Use $amount instead
* @see $amount
* @var float|int
*/
public $total;

/**
* @var float|int
*/
public $amount; // Total amount of payment

/**
* @var array<float|int>
*/
public $amounts = array(); // Array of amounts

/**
Expand All @@ -73,7 +82,7 @@ class PaymentVAT extends CommonObject

/**
* @var string
* @deprecated
* @deprecated Use $num_payment instead
* @see $num_payment
*/
public $num_paiement;
Expand Down Expand Up @@ -578,7 +587,7 @@ public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom
$acc = new Account($this->db);
$acc->fetch($accountid);

$total = $this->total;
$total = $this->amount;
if ($mode == 'payment_vat') {
$total = -$total;
}
Expand Down
16 changes: 15 additions & 1 deletion htdocs/expensereport/class/paymentexpensereport.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* Copyright (C) 2015-2017 Alexandre Spangaro <[email protected]>
* Copyright (C) 2018 Nicolas ZABOURI <[email protected]>
* Copyright (C) 2024 Frédéric France <[email protected]>
* Copyright (C) 2024 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 @@ -65,7 +66,13 @@ class PaymentExpenseReport extends CommonObject
* @var int|string
*/
public $datep = '';
/**
* @var float|int
*/
public $amount; // Total amount of payment
/**
* @var array<float|int>
*/
public $amounts = array(); // Array of amounts

/**
Expand Down Expand Up @@ -94,7 +101,14 @@ class PaymentExpenseReport extends CommonObject
*/
public $fk_user_modif;

/**
* @var string
*/
public $type_code;

/**
* @var string
*/
public $type_label;

/**
Expand Down Expand Up @@ -693,7 +707,7 @@ public function getNomUrl($withpicto = 0, $maxlen = 0)
}
global $action;
$hookmanager->initHooks(array($this->element . 'dao'));
$parameters = array('id'=>$this->id, 'getnomurl' => &$result);
$parameters = array('id' => $this->id, 'getnomurl' => &$result);
$reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook > 0) {
$result = $hookmanager->resPrint;
Expand Down
28 changes: 25 additions & 3 deletions htdocs/loan/class/paymentloan.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* Copyright (C) 2014-2018 Alexandre Spangaro <[email protected]>
* Copyright (C) 2015-2024 Frédéric France <[email protected]>
* Copyright (C) 2020 Maxime DEMAREST <[email protected]>
* Copyright (C) 2024 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 @@ -62,14 +63,23 @@ class PaymentLoan extends CommonObject
public $datep = '';

/**
* @var array Array of amounts
* @var array<float|int> Array of amounts
*/
public $amounts = array();

public $amount_capital; // Total amount of payment
/**
* @var float|int Total amount of payment
*/
public $amount_capital;

/**
* @var float|int
*/
public $amount_insurance;

/**
* @var float|int
*/
public $amount_interest;

/**
Expand Down Expand Up @@ -98,10 +108,22 @@ class PaymentLoan extends CommonObject
*/
public $fk_user_modif;

/**
* @var string
*/
public $type_code;
/**
* @var string
*/
public $type_label;
public $chid;
/**
* @var string
*/
public $label;
/**
* @var string
*/
public $paymenttype;
public $bank_account;
public $bank_line;
Expand Down Expand Up @@ -666,7 +688,7 @@ public function getNomUrl($withpicto = 0, $maxlen = 0, $notooltip = 0, $moretitl

global $action;
$hookmanager->initHooks(array($this->element . 'dao'));
$parameters = array('id'=>$this->id, 'getnomurl' => &$result);
$parameters = array('id' => $this->id, 'getnomurl' => &$result);
$reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook > 0) {
$result = $hookmanager->resPrint;
Expand Down
7 changes: 4 additions & 3 deletions htdocs/public/bookcal/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright (C) 2006-2017 Laurent Destailleur <[email protected]>
* Copyright (C) 2009-2012 Regis Houssin <[email protected]>
* Copyright (C) 2023 anthony Berton <[email protected]>
* Copyright (C) 2024 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 @@ -94,7 +95,7 @@
$max_day_in_prev_month = date("t", dol_mktime(0, 0, 0, $prev_month, 1, $prev_year, 'gmt')); // Nb of days in previous month
$max_day_in_month = date("t", dol_mktime(0, 0, 0, $month, 1, $year)); // Nb of days in next month
// tmpday is a negative or null cursor to know how many days before the 1st to show on month view (if tmpday=0, 1st is monday)
$tmpday = -date("w", dol_mktime(12, 0, 0, $month, 1, $year, 'gmt')) + 2; // date('w') is 0 for sunday
$tmpday = - (int) date("w", dol_mktime(12, 0, 0, $month, 1, $year, 'gmt')) + 2; // date('w') is 0 for sunday
$tmpday += ((isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1) - 1);
if ($tmpday >= 1) {
$tmpday -= 7; // If tmpday is 0 we start with sunday, if -6, we start with monday of previous week.
Expand Down Expand Up @@ -398,13 +399,13 @@ function llxHeaderVierge($title, $head = "", $disablejs = 0, $disablehead = 0, $
$numdayinweek = (($i + (isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1)) % 7);
if (!empty($conf->dol_optimize_smallscreen)) {
print ' <td class="center bold uppercase tdfordaytitle'.($i == 0 ? ' borderleft' : '').'">';
$labelshort = array(0=>'SundayMin', 1=>'MondayMin', 2=>'TuesdayMin', 3=>'WednesdayMin', 4=>'ThursdayMin', 5=>'FridayMin', 6=>'SaturdayMin');
$labelshort = array(0 => 'SundayMin', 1 => 'MondayMin', 2 => 'TuesdayMin', 3 => 'WednesdayMin', 4 => 'ThursdayMin', 5 => 'FridayMin', 6 => 'SaturdayMin');
print $langs->trans($labelshort[$numdayinweek]);
print ' </td>'."\n";
} else {
print ' <td class="center minwidth75 bold uppercase small tdoverflowmax50 tdfordaytitle'.($i == 0 ? ' borderleft' : '').'">';
//$labelshort = array(0=>'SundayMin', 1=>'MondayMin', 2=>'TuesdayMin', 3=>'WednesdayMin', 4=>'ThursdayMin', 5=>'FridayMin', 6=>'SaturdayMin');
$labelshort = array(0=>'Sunday', 1=>'Monday', 2=>'Tuesday', 3=>'Wednesday', 4=>'Thursday', 5=>'Friday', 6=>'Saturday');
$labelshort = array(0 => 'Sunday', 1 => 'Monday', 2 => 'Tuesday', 3 => 'Wednesday', 4 => 'Thursday', 5 => 'Friday', 6 => 'Saturday');
print $langs->trans($labelshort[$numdayinweek]);
print ' </td>'."\n";
}
Expand Down

0 comments on commit f5a0255

Please sign in to comment.