Qual: Fix PHPStan and Phan notices (#37950)

* Qual: Update GETPOST calls to handle hint array type

# Qual: Update GETPOST calls to handle hint array type

- Updated GETPOST calls for 'amounts' and 'multicurrency_amounts' to explicitly handle array inputs by adding the 'array' type parameter

This fixes PHPStan notices where expressions expect an array.

* Qual: Set type for status label mapping in LignePrelevement (PHPStan)

# Qual: Set type for status label mapping in LignePrelevement (PHPStan)

Added type hint to property `$labelStatus`

* Qual: Add type hints to datec and datep properties in PaymentSocialContribution

# Qual: Add type hints to datec and datep properties in PaymentSocialContribution

Added type hints to datec and datep properties.

* Qual: Add type hint to MIME mapping for image file extensions

# Qual: Add type hint to MIME mapping for image file extensions

Added type hint to `$image_types`

* Qual: Better type hint for getAllItemsLinkedByObjectID method

# Qual: Better type hint for getAllItemsLinkedByObjectID method

The return type annotation for the getAllItemsLinkedByObjectID method has been updated from 'array|int' to 'string[]|int'.

* Qual: Better type hint for fetchAll return value

# Qual: Better type hint for fetchAll return value

Suggest thet fetchAll returns list of objects

* Qual: Remove array from return value hint

* Qual: Add missing type hints to Notify

* Qual: Cast resource IDs to integers in getAllResourcesOfWorkstation

# Qual: Cast resource IDs to integers in getAllResourcesOfWorkstation

Ensure returned value is list of ints as parent::getAllItemsLinkedByObjectID does not ensure value type.

* Qual: Ensure correct return type for getAllGroupsOfWorkstation

* Qual: Improve typing hints

* Qual: Improve typing hints, ignore some notices

* Qual: Fix argument type

* Qual: Improve type hints

* Qual: Improve typing hints

* Qual: Add missing type hint

* Qual: Update Phan baseline

* Qual: Remove redundant exit (PHPStan, Phan)
This commit is contained in:
MDW 2026-04-21 02:28:35 +02:00 committed by GitHub
parent ce3d82417e
commit 295bbc08ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 53 additions and 33 deletions

View file

@ -72,7 +72,6 @@ return [
'htdocs/core/class/html.formcompany.class.php' => ['PhanUndeclaredProperty'],
'htdocs/core/class/html.formmail.class.php' => ['PhanUndeclaredProperty'],
'htdocs/core/class/openid.class.php' => ['PhanTypeMismatchArgument'],
'htdocs/core/class/rssparser.class.php' => ['PhanTypeMismatchArgument'],
'htdocs/core/class/timespent.class.php' => ['PhanUndeclaredMethod', 'PhanUndeclaredProperty'],
'htdocs/core/lib/admin.lib.php' => ['PhanUndeclaredProperty'],
'htdocs/core/lib/files.lib.php' => ['PhanUndeclaredProperty'],

View file

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2011 Auguria <anthony.poiret@auguria.net>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2026 Lenin Rivas <frederic.france@free.fr>
*
@ -59,7 +59,7 @@ $langs->load('compta');
//init var
$invoice_type = GETPOSTINT('invoice_type');
$amountPayment = GETPOST('amountPayment');
$amounts = GETPOST('amounts'); // from text inputs : invoice amount payment (check required)
$amounts = GETPOST('amounts', 'array'); // from text inputs : invoice amount payment (check required)
$remains = GETPOST('remains'); // from dolibarr's object (no need to check)
$currentInvId = GETPOST('imgClicked'); // from DOM elements : imgId (equals invoice id)
@ -69,7 +69,7 @@ $amountPayment = $amountPayment != '' ? (is_numeric(price2num($amountPayment)) ?
// Multicurrency LRR
$multicurrency = GETPOSTINT('multicurrency');
$multicurrencyAmountPayment = GETPOST('multicurrency_amountPayment');
$multicurrencyAmounts = GETPOST('multicurrency_amounts'); // from text inputs : invoice amount payment (check required)
$multicurrencyAmounts = GETPOST('multicurrency_amounts', 'array'); // from text inputs : invoice amount payment (check required)
$multicurrencyRemains = GETPOST('multicurrency_remains'); // from dolibarr's object (no need to check)
// Getting the posted keys=>values, sanitize the ones who are from text inputs

View file

@ -3,6 +3,7 @@
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2026 MDW <mdeweerd@users.noreply.github.com>
*
* 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
@ -66,6 +67,9 @@ class LignePrelevement
*/
public $db;
/**
* @var string[] Map status index to localized labels
*/
public $labelStatus = array();
const STATUS_DRAFT = 0;

View file

@ -3,7 +3,7 @@
* Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
* Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
*
* 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
@ -59,7 +59,14 @@ class PaymentSocialContribution extends CommonObject
*/
public $fk_charge;
/**
* @var int|'' Date of creation
*/
public $datec = '';
/**
* @var int|'' Date of payment
*/
public $datep = '';
/**
@ -137,7 +144,7 @@ class PaymentSocialContribution extends CommonObject
public $chid;
/**
* @var int|string datepaye
* @var int|'' Payment date when creating
*/
public $datepaye;

View file

@ -189,6 +189,7 @@ class CMailFile
public $html_images = array();
/** @var array<array{name:string,fullpath:string,content_type:string,cid:string,image_encoded:string}> */
public $images_encoded = array();
/** @var array<string,string> Filename extension to MIME mapping */
public $image_types = array(
'gif' => 'image/gif',
'jpg' => 'image/jpeg',

View file

@ -1,7 +1,7 @@
<?php
/* Copyright (C) 2007-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2020 Florian HENRY <florian.henry@scopen.fr>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2025 Frédéric France <frederic.france@free.fr>
*
* This program is free software; you can redistribute it and/or modify
@ -183,7 +183,7 @@ class CLeadStatus extends CommonDict
* @param int $offset Offset
* @param string $filter Filter USF
* @param string $filtermode Filter mode (AND or OR)
* @return array|int int <0 if KO, array of pages if OK
* @return self[]|int int <0 if KO, array of pages if OK
*/
public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
{

View file

@ -4914,7 +4914,7 @@ abstract class CommonObject
* @param string $field_select name of field we need to get a list
* @param string $field_where name of field of object we need to get linked items
* @param string $table_element name of association table
* @return array|int Array of record, -1 if empty
* @return string[]|int Array of record, -1 if empty
*/
public static function getAllItemsLinkedByObjectID($fk_object_where, $field_select, $field_where, $table_element)
{
@ -4946,7 +4946,7 @@ abstract class CommonObject
* @param int $fk_object_where id of object we need to get linked items
* @param string $field_where name of field of object we need to get linked items
* @param string $table_element name of association table
* @return array|int Array of record, -1 if empty
* @return int<-1,max> Array of records, -1 if empty argument
*/
public static function getCountOfItemsLinkedByObjectID($fk_object_where, $field_where, $table_element)
{

View file

@ -139,7 +139,9 @@ class Notify
*/
public $fk_project;
// This codes actions are defined into table llx_notify_def
/**
* @var string[] These codes actions are defined in table llx_notify_def
*/
public static $arrayofnotifsupported = array(
'BILL_CANCEL',
'BILL_VALIDATE',
@ -185,10 +187,10 @@ class Notify
* Return message that say how many notification (and to which email) will occurs on requested event.
* This is to show confirmation messages before event is recorded.
*
* @param string $action Id of action in llx_c_action_trigger
* @param int $socid Id of third party
* @param Object $object Object the notification is about
* @return string Message
* @param string $action Id of action in llx_c_action_trigger
* @param int $socid Id of third party
* @param ?CommonObject $object Object the notification is about
* @return string Message
*/
public function confirmMessage($action, $socid, $object)
{
@ -451,10 +453,10 @@ class Notify
*
* @param string $notifcode Code of action in llx_c_action_trigger (new usage) or Id of action in llx_c_action_trigger (old usage)
* @param int $socid Id of third party or 0 for all thirdparties or -1 for no thirdparties
* @param CommonObject $object Object the notification is about (need it to check threshold value of some notifications)
* @param ?CommonObject $object Object the notification is about (need it to check threshold value of some notifications)
* @param int $userid Id of user or 0 for all users or -1 for no users
* @param array $scope Scope where to search
* @return array|int Return integer <0 if KO, array of notifications to send if OK
* @param string[] $scope Scope where to search
* @return array<string,array{type:'touser'|'tofixedemail',code:string,emaildesc:string,email:string,userid:int,isemailvalid:bool}>|-1 Return integer <0 if KO, array of notifications to send if OK
*/
public function getNotificationsArray($notifcode, $socid = 0, $object = null, $userid = 0, $scope = array('thirdparty', 'user', 'global'))
{
@ -547,7 +549,7 @@ class Notify
$newval2 = trim($obj->email);
$isvalid = isValidEmail($newval2);
if (empty($resarray[$newval2])) {
$resarray[$newval2] = array('type' => 'touser', 'code' => trim($obj->code), 'emaildesc' => 'User id '.$obj->rowid, 'email' => $newval2, 'userid' => $obj->rowid, 'isemailvalid' => $isvalid);
$resarray[$newval2] = array('type' => 'touser', 'code' => trim($obj->code), 'emaildesc' => 'User id '.$obj->rowid, 'email' => $newval2, 'userid' => (int) $obj->rowid, 'isemailvalid' => $isvalid);
}
}
$i++;

View file

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2011-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
*
* This program is free software; you can redistribute it and/or modify
@ -99,6 +99,9 @@ class RssParser
*/
private $current_namespace;
/**
* @var array<array<string,string>|array<string,array<string,string>>>
*/
public $items = array();
/**
* @var array<string,string>|array<string,array<string,string>>
@ -811,11 +814,14 @@ class RssParser
}
} else {
if (!empty($this->initem)) {
$this->concat($this->current_item[$el], $text);
// @phpstan-ignore-next-line argument.type
$this->concat($this->current_item[$el], $text); // @phan-suppress-current-line PhanTypeMismatchArgument
} elseif (!empty($this->intextinput)) {
$this->concat($this->textinput[$el], $text);
// @phpstan-ignore-next-line argument.type
$this->concat($this->textinput[$el], $text); // @phan-suppress-current-line PhanTypeMismatchArgument
} elseif (!empty($this->inimage)) {
$this->concat($this->image[$el], $text);
// @phpstan-ignore-next-line argument.type
$this->concat($this->image[$el], $text); // @phan-suppress-current-line PhanTypeMismatchArgument
} elseif (!empty($this->inchannel)) {
$this->concat($this->channel[$el], $text);
}

View file

@ -1379,7 +1379,7 @@ if (class_exists('mysqli')) {
}
if (strpos($host, 'ssl://') === 0) {
$host = substr($host, 6);
parent::options(MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, false);
parent::options(MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, 0);
// Suppress false positive @phan-suppress-next-line PhanTypeMismatchArgumentInternalProbablyReal
parent::ssl_set(null, null, "", null, null);
$flags = MYSQLI_CLIENT_SSL;

View file

@ -3,6 +3,7 @@
* FCKeditor - The text editor for Internet - http://www.fckeditor.net
* Copyright (C) 2003-2010 Frederico Caldeira Knabben
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2026 MDW <mdeweerd@users.noreply.github.com>
*
* == BEGIN LICENSE ==
*
@ -52,7 +53,6 @@ $entity = ((!empty($_SESSION['dol_entity']) && $_SESSION['dol_entity'] > 1) ? $_
if (!empty($user->admin) && !$user->hasRight('website', 'write')) {
accessforbidden('Need to be admin or having write permission on website module');
exit;
}

View file

@ -3,6 +3,7 @@
* Copyright (C) 2018-2019 Nicolas ZABOURI <info@inovea-conseil.com>
* Copyright (C) 2019-2024 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2026 John BOTELLA
* Copyright (C) 2026 MDW <mdeweerd@users.noreply.github.com>
*
* 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
@ -98,7 +99,7 @@ class modQuickMemo extends DolibarrModules
}
$compatibleHooks = array_unique($compatibleHooks);
// Security check
$compatibleHooks = array_filter($compatibleHooks, function (string $k) {
$compatibleHooks = array_filter($compatibleHooks, /** @return int|false */ static function (string $k) {
return preg_match('/^[a-zA-Z0-9_]+$/', $k);
});

View file

@ -398,7 +398,7 @@ class Position extends CommonObject
* @param string $filter Filter as an Universal Search string.
* Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')'
* @param string $filtermode No more used
* @return array|int int <0 if KO, array of pages if OK
* @return self[]|int int <0 if KO, array of pages if OK
*/
public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
{
@ -985,7 +985,7 @@ class Position extends CommonObject
/**
* Create an array of lines
*
* @return array|int array of lines if OK, <0 if KO
* @return CommonObject[]|int array of lines if OK, <0 if KO
*/
public function getLinesArray()
{
@ -1063,7 +1063,7 @@ class Position extends CommonObject
* getForUser
*
* @param int $userid id of user we need to get position list
* @return array|int of positions of user with for each of them the job fetched into that array
* @return self[]|int of positions of user with for each of them the job fetched into that array
*/
public function getForUser($userid)
{

View file

@ -432,7 +432,7 @@ class Skill extends CommonObject
/**
* Load object lines in memory from the database
*
* @return array|int Return integer <0 if KO, array of skill level found
* @return CommonObject[]|int Return integer <0 if KO, array of skill level found
*/
public function fetchLines()
{
@ -991,7 +991,7 @@ class Skill extends CommonObject
/**
* Create an array of lines
*
* @return array|int array of lines if OK, <0 if KO
* @return Skilldet[]|int array of lines if OK, <0 if KO
*/
public function getLinesArray()
{

View file

@ -95,7 +95,7 @@ class WorkstationResource extends CommonObject
{
global $db;
$obj = new self($db);
return parent::getAllItemsLinkedByObjectID($fk_workstation, 'fk_resource', 'fk_workstation', $obj->table_element);
return array_map('intval', parent::getAllItemsLinkedByObjectID($fk_workstation, 'fk_resource', 'fk_workstation', $obj->table_element));
}
/**

View file

@ -95,7 +95,7 @@ class WorkstationUserGroup extends CommonObject
global $db;
$obj = new self($db);
return parent::getAllItemsLinkedByObjectID($fk_workstation, 'fk_usergroup', 'fk_workstation', $obj->table_element);
return array_map('intval', parent::getAllItemsLinkedByObjectID($fk_workstation, 'fk_usergroup', 'fk_workstation', $obj->table_element));
}
/**