From 33486f10c05b9e24796aa29ced078ccf31b13d3f Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 20 Mar 2024 13:58:43 +0100 Subject: [PATCH 01/23] Fix PhanTypeMismatchReturnNullable by initialising return value --- htdocs/adherents/class/adherent.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index c6ce7429708..f71fa705c3f 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -560,12 +560,13 @@ class Adherent extends CommonObject * Return translated label by the nature of a adherent (physical or moral) * * @param string $morphy Nature of the adherent (physical or moral) - * @param int $addbadge Add badge (1=Full label, 2=First letters only) + * @param int<0,2> $addbadge Add badge (1=Full label, 2=First letters only) * @return string Label */ public function getmorphylib($morphy = '', $addbadge = 0) { global $langs; + $s = ''; // Clean var if (!$morphy) { @@ -573,7 +574,6 @@ class Adherent extends CommonObject } if ($addbadge) { - $s = ''; $labeltoshowm = $langs->trans("Moral"); $labeltoshowp = $langs->trans("Physical"); if ($morphy == 'phy') { From 3b93de27097f3a8926d1d9f750a952472dffde8c Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 20 Mar 2024 14:10:45 +0100 Subject: [PATCH 02/23] Fix PhanTypeMismatchReturnNullable by initialising return value + Some PHPdoc typing --- .../adherents/class/adherentstats.class.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/htdocs/adherents/class/adherentstats.class.php b/htdocs/adherents/class/adherentstats.class.php index f99b20f86d5..612f408edd9 100644 --- a/htdocs/adherents/class/adherentstats.class.php +++ b/htdocs/adherents/class/adherentstats.class.php @@ -3,6 +3,7 @@ * Copyright (c) 2005-2011 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2023 Waël Almoman + * Copyright (C) 2024 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 @@ -168,15 +169,15 @@ class AdherentStats extends Stats /** * Return count of member by status group by adh type, total and average * - * @param int $numberYears Number of years to scan (0 = all) - * @return array Array with total of draft, pending, uptodate, expired, resiliated for each member type + * @param int $numberYears Number of years to scan (0 = all) + * @return array Array with total of draft, pending, uptodate, expired, resiliated for each member type */ public function countMembersByTypeAndStatus($numberYears = 0) { global $user; $now = dol_now(); - $endYear = date('Y'); + $endYear = (int) date('Y'); $startYear = $endYear - $numberYears; $sql = "SELECT t.rowid as fk_adherent_type, t.libelle as label"; @@ -224,7 +225,7 @@ class AdherentStats extends Stats 'members_resiliated' => (int) $objp->members_resiliated ); $totalrow = 0; - foreach ($MembersCountArray[$objp->fk_adherent_type] as $key=>$nb) { + foreach ($MembersCountArray[$objp->fk_adherent_type] as $key => $nb) { if ($key != 'label') { $totalrow += $nb; $totalstatus[$key] += $nb; @@ -244,16 +245,17 @@ class AdherentStats extends Stats /** * Return count of member by status group by adh type, total and average * - * @param int $numberYears Number of years to scan (0 = all) - * @return array Array with total of draft, pending, uptodate, expired, resiliated for each member tag + * @param int $numberYears Number of years to scan (0 = all) + * @return array Array with total of draft, pending, uptodate, expired, resiliated for each member tag */ public function countMembersByTagAndStatus($numberYears = 0) { global $user; $now = dol_now(); - $endYear = date('Y'); + $endYear = (int) date('Y'); $startYear = $endYear - $numberYears; + $MembersCountArray = []; $sql = "SELECT c.rowid as fk_categorie, c.label as label"; $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_DRAFT, "'members_draft'", 'NULL').") as members_draft"; @@ -282,7 +284,6 @@ class AdherentStats extends Stats if ($result) { $num = $this->db->num_rows($result); $i = 0; - $MembersCountArray = []; $totalstatus = array( 'label' => 'Total', 'members_draft' => 0, @@ -304,7 +305,7 @@ class AdherentStats extends Stats 'members_resiliated' => (int) $objp->members_resiliated ); $totalrow = 0; - foreach ($MembersCountArray[$objp->fk_categorie] as $key=>$nb) { + foreach ($MembersCountArray[$objp->fk_categorie] as $key => $nb) { if ($key != 'label') { $totalrow += $nb; $totalstatus[$key] += $nb; From 3a27977b46fc942eb664e9f933bbab556051f5d8 Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 20 Mar 2024 14:18:37 +0100 Subject: [PATCH 03/23] Fix PhanTypeMismatchReturnNullable with typing test --- htdocs/comm/action/class/actioncomm.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index f4f77bcaa9d..09e73b188f8 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -1393,7 +1393,7 @@ class ActionComm extends CommonObject * * @param User $user Object user * @param int $load_state_board Load indicator array this->nb - * @return WorkboardResponse|int Return integer <0 if KO, WorkboardResponse if OK + * @return WorkboardResponse|int<-1,1> Return integer <0 if KO, WorkboardResponse if OK */ public function load_board($user, $load_state_board = 0) { @@ -1462,7 +1462,7 @@ class ActionComm extends CommonObject } $this->db->free($resql); - if (empty($load_state_board)) { + if (empty($load_state_board) && $response instanceof WorkboardResponse) { return $response; } else { return 1; From 0a1a663e3471360ce6a8b79e8df535ad027f6609 Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 20 Mar 2024 14:21:35 +0100 Subject: [PATCH 04/23] Fix PhanTypeMismatchReturnNullable with initialisation --- htdocs/comm/propal/class/api_proposals.class.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/comm/propal/class/api_proposals.class.php b/htdocs/comm/propal/class/api_proposals.class.php index aa1e3d0e980..546d40d052d 100644 --- a/htdocs/comm/propal/class/api_proposals.class.php +++ b/htdocs/comm/propal/class/api_proposals.class.php @@ -4,6 +4,7 @@ * Copyright (C) 2020 Thibault FOUCART * Copyright (C) 2022 ATM Consulting * Copyright (C) 2022 OpenDSI + * Copyright (C) 2024 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 @@ -410,6 +411,7 @@ class Proposals extends DolibarrApi } $errors = []; + $updateRes = 0; $this->db->begin(); foreach ($request_data as $TData) { From d245dab56b56dcfab7454a395b790052a094a9c3 Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 20 Mar 2024 14:56:14 +0100 Subject: [PATCH 05/23] Fix PhanTypeMismatchReturnNullable by setting variable --- htdocs/projet/class/task.class.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/htdocs/projet/class/task.class.php b/htdocs/projet/class/task.class.php index 45dcad80025..84d78726599 100644 --- a/htdocs/projet/class/task.class.php +++ b/htdocs/projet/class/task.class.php @@ -2051,9 +2051,10 @@ class Task extends CommonObjectLine $this->error = $clone_task->error; $error++; } - // End - if (!$error) { + if ($error) { + $clone_task_id = 0; // For static tool check + } else { $clone_task_id = $clone_task->id; $clone_task_ref = $clone_task->ref; From 7e1bf61c0db34f4deb6308e03472444a8da63249 Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 20 Mar 2024 17:59:48 +0100 Subject: [PATCH 06/23] Fix PhanTypeMismatchReturnNullable with init --- htdocs/core/class/html.formprojet.class.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/htdocs/core/class/html.formprojet.class.php b/htdocs/core/class/html.formprojet.class.php index 9bbc5e75018..b6f50754c6b 100644 --- a/htdocs/core/class/html.formprojet.class.php +++ b/htdocs/core/class/html.formprojet.class.php @@ -3,6 +3,7 @@ * Copyright (C) 2015 Marcos García * Copyright (C) 2018 Charlene Benke * Copyright (C) 2024 Frédéric France + * Copyright (C) 2024 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 @@ -686,7 +687,7 @@ class FormProjets extends Form * @param string $morecss Add more css * @param int $noadmininfo 0=Add admin info, 1=Disable admin info * @param int $addcombojs 1=Add a js combo - * @return int|string The HTML select list of element or '' if nothing or -1 if KO + * @return int<-1,-1>|string The HTML select list of element or '' if nothing or -1 if KO */ public function selectOpportunityStatus($htmlname, $preselected = '-1', $showempty = 1, $useshortlabel = 0, $showallnone = 0, $showpercent = 0, $morecss = '', $noadmininfo = 0, $addcombojs = 0) { @@ -701,6 +702,7 @@ class FormProjets extends Form if ($resql) { $num = $this->db->num_rows($resql); $i = 0; + $sellist = ''; if ($num > 0) { $sellist = ''; } @@ -7277,7 +7277,7 @@ abstract class CommonObject if (!preg_match('/search_/', $keyprefix)) { // If keyprefix is search_ or search_options_, we must just use a simple text field require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; $doleditor = new DolEditor($keyprefix.$key.$keysuffix, $value, '', 200, 'dolibarr_notes', 'In', false, false, isModEnabled('fckeditor') && $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_5, '90%'); - $out = $doleditor->Create(1, '', true, '', '', $moreparam, $morecss); + $out = (string) $doleditor->Create(1, '', true, '', '', $moreparam, $morecss); } else { $out = ''; } From 2496d20d4fe19067463e67fe3a615e52c792d80a Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 20 Mar 2024 23:38:28 +0100 Subject: [PATCH 23/23] Fix nullable return with if($ok == 1) in stead of if($ok) # Fix nullable return with if($ok == 1) in stead of if($ok) This seems to be a bug in Phan where if($ok) changes the type of $ok. Testing with '$ok == 1' instead fixes the issue. This has been reported to the phan team. --- htdocs/core/modules/DolibarrModules.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/core/modules/DolibarrModules.class.php b/htdocs/core/modules/DolibarrModules.class.php index 850ec739d06..41d2b20efd1 100644 --- a/htdocs/core/modules/DolibarrModules.class.php +++ b/htdocs/core/modules/DolibarrModules.class.php @@ -1126,7 +1126,7 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it * * @param string $reldir Relative directory where to scan files. Example: '/install/mysql/' or '/module/sql/' * @param string $onlywithsuffix Only with the defined suffix - * @return int Return integer <=0 if KO, >0 if OK + * @return int<0,1> Return integer <=0 if KO, >0 if OK */ protected function _load_tables($reldir, $onlywithsuffix = '') { @@ -1135,6 +1135,7 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it $error = 0; $dirfound = 0; + $ok = 1; if (empty($reldir)) { return 1; @@ -1142,9 +1143,8 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it include_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; - $ok = 1; foreach ($conf->file->dol_document_root as $dirroot) { - if ($ok) { + if ($ok == 1) { $dirsql = $dirroot.$reldir; $ok = 0;