From 2696c9a1071431e300ad5354c5ef9d6f5e75eafe Mon Sep 17 00:00:00 2001 From: MDW Date: Sat, 25 Jan 2025 00:46:59 +0100 Subject: [PATCH] Fix ci phan/phpstan notices # Fix ci phan/phpstan notices Fix most notices, except undefined fk_website in SocieteAccount as it is not clear if that is supposed to be a property there (more specifically, that it is set). --- htdocs/comm/action/index.php | 6 +++--- htdocs/comm/action/peruser.php | 18 +++++++++--------- htdocs/core/class/conf.class.php | 11 ++++++----- htdocs/loan/note.php | 2 +- htdocs/public/payment/paymentok.php | 16 +++++++++------- 5 files changed, 28 insertions(+), 25 deletions(-) diff --git a/htdocs/comm/action/index.php b/htdocs/comm/action/index.php index 86b41f9d7ad..0f46efb5a85 100644 --- a/htdocs/comm/action/index.php +++ b/htdocs/comm/action/index.php @@ -8,7 +8,7 @@ * Copyright (C) 2015 Marcos García * Copyright (C) 2017 Open-DSI * Copyright (C) 2021-2025 Frédéric France - * Copyright (C) 2024 MDW + * Copyright (C) 2024-2025 MDW * * 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 @@ -1145,7 +1145,7 @@ if ($user->hasRight("holiday", "read")) { $sql .= " AND x.date_fin >= '".$db->idate(dol_get_first_day($year, $month))."'"; } if (!$user->hasRight('holiday', 'readall')) { - $sql.= " AND x.fk_user IN(".$db->sanitize(implode(", ", $user->getAllChildIds(1))).") "; + $sql .= " AND x.fk_user IN(".$db->sanitize(implode(", ", $user->getAllChildIds(1))).") "; } $resql = $db->query($sql); @@ -2119,7 +2119,7 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa //var_dump($event->userassigned); //var_dump($event->transparency); print 'use_javascript_ajax)) { // If javascript on $s .= "\n".''."\n"; } else { // If javascript off $newparam = $param; // newparam is for birthday links - $newparam = preg_replace('/showbirthday=[0-1]/i', 'showbirthday='.(empty($showbirthday) ? 1 : 0), $newparam); + $newparam = preg_replace('/showbirthday=[0-1]/i', 'showbirthday='.($showbirthday ? '1' : '0'), $newparam); // Always false @phpstan-ignore-line if (!preg_match('/showbirthday=/i', $newparam)) { $newparam .= '&showbirthday=1'; } $link = ''; - if (empty($showbirthday)) { + if ($showbirthday) { // Always false @phpstan-ignore-line $link .= $langs->trans("AgendaShowBirthdayEvents"); } else { $link .= $langs->trans("AgendaHideBirthdayEvents"); @@ -983,7 +983,7 @@ if ($resql) { // BIRTHDATES CALENDAR // Complete $eventarray with birthdates -if ($showbirthday) { +if ($showbirthday) { // always false @phpstan-ignore-line // Add events in array $sql = 'SELECT sp.rowid, sp.lastname, sp.firstname, sp.birthday'; $sql .= ' FROM '.MAIN_DB_PREFIX.'socpeople as sp'; @@ -1067,7 +1067,7 @@ if ($user->hasRight("holiday", "read")) { $sql .= " AND x.date_debut < '".$db->idate(dol_get_last_day($year, $month))."'"; $sql .= " AND x.date_fin >= '".$db->idate(dol_get_first_day($year, $month))."'"; if (!$user->hasRight('holiday', 'readall')) { - $sql.= " AND x.fk_user IN(".$db->sanitize(implode(", ", $user->getAllChildIds(1))).") "; + $sql .= " AND x.fk_user IN(".$db->sanitize(implode(", ", $user->getAllChildIds(1))).") "; } $resql = $db->query($sql); @@ -1342,7 +1342,7 @@ if (count($listofextcals)) { $addevent = true; } - if ($addevent) { + if ($addevent && $datestart !== null && $dateend !== null) { $event->id = $icalevent['UID']; $event->ref = (string) $event->id; $userstatic = new User($db); @@ -2438,7 +2438,7 @@ function show_day_events2($username, $day, $month, $year, $monthshown, $style, & print 'style="background: #'.$color3.'; "'; } print 'class="'; - print($style3 ? $style3.' ' : ''); + print $style3.' '; print 'center'.($title2 ? ' classfortooltip' : '').($title3 ? ' cursorpointer' : '').'" ref="ref_'.$username->id.'_'.sprintf("%04d", $year).'_'.sprintf("%02d", $month).'_'.sprintf("%02d", $day).'_'.sprintf("%02d", $h).'_30_'.($ids3 ? $ids3 : 'none').'"'.($title3 ? ' title="'.$title3.'"' : '').'>'; print $string3; print ''; @@ -2450,7 +2450,7 @@ function show_day_events2($username, $day, $month, $year, $monthshown, $style, & print 'style="background: #'.$color4.'; "'; } print 'class="'; - print($style4 ? $style4.' ' : ''); + print $style4.' '; print 'center'.($title3 ? ' classfortooltip' : '').($title4 ? ' cursorpointer' : '').'" ref="ref_'.$username->id.'_'.sprintf("%04d", $year).'_'.sprintf("%02d", $month).'_'.sprintf("%02d", $day).'_'.sprintf("%02d", $h).'_45_'.($ids4 ? $ids4 : 'none').'"'.($title4 ? ' title="'.$title4.'"' : '').'>'; print $string4; print ''; diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index e5dde138be6..b24276f92d0 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -5,6 +5,7 @@ * Copyright (C) 2005-2017 Regis Houssin * Copyright (C) 2006 Jean Heimburger * Copyright (C) 2024-2025 Frédéric France + * Copyright (C) 2024-2025 MDW * * 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 @@ -85,7 +86,7 @@ class Conf extends stdClass public $disable_compute; /** - * @var string Used to store current currency (ISO code like 'USD', 'EUR', ...). To get the currency symbol: $langs->getCurrencySymbol($this->currency) + * @var string Used to store current currency (ISO code like 'USD', 'EUR', ...). To get the currency symbol:->getCurrencySymbol($this->currency) */ public $currency; @@ -149,12 +150,12 @@ class Conf extends stdClass public $entities = array(); /** - * @var int Set if we force param dol_hide_topmenu into login url + * @var int<0,1> Set if we force param dol_hide_topmenu into login url */ public $dol_hide_topmenu; /** - * @var int Set if we force param dol_hide_leftmenu into login url + * @var int<0,1> Set if we force param dol_hide_leftmenu into login url */ public $dol_hide_leftmenu; @@ -1204,10 +1205,10 @@ class Conf extends stdClass // For modules that want to disable top or left menu if (!empty($this->global->MAIN_HIDE_TOP_MENU)) { - $this->dol_hide_topmenu = getDolGlobalInt('MAIN_HIDE_TOP_MENU'); + $this->dol_hide_topmenu = (int) (bool) getDolGlobalInt('MAIN_HIDE_TOP_MENU'); } if (!empty($this->global->MAIN_HIDE_LEFT_MENU)) { - $this->dol_hide_leftmenu = getDolGlobalInt('MAIN_HIDE_LEFT_MENU'); + $this->dol_hide_leftmenu = (int) (bool) getDolGlobalInt('MAIN_HIDE_LEFT_MENU'); } if (empty($this->global->MAIN_SIZE_SHORTLIST_LIMIT)) { diff --git a/htdocs/loan/note.php b/htdocs/loan/note.php index 7a117e64ba7..680ad131370 100644 --- a/htdocs/loan/note.php +++ b/htdocs/loan/note.php @@ -6,7 +6,7 @@ * Copyright (C) 2015-2025 Frédéric France * Copyright (C) 2016-2025 Alexandre Spangaro * Copyright (C) 2017 Ferran Marcet - * Copyright (C) 2024 MDW + * Copyright (C) 2024-2025 MDW * * 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 diff --git a/htdocs/public/payment/paymentok.php b/htdocs/public/payment/paymentok.php index aa46e7ccf0b..6d415d7820f 100644 --- a/htdocs/public/payment/paymentok.php +++ b/htdocs/public/payment/paymentok.php @@ -6,6 +6,7 @@ * Copyright (C) 2021 Maxime Demarest * Copyright (C) 2021 Dorian Vabre * Copyright (C) 2024-2025 Frédéric France + * Copyright (C) 2025 MDW * * 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 @@ -44,7 +45,7 @@ if (!defined('NOBROWSERNOTIF')) { } if (!defined('XFRAMEOPTIONS_ALLOWALL')) { - define('XFRAMEOPTIONS_ALLOWALL', '1'); + define('XFRAMEOPTIONS_ALLOWALL', '1'); } // For MultiCompany module. @@ -394,7 +395,7 @@ if (empty($ipaddress)) { $ipaddress = $_SESSION['ipaddress']; } if (empty($TRANSACTIONID)) { - $TRANSACTIONID = empty($_SESSION['TRANSACTIONID']) ? '' :$_SESSION['TRANSACTIONID']; // pi_... or ch_... + $TRANSACTIONID = empty($_SESSION['TRANSACTIONID']) ? '' : $_SESSION['TRANSACTIONID']; // pi_... or ch_... if (empty($TRANSACTIONID) && GETPOST('payment_intent', 'alphanohtml')) { // For the case we use STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION = 2 $TRANSACTIONID = GETPOST('payment_intent', 'alphanohtml'); @@ -1653,18 +1654,18 @@ if ($ispaymentok) { } else { $booth->status = ConferenceOrBooth::STATUS_SUGGESTED; $resultboothupdate = $booth->update($user); - if ($resultboothupdate<0) { + if ($resultboothupdate < 0) { // Finding the thirdparty by getting the invoice $invoice = new Facture($db); $resultinvoice = $invoice->fetch($ref); - if ($resultinvoice<0) { + if ($resultinvoice < 0) { $postactionmessages[] = 'Could not find the associated invoice.'; $ispostactionok = -1; $error++; } else { $thirdparty = new Societe($db); $resultthirdparty = $thirdparty->fetch($invoice->socid); - if ($resultthirdparty<0) { + if ($resultthirdparty < 0) { $error++; setEventMessages(null, $thirdparty->errors, "errors"); } else { @@ -1893,10 +1894,11 @@ if ($ispaymentok) { $payerID = empty($PAYPALPAYERID) ? $_SESSION['payerID'] : $PAYPALPAYERID; // Set by newpayment.php $currencyCodeType = empty($_SESSION['currencyCodeType']) ? '' : $_SESSION['currencyCodeType']; - $FinalPaymentAmt = empty($_SESSION["FinalPaymentAmt"]) ? '': $_SESSION["FinalPaymentAmt"]; + $FinalPaymentAmt = empty($_SESSION["FinalPaymentAmt"]) ? '' : $_SESSION["FinalPaymentAmt"]; $paymentType = empty($_SESSION['PaymentType']) ? '' : $_SESSION['PaymentType']; // Seems used by paypal only if (is_object($object) && method_exists($object, 'call_trigger')) { + '@phan-var-force CommonObject $object'; // Call trigger $result = $object->call_trigger('PAYMENTONLINE_PAYMENT_OK', $user); if ($result < 0) { @@ -1904,7 +1906,7 @@ if ($ispaymentok) { } // End call triggers } elseif (get_class($object) == 'stdClass') { - //In some case $object is not instantiate (for paiement on custom object) We need to deal with payment + //In some cases $object is not instantiated (for payment on custom object) We need to deal with payment include_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; $paiement = new Paiement($db); $result = $paiement->call_trigger('PAYMENTONLINE_PAYMENT_OK', $user);