From bfd620b73e88777280376bc1c8bf0dada04d74f3 Mon Sep 17 00:00:00 2001 From: MDW Date: Sun, 10 May 2026 00:26:46 +0200 Subject: [PATCH] Qual: Fix Phan notices (#38069) * Qual: Fix Phan notices # Qual: Fix Phan notices Fix notices related to PhanUndeclaredProperty * Qual: Update Phan baseline * Qual: Fix Phan notice that occurred after merge --- dev/tools/phan/baseline.txt | 6 +- htdocs/core/actions_sendmails.inc.php | 6 +- htdocs/projet/tasks/time.php | 9 ++- .../tasks/tpl/linkedobjectblock.tpl.php | 4 +- .../class/html.formlistwebportal.class.php | 55 +++++++++++-------- 5 files changed, 49 insertions(+), 31 deletions(-) diff --git a/dev/tools/phan/baseline.txt b/dev/tools/phan/baseline.txt index c0b4c86a907..01f2013ba02 100644 --- a/dev/tools/phan/baseline.txt +++ b/dev/tools/phan/baseline.txt @@ -9,8 +9,8 @@ */ return [ // # Issue statistics: - // PhanUndeclaredProperty : 390+ occurrences - // PhanUndeclaredGlobalVariable : 50+ occurrences + // PhanUndeclaredProperty : 380+ occurrences + // PhanUndeclaredGlobalVariable : 45+ occurrences // PhanTypeMismatchArgument : 35+ occurrences // PhanTypeMismatchProperty : 20+ occurrences // PhanTypeInvalidDimOffset : 10+ occurrences @@ -38,7 +38,6 @@ return [ 'htdocs/commande/list.php' => ['PhanUndeclaredProperty'], 'htdocs/commande/list_det.php' => ['PhanTypeInvalidDimOffset'], 'htdocs/compta/bank/class/account.class.php' => ['PhanUndeclaredProperty'], - 'htdocs/compta/bank/line.php' => ['PhanUndeclaredGlobalVariable'], 'htdocs/compta/bank/various_payment/card.php' => ['PhanUndeclaredProperty'], 'htdocs/compta/bank/various_payment/document.php' => ['PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'], 'htdocs/compta/facture/class/facture-rec.class.php' => ['PhanUndeclaredProperty'], @@ -220,7 +219,6 @@ return [ 'htdocs/variants/tpl/productattributevalueline_view.tpl.php' => ['PhanUndeclaredProperty'], 'htdocs/webhook/class/target.class.php' => ['PhanUndeclaredMethod'], 'htdocs/webhook/target_card.php' => ['PhanUndeclaredGlobalVariable'], - 'htdocs/webportal/class/html.formlistwebportal.class.php' => ['PhanUndeclaredProperty'], 'htdocs/webservices/server_project.php' => ['PhanUndeclaredProperty'], ], // 'directory_suppressions' => ['src/directory_name' => ['PhanIssueName1', 'PhanIssueName2']] can be manually added if needed. diff --git a/htdocs/core/actions_sendmails.inc.php b/htdocs/core/actions_sendmails.inc.php index af892b9d58e..58ecf64bfa3 100644 --- a/htdocs/core/actions_sendmails.inc.php +++ b/htdocs/core/actions_sendmails.inc.php @@ -1,6 +1,6 @@ - * Copyright (C) 2024-2025 MDW + * Copyright (C) 2024-2026 MDW * Copyright (C) 2024-2025 Frédéric France * Copyright (C) 2013 Juanjo Menent * @@ -155,11 +155,13 @@ if (($action == 'send' || $action == 'relance') && !GETPOST('addfile') && !GETPO $sendtosocid = $thirdparty->id; } } elseif ($object->element == 'member' || $object->element == 'user') { + '@phan-var-force Adherent|User $object'; $thirdparty = $object; if ($object->socid > 0) { $sendtosocid = $object->socid; } } elseif ($object->element == 'expensereport') { + '@phan-var-force ExpenseReport $object'; $tmpuser = new User($db); $tmpuser->fetch($object->fk_user_author); $thirdparty = $tmpuser; @@ -167,11 +169,13 @@ if (($action == 'send' || $action == 'relance') && !GETPOST('addfile') && !GETPO $sendtosocid = $object->socid; } } elseif ($object->element == 'societe') { + '@phan-var-force Societe $object'; $thirdparty = $object; if (is_object($thirdparty) && $thirdparty->id > 0) { $sendtosocid = $thirdparty->id; } } elseif ($object->element == 'contact') { + '@phan-var-force Contact $object'; $contact = $object; if ($contact->id > 0) { $contact->fetch_thirdparty(); diff --git a/htdocs/projet/tasks/time.php b/htdocs/projet/tasks/time.php index 206f66a1167..59e7904b4a8 100644 --- a/htdocs/projet/tasks/time.php +++ b/htdocs/projet/tasks/time.php @@ -7,7 +7,7 @@ * Copyright (C) 2018-2025 Frédéric France * Copyright (C) 2019-2021 Christophe Battarel * Copyright (C) 2023 Gauthier VERDOL - * Copyright (C) 2024-2025 MDW + * Copyright (C) 2024-2026 MDW * Copyright (C) 2024 Vincent de Grandpré * Copyright (C) 2024 Solution Libre SAS * Copyright (C) 2026 Joachim Kueter @@ -504,6 +504,11 @@ if ($action == 'confirm_generateinvoice' && $user->hasRight('facture', 'creer')) foreach ($toselect as $key => $value) { // Get userid, timepent $object->fetchTimeSpent($value); // $value is ID of 1 line in timespent table + if (!array_key_exists($object->timespent_fk_user, $arrayoftasks)) { + $arrayoftasks[$object->timespent_fk_user] = [ + (int) $object->timespent_fk_product => ['timespent' => 0, 'totalvaluetodivideby3600' => 0] + ]; + } $arrayoftasks[$object->timespent_fk_user][(int) $object->timespent_fk_product]['timespent'] += $object->timespent_duration; $arrayoftasks[$object->timespent_fk_user][(int) $object->timespent_fk_product]['totalvaluetodivideby3600'] += ($object->timespent_duration * $object->timespent_thm); } @@ -2463,7 +2468,7 @@ if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0 || $allprojectforuser print ''; if ($action == 'editline' && GETPOSTINT('lineid') == $task_time->rowid) { print img_picto('', 'service'); - print $form->select_produits($task_time->fk_product, 'fk_product', 1, 0, $projectstatic->thirdparty->price_level, 1, 2, '', 1, array(), $projectstatic->thirdparty->id, 'None', 0, 'maxwidth500', ($user->hasRight('produit', 'lire') ? 0 : 1), '', null, 1); + print $form->select_produits($task_time->fk_product, 'fk_product', 1, 0, $projectstatic->thirdparty->price_level, 1, 2, '', 1, array(), $projectstatic->thirdparty->id, 'None', 0, 'maxwidth500', ($user->hasRight('produit', 'lire') ? 0 : 1), '', null, 1); } elseif (!empty($task_time->fk_product)) { $product = new Product($db); $resultFetch = $product->fetch($task_time->fk_product); diff --git a/htdocs/projet/tasks/tpl/linkedobjectblock.tpl.php b/htdocs/projet/tasks/tpl/linkedobjectblock.tpl.php index 1c28eccda55..067abf6a5f7 100644 --- a/htdocs/projet/tasks/tpl/linkedobjectblock.tpl.php +++ b/htdocs/projet/tasks/tpl/linkedobjectblock.tpl.php @@ -3,7 +3,7 @@ * Copyright (C) 2014 Marcos García * Copyright (C) 2019 Laurent Destailleur * Copyright (C) 2024 Charlene Benke - * Copyright (C) 2024 MDW + * Copyright (C) 2024-2026 MDW * Copyright (C) 2025 Frédéric France * * This program is free software; you can redistribute it and/or modify @@ -41,6 +41,7 @@ $langs = $GLOBALS['langs']; * @var CommonObject $object */ $linkedObjectBlock = $GLOBALS['linkedObjectBlock']; +// Note - at this time there does not seem to be a list of linked objects '@phan-var-force CommonObject[] $linkedObjectBlock'; /** @var Task[] $linkedObjectBlock */ @@ -48,7 +49,6 @@ $linkedObjectBlock = $GLOBALS['linkedObjectBlock']; $langs->load("tasks"); $linkedObjectBlock = dol_sort_array($linkedObjectBlock, 'date,ref', 'desc', 0, 0, 1); -'@phan-var-force CommonObject[] $linkedObjectBlock'; // Repeat because type lost after dol_sort_array) /** @var Task[] $linkedObjectBlock */ $total = 0; diff --git a/htdocs/webportal/class/html.formlistwebportal.class.php b/htdocs/webportal/class/html.formlistwebportal.class.php index b996d79185c..b642525092d 100644 --- a/htdocs/webportal/class/html.formlistwebportal.class.php +++ b/htdocs/webportal/class/html.formlistwebportal.class.php @@ -3,7 +3,7 @@ * Copyright (C) 2023-2024 Lionel Vessiller * Copyright (C) 2023-2024 Patrice Andreani * Copyright (C) 2024-2025 Frédéric France - * Copyright (C) 2024-2025 MDW + * Copyright (C) 2024-2026 MDW * Copyright (C) 2026 Charlene Benke * * This program is free software; you can redistribute it and/or modify @@ -580,16 +580,22 @@ class FormListWebPortal if (!empty($field_spec['arrayofkeyval']) && is_array($field_spec['arrayofkeyval'])) { $out = $this->form->selectarray('search_' . $field_key, $field_spec['arrayofkeyval'], (isset($this->search[$field_key]) ? $this->search[$field_key] : ''), $field_spec['notnull'], 0, 0, '', 1, 0, 0, '', ''); } elseif (preg_match('/^(date|timestamp|datetime)/', $field_spec['type'])) { - $postDateStart = dol_mktime(0, 0, 0, - (int) isset($this->search[$field_key . '_dtstartmonth']) ? $this->search[$field_key . '_dtstartmonth'] : 0, - (int) isset($this->search[$field_key . '_dtstartday']) ? $this->search[$field_key . '_dtstartday'] : 0, - (int) isset($this->search[$field_key . '_dtstartyear']) ? $this->search[$field_key . '_dtstartyear'] : 0 - ); - $postDateEnd = dol_mktime(0, 0, 0, - (int) isset($this->search[$field_key . '_dtendmonth']) ? $this->search[$field_key . '_dtendmonth'] : 0, - (int) isset($this->search[$field_key . '_dtendday']) ? $this->search[$field_key . '_dtendday'] : 0, - (int) isset($this->search[$field_key . '_dtendyear']) ? $this->search[$field_key . '_dtendyear'] : 0 - ); + $postDateStart = dol_mktime( + 0, + 0, + 0, + (int) isset($this->search[$field_key . '_dtstartmonth']) ? $this->search[$field_key . '_dtstartmonth'] : 0, + (int) isset($this->search[$field_key . '_dtstartday']) ? $this->search[$field_key . '_dtstartday'] : 0, + (int) isset($this->search[$field_key . '_dtstartyear']) ? $this->search[$field_key . '_dtstartyear'] : 0 + ); + $postDateEnd = dol_mktime( + 0, + 0, + 0, + (int) isset($this->search[$field_key . '_dtendmonth']) ? $this->search[$field_key . '_dtendmonth'] : 0, + (int) isset($this->search[$field_key . '_dtendday']) ? $this->search[$field_key . '_dtendday'] : 0, + (int) isset($this->search[$field_key . '_dtendyear']) ? $this->search[$field_key . '_dtendyear'] : 0 + ); $out = '
'; $out .= $this->form->inputDate('search_' . $field_key . '_dtstart', $postDateStart ? $postDateStart : '', $langs->trans('From')); @@ -617,10 +623,13 @@ class FormListWebPortal // specific to get invoice status (depends on payment) if ($this->element == 'invoice') { + $invoice = $this->object; // Copy to help static analysis + /** @var Facture $invoice */ + '@phan-var-force Facture $invoice'; $discount = new DiscountAbsolute($this->db); // Store company - $idCompany = (int) $this->object->socid; + $idCompany = (int) $invoice->socid; if (!isset($this->companyStaticList[$idCompany])) { $companyStatic = new Societe($this->db); $companyStatic->fetch($idCompany); @@ -629,19 +638,18 @@ class FormListWebPortal $companyStatic = $this->companyStaticList[$idCompany]; // paid sum - $payment = $this->object->getSommePaiement(); - $totalcreditnotes = $this->object->getSumCreditNotesUsed(); - $totaldeposits = $this->object->getSumDepositsUsed(); + $payment = $invoice->getSommePaiement(); + $totalcreditnotes = $invoice->getSumCreditNotesUsed(); + $totaldeposits = $invoice->getSumDepositsUsed(); // remain to pay $totalpay = $payment + $totalcreditnotes + $totaldeposits; - $remaintopay = price2num($this->object->total_ttc - $totalpay); - if ($this->object->status == Facture::STATUS_CLOSED && $this->object->close_code == 'discount_vat') { // If invoice closed with discount for anticipated payment + $remaintopay = price2num($invoice->total_ttc - $totalpay); + if ($invoice->status == Facture::STATUS_CLOSED && $invoice->close_code == 'discount_vat') { // If invoice closed with discount for anticipated payment $remaintopay = 0; } - if ($this->object->type == Facture::TYPE_CREDIT_NOTE && $this->object->paye == 1) { - // @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal - $remaincreditnote = $discount->getAvailableDiscounts($companyStatic, '', 'rc.fk_facture_source=' . $this->object->id); + if ($invoice->type == Facture::TYPE_CREDIT_NOTE && $invoice->paye == 1) { + $remaincreditnote = $discount->getAvailableDiscounts($companyStatic, null, 'rc.fk_facture_source=' . $invoice->id); $remaintopay = -$remaincreditnote; } @@ -688,8 +696,11 @@ class FormListWebPortal $filedir = $conf->{$element}->multidir_output[$this->object->entity] . '/' . dol_sanitizeFileName($this->object->ref); $out = $this->form->getDocumentsLink($element, $filename, $filedir); } elseif ($field_key == 'signature_link') { - if ($this->object->fk_statut == Propal::STATUS_VALIDATED) { - $out = $this->form->getSignatureLink('proposal', $this->object); + $webobject = $this->object; // Intermediate var to help with typing. + /** @var WebPortalPropal|WebPortalOrder|WebPortalInvoice $webobject */ + '@phan-var-force WebPortalPropal|WebPortalOrder|WebPortalInvoice $webobject'; + if ($webobject->fk_statut == Propal::STATUS_VALIDATED) { + $out = $this->form->getSignatureLink('proposal', $webobject); } } else { $out = $this->form->showOutputFieldForObject($this->object, $field_spec, $field_key, $this->object->$field_key, '');