Qual: Fix PHPStan for ldap, pgsql, odtphp (#38246)

# Qual: Fix PHPStan for ldap, pgsql, odtphp

- Adjust typing in ldap and pgsql class to fix PHPStan notices;
- Exclude all files for odtphp from analysis (external lib);
- Update PHPStan baseline.
This commit is contained in:
MDW 2026-05-18 03:01:50 +02:00 committed by GitHub
parent a74de0be97
commit 24bba6caa9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 18 additions and 383 deletions

View file

@ -2664,12 +2664,6 @@ parameters:
count: 1
path: ../../../htdocs/core/ajax/ajaxdirpreview.php
-
message: '#^Variable \$action might not be defined\.$#'
identifier: variable.undefined
count: 1
path: ../../../htdocs/core/ajax/ajaxdirtree.php
-
message: '#^Variable \$original_file might not be defined\.$#'
identifier: variable.undefined
@ -3306,144 +3300,6 @@ parameters:
count: 1
path: ../../../htdocs/core/class/interfaces.class.php
-
message: '#^If condition is always false\.$#'
identifier: if.alwaysFalse
count: 1
path: ../../../htdocs/core/class/ldap.class.php
-
message: '#^Negated boolean expression is always true\.$#'
identifier: booleanNot.alwaysTrue
count: 2
path: ../../../htdocs/core/class/ldap.class.php
-
message: '#^Parameter \#1 \$ldap of function ldap_add expects LDAP\\Connection, resource\|true given\.$#'
identifier: argument.type
count: 1
path: ../../../htdocs/core/class/ldap.class.php
-
message: '#^Parameter \#1 \$ldap of function ldap_bind expects LDAP\\Connection, bool\|resource given\.$#'
identifier: argument.type
count: 2
path: ../../../htdocs/core/class/ldap.class.php
-
message: '#^Parameter \#1 \$ldap of function ldap_delete expects LDAP\\Connection, resource\|true given\.$#'
identifier: argument.type
count: 1
path: ../../../htdocs/core/class/ldap.class.php
-
message: '#^Parameter \#1 \$ldap of function ldap_errno expects LDAP\\Connection, bool\|resource given\.$#'
identifier: argument.type
count: 9
path: ../../../htdocs/core/class/ldap.class.php
-
message: '#^Parameter \#1 \$ldap of function ldap_errno expects LDAP\\Connection, resource\|true given\.$#'
identifier: argument.type
count: 3
path: ../../../htdocs/core/class/ldap.class.php
-
message: '#^Parameter \#1 \$ldap of function ldap_error expects LDAP\\Connection, bool\|resource given\.$#'
identifier: argument.type
count: 9
path: ../../../htdocs/core/class/ldap.class.php
-
message: '#^Parameter \#1 \$ldap of function ldap_error expects LDAP\\Connection, resource\|true given\.$#'
identifier: argument.type
count: 8
path: ../../../htdocs/core/class/ldap.class.php
-
message: '#^Parameter \#1 \$ldap of function ldap_first_entry expects LDAP\\Connection, bool\|resource given\.$#'
identifier: argument.type
count: 2
path: ../../../htdocs/core/class/ldap.class.php
-
message: '#^Parameter \#1 \$ldap of function ldap_first_entry expects LDAP\\Connection, resource\|true given\.$#'
identifier: argument.type
count: 1
path: ../../../htdocs/core/class/ldap.class.php
-
message: '#^Parameter \#1 \$ldap of function ldap_get_attributes expects LDAP\\Connection, resource\|true given\.$#'
identifier: argument.type
count: 1
path: ../../../htdocs/core/class/ldap.class.php
-
message: '#^Parameter \#1 \$ldap of function ldap_get_entries expects LDAP\\Connection, bool\|resource given\.$#'
identifier: argument.type
count: 3
path: ../../../htdocs/core/class/ldap.class.php
-
message: '#^Parameter \#1 \$ldap of function ldap_get_option expects LDAP\\Connection, bool\|resource given\.$#'
identifier: argument.type
count: 1
path: ../../../htdocs/core/class/ldap.class.php
-
message: '#^Parameter \#1 \$ldap of function ldap_get_values_len expects LDAP\\Connection, bool\|resource given\.$#'
identifier: argument.type
count: 2
path: ../../../htdocs/core/class/ldap.class.php
-
message: '#^Parameter \#1 \$ldap of function ldap_mod_add expects LDAP\\Connection, resource\|true given\.$#'
identifier: argument.type
count: 1
path: ../../../htdocs/core/class/ldap.class.php
-
message: '#^Parameter \#1 \$ldap of function ldap_mod_del expects LDAP\\Connection, resource\|true given\.$#'
identifier: argument.type
count: 1
path: ../../../htdocs/core/class/ldap.class.php
-
message: '#^Parameter \#1 \$ldap of function ldap_mod_replace expects LDAP\\Connection, resource\|true given\.$#'
identifier: argument.type
count: 2
path: ../../../htdocs/core/class/ldap.class.php
-
message: '#^Parameter \#1 \$ldap of function ldap_rename expects LDAP\\Connection, resource\|true given\.$#'
identifier: argument.type
count: 1
path: ../../../htdocs/core/class/ldap.class.php
-
message: '#^Parameter \#1 \$ldap of function ldap_search expects array\|LDAP\\Connection, bool\|resource given\.$#'
identifier: argument.type
count: 6
path: ../../../htdocs/core/class/ldap.class.php
-
message: '#^Parameter \#1 \$ldap of function ldap_search expects array\|LDAP\\Connection, resource\|true given\.$#'
identifier: argument.type
count: 1
path: ../../../htdocs/core/class/ldap.class.php
-
message: '#^Parameter \#1 \$ldap of function ldap_set_option expects LDAP\\Connection\|null, bool\|resource given\.$#'
identifier: argument.type
count: 3
path: ../../../htdocs/core/class/ldap.class.php
-
message: '#^Parameter \#1 \$ldap of function ldap_unbind expects LDAP\\Connection, resource given\.$#'
identifier: argument.type
count: 1
path: ../../../htdocs/core/class/ldap.class.php
-
message: '#^Negated boolean expression is always true\.$#'
identifier: booleanNot.alwaysTrue
@ -3600,48 +3456,6 @@ parameters:
count: 1
path: ../../../htdocs/core/db/mysqli.class.php
-
message: '#^Parameter \#1 \$result of function pg_affected_rows expects PgSql\\Result, bool\|resource given\.$#'
identifier: argument.type
count: 1
path: ../../../htdocs/core/db/pgsql.class.php
-
message: '#^Parameter \#1 \$result of function pg_fetch_array expects PgSql\\Result, bool\|resource given\.$#'
identifier: argument.type
count: 1
path: ../../../htdocs/core/db/pgsql.class.php
-
message: '#^Parameter \#1 \$result of function pg_fetch_object expects PgSql\\Result, bool\|resource given\.$#'
identifier: argument.type
count: 1
path: ../../../htdocs/core/db/pgsql.class.php
-
message: '#^Parameter \#1 \$result of function pg_fetch_row expects PgSql\\Result, bool\|resource given\.$#'
identifier: argument.type
count: 1
path: ../../../htdocs/core/db/pgsql.class.php
-
message: '#^Parameter \#1 \$result of function pg_free_result expects PgSql\\Result, resource given\.$#'
identifier: argument.type
count: 1
path: ../../../htdocs/core/db/pgsql.class.php
-
message: '#^Parameter \#1 \$result of function pg_num_rows expects PgSql\\Result, resource\|true given\.$#'
identifier: argument.type
count: 1
path: ../../../htdocs/core/db/pgsql.class.php
-
message: '#^Parameter \#1 \$resultset of method DoliDBPgsql\:\:fetch_row\(\) expects resource, PgSql\\Result given\.$#'
identifier: argument.type
count: 2
path: ../../../htdocs/core/db/pgsql.class.php
-
message: '#^Variable \$conf might not be defined\.$#'
identifier: variable.undefined
@ -4026,18 +3840,6 @@ parameters:
count: 1
path: ../../../htdocs/core/login/functions_ldap.php
-
message: '#^Parameter \#1 \$ldap of function ldap_errno expects LDAP\\Connection, resource given\.$#'
identifier: argument.type
count: 1
path: ../../../htdocs/core/login/functions_ldap.php
-
message: '#^Parameter \#1 \$ldap of function ldap_error expects LDAP\\Connection, resource given\.$#'
identifier: argument.type
count: 1
path: ../../../htdocs/core/login/functions_ldap.php
-
message: '#^If condition is always true\.$#'
identifier: if.alwaysTrue
@ -5844,180 +5646,6 @@ parameters:
count: 1
path: ../../../htdocs/imports/import.php
-
message: '#^Class Segment implements generic interface IteratorAggregate but does not specify its types\: TKey, TValue$#'
identifier: missingType.generics
count: 1
path: ../../../htdocs/includes/odtphp/Segment.php
-
message: '#^Default value of the parameter \#3 \$encode \(true\) of method Segment\:\:setVars\(\) is incompatible with type string\.$#'
identifier: parameter.defaultValue
count: 1
path: ../../../htdocs/includes/odtphp/Segment.php
-
message: '#^Method Segment\:\:__call\(\) has parameter \$args with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: ../../../htdocs/includes/odtphp/Segment.php
-
message: '#^Method Segment\:\:macroReplace\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: ../../../htdocs/includes/odtphp/Segment.php
-
message: '#^Parameter \#3 \$encode of method Segment\:\:setVars\(\) expects string, false given\.$#'
identifier: argument.type
count: 1
path: ../../../htdocs/includes/odtphp/Segment.php
-
message: '#^Property Segment\:\:\$children has no type specified\.$#'
identifier: missingType.property
count: 1
path: ../../../htdocs/includes/odtphp/Segment.php
-
message: '#^Property Segment\:\:\$file has no type specified\.$#'
identifier: missingType.property
count: 1
path: ../../../htdocs/includes/odtphp/Segment.php
-
message: '#^Property Segment\:\:\$images has no type specified\.$#'
identifier: missingType.property
count: 1
path: ../../../htdocs/includes/odtphp/Segment.php
-
message: '#^Property Segment\:\:\$odf has no type specified\.$#'
identifier: missingType.property
count: 1
path: ../../../htdocs/includes/odtphp/Segment.php
-
message: '#^Property Segment\:\:\$vars has no type specified\.$#'
identifier: missingType.property
count: 1
path: ../../../htdocs/includes/odtphp/Segment.php
-
message: '#^Class SegmentIterator implements generic interface RecursiveIterator but does not specify its types\: TKey, TValue$#'
identifier: missingType.generics
count: 1
path: ../../../htdocs/includes/odtphp/SegmentIterator.php
-
message: '#^Method SegmentIterator\:\:__construct\(\) has parameter \$ref with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: ../../../htdocs/includes/odtphp/SegmentIterator.php
-
message: '#^Method SegmentIterator\:\:getChildren\(\) return type with generic interface RecursiveIterator does not specify its types\: TKey, TValue$#'
identifier: missingType.generics
count: 1
path: ../../../htdocs/includes/odtphp/SegmentIterator.php
-
message: '#^Property SegmentIterator\:\:\$key has no type specified\.$#'
identifier: missingType.property
count: 1
path: ../../../htdocs/includes/odtphp/SegmentIterator.php
-
message: '#^Property SegmentIterator\:\:\$keys has no type specified\.$#'
identifier: missingType.property
count: 1
path: ../../../htdocs/includes/odtphp/SegmentIterator.php
-
message: '#^Property SegmentIterator\:\:\$ref has no type specified\.$#'
identifier: missingType.property
count: 1
path: ../../../htdocs/includes/odtphp/SegmentIterator.php
-
message: '#^Method Odf\:\:__construct\(\) has parameter \$config with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: ../../../htdocs/includes/odtphp/odf.php
-
message: '#^Method Odf\:\:_getDataFromHtml\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: ../../../htdocs/includes/odtphp/odf.php
-
message: '#^Method Odf\:\:_isHtmlTag\(\) is unused\.$#'
identifier: method.unused
count: 1
path: ../../../htdocs/includes/odtphp/odf.php
-
message: '#^Method Odf\:\:_replaceHtmlWithOdtTag\(\) has parameter \$customStyles with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: ../../../htdocs/includes/odtphp/odf.php
-
message: '#^Method Odf\:\:_replaceHtmlWithOdtTag\(\) has parameter \$fontDeclarations with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: ../../../htdocs/includes/odtphp/odf.php
-
message: '#^Method Odf\:\:_replaceHtmlWithOdtTag\(\) has parameter \$tags with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: ../../../htdocs/includes/odtphp/odf.php
-
message: '#^Method Odf\:\:getConfig\(\) should return string but returns false\.$#'
identifier: return.type
count: 1
path: ../../../htdocs/includes/odtphp/odf.php
-
message: '#^Parameter \#1 \$prefix of function uniqid expects string, int\<0, max\> given\.$#'
identifier: argument.type
count: 1
path: ../../../htdocs/includes/odtphp/odf.php
-
message: '#^Property Odf\:\:\$config has no type specified\.$#'
identifier: missingType.property
count: 1
path: ../../../htdocs/includes/odtphp/odf.php
-
message: '#^Property Odf\:\:\$images has no type specified\.$#'
identifier: missingType.property
count: 1
path: ../../../htdocs/includes/odtphp/odf.php
-
message: '#^Property Odf\:\:\$segments has no type specified\.$#'
identifier: missingType.property
count: 1
path: ../../../htdocs/includes/odtphp/odf.php
-
message: '#^Property Odf\:\:\$userdefined has no type specified\.$#'
identifier: missingType.property
count: 1
path: ../../../htdocs/includes/odtphp/odf.php
-
message: '#^Property Odf\:\:\$vars has no type specified\.$#'
identifier: missingType.property
count: 1
path: ../../../htdocs/includes/odtphp/odf.php
-
message: '#^Ternary operator condition is always true\.$#'
identifier: ternary.alwaysTrue

View file

@ -32,7 +32,7 @@ parameters:
- htdocs/includes/mobiledetect/*
- htdocs/includes/nusoap/*
- htdocs/includes/OAuth/*
- htdocs/includes/odtphp/zip/*
- htdocs/includes/odtphp/*
- htdocs/includes/parsedown/*
- htdocs/includes/php-iban/*
- htdocs/includes/phpoffice/*

View file

@ -30,7 +30,7 @@
* Note:
* LDAP_ESCAPE_FILTER is to escape char array('\\', '*', '(', ')', "\x00")
* LDAP_ESCAPE_DN is to escape char array('\\', ',', '=', '+', '<', '>', ';', '"', '#')
* @phan-file-suppress PhanTypeMismatchArgumentInternal (notifications concern 'resource)
* @phan-file-suppress PhanTypeMismatchArgumentInternal (notifications concern 'resource')
*/
/**
@ -242,7 +242,8 @@ class Ldap
public $ldapcharset = 'UTF-8';
/**
* @var bool|resource The internal LDAP connection handle. Was a resource before PHP 8.1 and is an object of class LDAP\Connection since PHP 8.1
* @var false|resource The internal LDAP connection handle. Was a resource before PHP 8.1 and is an object of class LDAP\Connection since PHP 8.1
* @phpstan-var LDAP\Connection
*/
public $connection;
@ -346,7 +347,7 @@ class Ldap
if (empty($this->error)) {
// Loop on each ldap server
foreach ($this->server as $host) {
if ($connected) {
if ($connected) { // @phpstan-ignore if.alwaysFalse
break;
}
if (empty($host)) {
@ -384,7 +385,7 @@ class Ldap
}
}
if (is_resource($this->connection) || is_object($this->connection)) {
if ($this->connection !== false) {
if ($ldapdebug) {
dol_syslog(get_class($this)."::connectBind this->connection is ok", LOG_DEBUG);
}
@ -436,7 +437,7 @@ class Ldap
}
}
// Try in anonymous
if (!$this->bind) {
if (!$this->bind) { // @phpstan-ignore booleanNot.alwaysTrue
dol_syslog(get_class($this)."::connectBind try bind anonymously on ".$host, LOG_DEBUG);
$result = $this->bind();
if ($result) {
@ -451,7 +452,7 @@ class Ldap
}
}
if (!$connected) {
if (!$connected) { // @phpstan-ignore booleanNot.alwaysTrue
$this->unbind();
}
} // End loop on each server
@ -540,7 +541,7 @@ class Ldap
}
}
} else {
if (is_resource($this->connection)) {
if ($this->connection !== false) {
// @phan-suppress-next-line PhanTypeMismatchArgumentInternalReal PhanTypeSuspiciousIndirectVariable
$this->result = @ldap_unbind($this->connection);
}

View file

@ -62,7 +62,9 @@ class DoliDBPgsql extends DoliDB
public $standard_conforming_strings = false;
/** @var resource|boolean Resultset of last query */
/**
* @var false|resource|PgSql\Result Resultset of last query
*/
private $_results;
@ -624,7 +626,8 @@ class DoliDBPgsql extends DoliDB
/**
* Return datas as an array
*
* @param resource $resultset Resultset of request
* @param bool|resource $resultset Resultset of request
* @phpstan-param bool|resource|PgSql\Result $resultset
* @return array<int,mixed>|null|int<0,0> Array or null if KO or end of cursor or 0 if resultset is bool
*/
public function fetch_row($resultset)
@ -634,6 +637,9 @@ class DoliDBPgsql extends DoliDB
if (!is_resource($resultset) && !is_object($resultset)) {
$resultset = $this->_results;
}
if (is_bool($resultset)) {
return 0;
}
return pg_fetch_row($resultset); // @phan-suppress-current-line PhanTypeMismatchArgumentProbablyReal
}

View file

@ -34,7 +34,7 @@ parameters:
- htdocs/includes/mobiledetect/*
- htdocs/includes/nusoap/*
- htdocs/includes/OAuth/*
- htdocs/includes/odtphp/zip/*
- htdocs/includes/odtphp/*
- htdocs/includes/parsedown/*
- htdocs/includes/php-iban/*
- htdocs/includes/phpoffice/*