Qual: Fix phan notices in API classes

This commit is contained in:
MDW
2025-03-02 15:10:25 +01:00
parent c02293a880
commit 035ede5874
36 changed files with 417 additions and 107 deletions

View File

@@ -6,7 +6,7 @@
* Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2018-2022 Thibault FOUCART <support@ptibogxiv.net>
* Copyright (C) 2024 Jon Bendtsen <jon.bendtsen.github@jonb.dk>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
*
*
* This program is free software; you can redistribute it and/or modify
@@ -65,7 +65,8 @@ class Setup extends DolibarrApi
* @param string $lang Code of the language the label of the type must be translated to
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.label:like:'SO-%')"
* @return array List of extra fields
* @phan-return Object[] List of extra fields
* @phan-return array<Object|false>
* @phpstan-return array<Object|false>
*
* @url GET actiontriggers
*
@@ -137,6 +138,8 @@ class Setup extends DolibarrApi
* @url GET dictionary/ordering_methods
*
* @return array [List of ordering methods]
* @phan-return array<Object|false>
* @phpstan-return array<Object|false>
*
* @throws RestException 400 Bad value for sqlfilters
* @throws RestException 403 Access denied
@@ -199,6 +202,8 @@ class Setup extends DolibarrApi
* @param int $active Payment type is active or not {@min 0} {@max 1}
* @param string $sqlfilters SQL criteria to filter with. Syntax example "(t.code:=:'OrderByWWW')"
* @return array [List of ordering reasons]
* @phan-return array<Object|false>
* @phpstan-return array<Object|false>
*
* @url GET dictionary/ordering_origins
*
@@ -266,6 +271,8 @@ class Setup extends DolibarrApi
* @url GET dictionary/payment_types
*
* @return array [List of payment types]
* @phan-return array<Object|false>
* @phpstan-return array<Object|false>
*
* @throws RestException 400 Bad value for sqlfilters
* @throws RestException 403 Access denied
@@ -331,6 +338,8 @@ class Setup extends DolibarrApi
* @param string $filter To filter the regions by name
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
* @return array List of regions
* @phan-return Cregion[]
* @phpstan-return Cregion[]
*
* @url GET dictionary/regions
*
@@ -395,6 +404,8 @@ class Setup extends DolibarrApi
*
* @param int $id ID of region
* @return Object Object with cleaned properties
* @phan-return Cregion
* @phpstan-return Cregion
*
* @url GET dictionary/regions/{id}
*
@@ -411,6 +422,8 @@ class Setup extends DolibarrApi
*
* @param string $code Code of region
* @return Object Object with cleaned properties
* @phan-return Cregion
* @phpstan-return Cregion
*
* @url GET dictionary/regions/byCode/{code}
*
@@ -438,6 +451,8 @@ class Setup extends DolibarrApi
* @param string $filter To filter the states by name
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
* @return array List of states
* @phan-return Cstate[]
* @phpstan-return Cstate[]
*
* @url GET dictionary/states
*
@@ -504,6 +519,8 @@ class Setup extends DolibarrApi
*
* @param int $id ID of state
* @return Object Object with cleaned properties
* @phan-return Cstate
* @phpstan-return Cstate
*
* @url GET dictionary/states/{id}
*
@@ -520,6 +537,8 @@ class Setup extends DolibarrApi
*
* @param string $code Code of state
* @return Object Object with cleaned properties
* @phan-return Cstate
* @phpstan-return Cstate
*
* @url GET dictionary/states/byCode/{code}
*
@@ -547,6 +566,8 @@ class Setup extends DolibarrApi
* @param string $lang Code of the language the label of the countries must be translated to
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
* @return array List of countries
* @phan-return Ccountry[]
* @phpstan-return Ccountry[]
*
* @url GET dictionary/countries
*
@@ -612,6 +633,8 @@ class Setup extends DolibarrApi
* @param int $id ID of country
* @param string $lang Code of the language the name of the country must be translated to
* @return Object Object with cleaned properties
* @phan-return Ccountry
* @phpstan-return Ccountry
*
* @url GET dictionary/countries/{id}
*
@@ -629,6 +652,8 @@ class Setup extends DolibarrApi
* @param string $code Code of country (2 characters)
* @param string $lang Code of the language the name of the country must be translated to
* @return Object Object with cleaned properties
* @phan-return Ccountry
* @phpstan-return Ccountry
*
* @url GET dictionary/countries/byCode/{code}
*
@@ -663,6 +688,8 @@ class Setup extends DolibarrApi
* @param int $id ID of region
* @param string $code Code of region
* @return Object Object with cleaned properties
* @phan-return Cregion
* @phpstan-return Cregion
*
* @throws RestException
*/
@@ -670,7 +697,7 @@ class Setup extends DolibarrApi
{
$region = new Cregion($this->db);
$result = $region->fetch($id, $code);
$result = $region->fetch($id, (int) $code);
if ($result < 0) {
throw new RestException(503, 'Error when retrieving region : '.$region->error);
} elseif ($result == 0) {
@@ -686,6 +713,8 @@ class Setup extends DolibarrApi
* @param int $id ID of state
* @param string $code Code of state
* @return Object Object with cleaned properties
* @phan-return Cstate
* @phpstan-return Cstate
*
* @throws RestException
*/
@@ -711,6 +740,8 @@ class Setup extends DolibarrApi
* @param string $iso ISO of country (3 characters)
* @param string $lang Code of the language the name of the country must be translated to
* @return Object Object with cleaned properties
* @phan-return Ccountry
* @phpstan-return Ccountry
*
* @throws RestException
*/
@@ -744,6 +775,8 @@ class Setup extends DolibarrApi
* @url GET dictionary/availability
*
* @return array [List of availability]
* @phan-return array<Object|false>
* @phpstan-return array<Object|false>
*
* @throws RestException 400 Bad value for sqlfilters
* @throws RestException 403 Access denied
@@ -820,7 +853,7 @@ class Setup extends DolibarrApi
* @param object $object Object with label to translate
* @param string $lang Code of the language the name of the object must be translated to
* @param string $prefix Prefix for translation key
* @param array $dict Array of dictionary for translation
* @param string[] $dict Array of dictionary for translation
* @return void
*/
private function translateLabel($object, $lang, $prefix = 'Country', $dict = array('dict'))
@@ -856,6 +889,8 @@ class Setup extends DolibarrApi
* @param int $active Event's type is active or not {@min 0} {@max 1}
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
* @return array List of events types
* @phan-return array<Object|false>
* @phpstan-return array<Object|false>
*
* @url GET dictionary/event_types
*
@@ -923,6 +958,8 @@ class Setup extends DolibarrApi
* @param int $active Event's type is active or not {@min 0} {@max 1}
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
* @return array List of expense report types
* @phan-return array<Object|false>
* @phpstan-return array<Object|false>
*
* @url GET dictionary/expensereport_types
*
@@ -989,6 +1026,8 @@ class Setup extends DolibarrApi
* @param string $lang Code of the language the label of the civility must be translated to
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
* @return array List of Contacts types
* @phan-return array<Object|false>
* @phpstan-return array<Object|false>
*
* @url GET dictionary/contact_types
*
@@ -1058,6 +1097,8 @@ class Setup extends DolibarrApi
* @param string $lang Code of the language the label of the civility must be translated to
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
* @return array List of civility types
* @phan-return array<Object|false>
* @phpstan-return array<Object|false>
*
* @url GET dictionary/civilities
*
@@ -1123,6 +1164,8 @@ class Setup extends DolibarrApi
* @param int $active Payment term is active or not {@min 0} {@max 1}
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
* @return array List of currencies
* @phan-return array<Object|false>
* @phpstan-return array<Object|false>
*
* @url GET dictionary/currencies
*
@@ -1193,6 +1236,8 @@ class Setup extends DolibarrApi
* @param string $elementtype Type of element ('adherent', 'commande', 'thirdparty', 'facture', 'propal', 'product', ...)
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.label:like:'SO-%')"
* @return array List of extra fields
* @phan-return array<string,array<string,array{id:string,type:string,label:string,size:string,elementtype:string,default:string,computed:string,unique:string,required:string,param:string,pos:string,alwayseditable:string,perms:string,list:string,printable:string,totalizable:string,langs:string,help:string,css:string,cssview:string,csslist:string,fk_user_author:string,fk_user_modif:string,datec:string,tms:string}>>
* @phpstan-return array<string,array<string,array{id:string,type:string,label:string,size:string,elementtype:string,default:string,computed:string,unique:string,required:string,param:string,pos:string,alwayseditable:string,perms:string,list:string,printable:string,totalizable:string,langs:string,help:string,css:string,cssview:string,csslist:string,fk_user_author:string,fk_user_modif:string,datec:string,tms:string}>>
*
* @url GET extrafields
*
@@ -1279,9 +1324,10 @@ class Setup extends DolibarrApi
* @param string $attrname extrafield attrname
* @param string $elementtype extrafield elementtype
* @return array
* @phan-return array{success:array{code:int,message:string}}
* @phpstan-return array{success:array{code:int,message:string}}
*
* @url DELETE extrafields/{elementtype}/{attrname}
*
*/
public function deleteExtrafieldsFromNames($attrname, $elementtype)
{
@@ -1315,11 +1361,12 @@ class Setup extends DolibarrApi
* @param string $attrname extrafield attrname
* @param string $elementtype extrafield elementtype
* @return array List of extra fields
* @phan-return array<string,array<string,array{id:string,type:string,label:string,size:string,elementtype:string,default:string,computed:string,unique:string,required:string,param:string,pos:string,alwayseditable:string,perms:string,list:string,printable:string,totalizable:string,langs:string,help:string,css:string,cssview:string,csslist:string,fk_user_author:string,fk_user_modif:string,datec:string,tms:string}>>
* @phpstan-return array<string,array<string,array{id:string,type:string,label:string,size:string,elementtype:string,default:string,computed:string,unique:string,required:string,param:string,pos:string,alwayseditable:string,perms:string,list:string,printable:string,totalizable:string,langs:string,help:string,css:string,cssview:string,csslist:string,fk_user_author:string,fk_user_modif:string,datec:string,tms:string}>>
*
* @url GET extrafields/{elementtype}/{attrname}
*
* @suppress PhanPluginUnknownArrayMethodParamType Luracast limitation
*
*/
public function getExtrafields($attrname, $elementtype)
{
@@ -1390,13 +1437,14 @@ class Setup extends DolibarrApi
*
* @param string $attrname extrafield attrname
* @param string $elementtype extrafield elementtype
* @param array $request_data Request datas
* @param array $request_data Request data
* @phan-param ?array<string,string> $request_data
* @phpstan-param ?array<string,string> $request_data
* @return int ID of extrafield
*
* @url POST extrafields/{elementtype}/{attrname}
*
* @suppress PhanPluginUnknownArrayMethodParamType Luracast limitation
*
*/
public function postExtrafields($attrname, $elementtype, $request_data = null)
{
@@ -1449,7 +1497,7 @@ class Setup extends DolibarrApi
$pos = $request_data['pos'];
$moreparams = array();
if (0 > $extrafields->addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique, $required, $default_value, $param, $alwayseditable, $perms, $list, $help, $computed, $entity, $langfile, $enabled, $totalizable, $printable, $moreparams)) {
if (0 > $extrafields->addExtraField($attrname, $label, $type, (int) $pos, $size, $elementtype, (int) $unique, (int) $required, $default_value, $param, (int) $alwayseditable, $perms, $list, $help, $computed, (string) $entity, $langfile, (string) $enabled, (int) $totalizable, (int) $printable, $moreparams)) {
throw new RestException(500, 'Error creating extrafield', array_merge(array($extrafields->errno), $extrafields->errors));
}
@@ -1474,18 +1522,18 @@ class Setup extends DolibarrApi
}
/**
* Update Extrafield object
*
* @param string $attrname extrafield attrname
* @param string $elementtype extrafield elementtype
* @param array $request_data Request datas
* @param array $request_data Request data
* @phan-param ?array<string,string> $request_data
* @phpstan-param ?array<string,string> $request_data
* @return int ID of extrafield
*
* @url PUT extrafields/{elementtype}/{attrname}
*
* @suppress PhanPluginUnknownArrayMethodParamType Luracast limitation
*
*/
public function updateExtrafields($attrname, $elementtype, $request_data = null)
{
@@ -1535,7 +1583,7 @@ class Setup extends DolibarrApi
$moreparams = array();
dol_syslog(get_class($this).'::updateExtraField', LOG_DEBUG);
if (0 > $extrafields->updateExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique, $required, $default_value, $param, $alwayseditable, $perms, $list, $help, $computed, $entity, $langfile, $enabled, $totalizable, $printable, $moreparams)) {
if (0 > $extrafields->updateExtraField($attrname, $label, $type, (int) $pos, $size, $elementtype, (int) $unique, (int) $required, $default_value, $param, (int) $alwayseditable, $perms, $list, $help, $computed, (string) $entity, $langfile, (string) $enabled, (int) $totalizable, (int) $printable, $moreparams)) {
throw new RestException(500, 'Error updating extrafield', array_merge(array($extrafields->errno), $extrafields->errors));
}
@@ -1571,6 +1619,8 @@ class Setup extends DolibarrApi
* @param int $active Town is active or not {@min 0} {@max 1}
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
* @return array List of towns
* @phan-return array<Object|false>
* @phpstan-return array<Object|false>
*
* @url GET dictionary/towns
*
@@ -1639,6 +1689,8 @@ class Setup extends DolibarrApi
* @url GET dictionary/payment_terms
*
* @return array List of payment terms
* @phan-return array<Object|false>
* @phpstan-return array<Object|false>
*
* @throws RestException 400 Bad value for sqlfilters
* @throws RestException 403 Access denied
@@ -1704,6 +1756,8 @@ class Setup extends DolibarrApi
* @url GET dictionary/shipping_methods
*
* @return array List of shipping methods
* @phan-return array<Object|false>
* @phpstan-return array<Object|false>
*
* @throws RestException 400 Bad value for sqlfilters
* @throws RestException 503 Error when retrieving list of shipping modes
@@ -1764,6 +1818,8 @@ class Setup extends DolibarrApi
* @param int $active Measuring unit is active or not {@min 0} {@max 1}
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
* @return array List of measuring unit
* @phan-return array<Object|false>
* @phpstan-return array<Object|false>
*
* @url GET dictionary/units
*
@@ -1824,6 +1880,8 @@ class Setup extends DolibarrApi
* @param int $active Lega form is active or not {@min 0} {@max 1}
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
* @return array List of legal form
* @phan-return array<Object|false>
* @phpstan-return array<Object|false>
*
* @url GET dictionary/legal_form
*
@@ -1886,6 +1944,8 @@ class Setup extends DolibarrApi
* @param int $active Staff is active or not {@min 0} {@max 1}
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
* @return array List of staff
* @phan-return array<Object|false>
* @phpstan-return array<Object|false>
*
* @url GET dictionary/staff
*
@@ -1945,6 +2005,8 @@ class Setup extends DolibarrApi
* @param int $active Social network is active or not {@min 0} {@max 1}
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
* @return array List of social networks
* @phan-return array<Object|false>
* @phpstan-return array<Object|false>
*
* @url GET dictionary/socialnetworks
*
@@ -2012,6 +2074,8 @@ class Setup extends DolibarrApi
* @param string $lang Code of the language the label of the category must be translated to
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
* @return array List of ticket categories
* @phan-return array<Object|false>
* @phpstan-return array<Object|false>
*
* @url GET dictionary/ticket_categories
*
@@ -2075,6 +2139,8 @@ class Setup extends DolibarrApi
* @param string $lang Code of the language the label of the severity must be translated to
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
* @return array List of ticket severities
* @phan-return array<Object|false>
* @phpstan-return array<Object|false>
*
* @url GET dictionary/ticket_severities
*
@@ -2138,6 +2204,8 @@ class Setup extends DolibarrApi
* @param string $lang Code of the language the label of the type must be translated to
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
* @return array List of ticket types
* @phan-return array<Object|false>
* @phpstan-return array<Object|false>
*
* @url GET dictionary/ticket_types
*
@@ -2202,6 +2270,8 @@ class Setup extends DolibarrApi
* @param string $lang Code of the language the label of the type must be translated to
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
* @return array List of incoterm types
* @phan-return array<Object|false>
* @phpstan-return array<Object|false>
*
* @url GET dictionary/incoterms
*
@@ -2258,7 +2328,9 @@ class Setup extends DolibarrApi
*
* @url GET /company
*
* @return array|mixed Mysoc object
* @return array Mysoc object
* @phan-return Societe My Company properties
* @phpstan-return Societe
*
* @throws RestException 403 Forbidden
*/
@@ -2312,6 +2384,8 @@ class Setup extends DolibarrApi
* Get the list of establishments.
*
* @return array List of establishments
* @phan-return array<Object|false>
* @phpstan-return array<Object|false>
*
* @url GET /establishments
*
@@ -2407,6 +2481,8 @@ class Setup extends DolibarrApi
*
* @param string $target Can be 'local' or 'default' or Url of the signatures file to use for the test. Must be reachable by the tested Dolibarr.
* @return array Result of file and setup integrity check
* @phan-return array{resultcode:string,resultcomment:string,expectedchecksum:string,currentchecksum:string,out:string}
* @phpstan-return array{resultcode:string,resultcomment:string,expectedchecksum:string,currentchecksum:string,out:string}
*
* @url GET checkintegrity
*
@@ -2729,7 +2805,9 @@ class Setup extends DolibarrApi
*
* @url GET /modules
*
* @return array|mixed Data without useless information
* @return array Data without useless information
* @phan-return array<string,string>
* @phpstan-return array<string,string>
*
* @throws RestException 403 Forbidden
*/