Skip to content

Commit

Permalink
Qual: Fix FunctionArray phan notices (#31754)
Browse files Browse the repository at this point in the history
* Qual: Fix FunctionArray phan notices

* Fix class name in typing of htdocs/modulebuilder/index.php

* Fix customreports phpdoc

* Adjust file type after completeFileArrayWithDatabaseInfo

* Further phpdoc typing improvements

* More phpdoc

* Improve typing with cast on position field

* Force phpstan version

* Add phpstan exception

* Fix array index type + adjust phan config comment
  • Loading branch information
mdeweerd authored Nov 11, 2024
1 parent 3448985 commit 9ec4618
Show file tree
Hide file tree
Showing 44 changed files with 616 additions and 738 deletions.
560 changes: 190 additions & 370 deletions build/phpstan/phpstan-baseline.neon

Large diffs are not rendered by default.

56 changes: 25 additions & 31 deletions dev/tools/phan/baseline.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dev/tools/phan/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@
'PhanCompatibleNegativeStringOffset', // return false positive
'PhanPluginConstantVariableBool', // a lot of false positive, in most cases, we want to keep the code as it is
// 'PhanPluginUnknownArrayPropertyType', // Helps find missing array keys or mismatches, remaining occurrences are likely unused properties
'PhanTypeArraySuspiciousNullable', // Was All fixed, but a lot of occurrences again because of properties made nullable for phpstan.
'PhanTypeArraySuspiciousNullable', // About 440 occurrences
// 'PhanTypeInvalidDimOffset', // Helps identify missing array indexes in types or reference to unset indexes
'PhanTypeObjectUnsetDeclaredProperty',
'PhanTypePossiblyInvalidDimOffset', // a lot of false positive, in most cases, we want to keep the code as it is
Expand Down
4 changes: 2 additions & 2 deletions htdocs/accountancy/class/accountancycategory.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ public function getCatsCpts($catid = 0)
*
* @param int $categorytype -1=All, 0=Only non computed groups, 1=Only computed groups
* @param int $active 1= active, 0=not active
* @return array<array{rowid:string,code:string,label:string,formula:string,position:string,category_type:string,sens:string,bc:string}>|int Array of groups or -1 if error
* @return never|array<array{rowid:string,code:string,label:string,formula:string,position:string,category_type:string,sens:string,bc:string}>|int Array of groups or -1 if error
* @see getCatsCpts(), getCptsCat()
*/
public function getCats($categorytype = -1, $active = 1)
Expand Down Expand Up @@ -839,7 +839,7 @@ public function getCats($categorytype = -1, $active = 1)
* @param string $predefinedgroupwhere Sql criteria filter to select accounting accounts. This value must be sanitized and not come from an input of a user.
* Example: "pcg_type = 'EXPENSE' AND fk_pcg_version = 'xx'"
* Example: "fk_accounting_category = 99"
* @return array<array{id:int,account_number:string,account_label:string}>|int<-1,-1> Array of accounting accounts or -1 if error
* @return never|array<array{id:int,account_number:string,account_label:string}>|int<-1,-1> Array of accounting accounts or -1 if error
* @see getCats(), getCatsCpts()
*/
public function getCptsCat($cat_id, $predefinedgroupwhere = '')
Expand Down
4 changes: 3 additions & 1 deletion htdocs/admin/system/filecheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@

// Fill file_list with files in signature, new files, modified files
$ret = getFilesUpdated($file_list, $xml->dolibarr_htdocs_dir[0], '', DOL_DOCUMENT_ROOT, $checksumconcat); // Fill array $file_list
'@phan-var-force array{insignature:string[],missing?:array<array{filename:string,expectedmd5:string,expectedsize:string}>,updated:array<array{filename:string,expectedmd5:string,expectedsize:string,md5:string}>} $file_list';
// Complete with list of new files
foreach ($scanfiles as $keyfile => $valfile) {
$tmprelativefilename = preg_replace('/^'.preg_quote(DOL_DOCUMENT_ROOT, '/').'/', '', $valfile['fullname']);
Expand Down Expand Up @@ -392,7 +393,7 @@
$out .= ' '.$form->textwithpicto('', $htmltext, 1, 'help', '', 0, 2, 'helprm'.$i);
}
$out .= '</td>'."\n";
$out .= '<td class="center">'.dol_escape_htmltag($file['expectedmd5']).'</td>'."\n";
$out .= '<td class="center">'.dol_escape_htmltag($file['expectedmd5']).'</td>'."\n"; // @phan-suppress-current-line PhanTypeInvalidDimOffset
$out .= '<td class="center">'.dol_escape_htmltag($file['md5']).'</td>'."\n";
$size = dol_filesize(DOL_DOCUMENT_ROOT.'/'.$file['filename']);
$totalsize += $size;
Expand Down Expand Up @@ -427,6 +428,7 @@
{
$file_list = array();
$ret = getFilesUpdated($file_list, $xml->dolibarr_htdocs_dir[0], '', ???, $checksumconcat); // Fill array $file_list
'@phan-var-force array{insignature:string[],missing?:array<array{filename:string,expectedmd5:string,expectedsize:string}>,updated:array<array{filename:string,expectedmd5:string,expectedsize:string,md5:string}>} $file_list';
}*/


Expand Down
5 changes: 3 additions & 2 deletions htdocs/api/class/api_setup.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2551,6 +2551,7 @@ public function getCheckIntegrity($target)

// Fill file_list with files in signature, new files, modified files
$ret = getFilesUpdated($file_list, $xml->dolibarr_htdocs_dir[0], '', DOL_DOCUMENT_ROOT, $checksumconcat); // Fill array $file_list
'@phan-var-force array{insignature:string[],missing?:array<array{filename:string,expectedmd5:string,expectedsize:string}>,updated:array<array{filename:string,expectedmd5:string,expectedsize:string,md5:string}>} $file_list';
// Complete with list of new files
foreach ($scanfiles as $keyfile => $valfile) {
$tmprelativefilename = preg_replace('/^'.preg_quote(DOL_DOCUMENT_ROOT, '/').'/', '', $valfile['fullname']);
Expand Down Expand Up @@ -2578,7 +2579,7 @@ public function getCheckIntegrity($target)
$out .= '<tr class="oddeven">';
$out .= '<td>'.$i.'</td>'."\n";
$out .= '<td>'.dol_escape_htmltag($file['filename']).'</td>'."\n";
$out .= '<td class="center">'.$file['expectedmd5'].'</td>'."\n";
$out .= '<td class="center">'.(array_key_exists('expectedmd5', $file) ? $file['expectedmd5'] : '').'</td>'."\n";
$out .= "</tr>\n";
}
} else {
Expand Down Expand Up @@ -2657,7 +2658,7 @@ public function getCheckIntegrity($target)
$out .= '<tr class="oddeven">';
$out .= '<td>'.$i.'</td>'."\n";
$out .= '<td>'.dol_escape_htmltag($file['filename']).'</td>'."\n";
$out .= '<td class="center">'.$file['expectedmd5'].'</td>'."\n";
$out .= '<td class="center">'.$file['expectedmd5'].'</td>'."\n"; // @phan-suppress-current-line PhanTypeInvalidDimOffset,PhanTypeSuspiciousStringExpression
$out .= '<td class="center">'.$file['md5'].'</td>'."\n";
$size = dol_filesize(DOL_DOCUMENT_ROOT.'/'.$file['filename']);
$totalsize += $size;
Expand Down
15 changes: 14 additions & 1 deletion htdocs/asset/tpl/depreciation_options_edit.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* Copyright (C) 2021 Open-Dsi <[email protected]>
* Copyright (C) 2024 Frédéric France <[email protected]>
* Copyright (C) 2024 José <[email protected]>
* Copyright (C) 2024 MDW <[email protected]>
*
* 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
Expand Down Expand Up @@ -31,7 +32,19 @@
* @var DoliDB $db
* @var Form $form
* @var HookManager $hookmanager
* @var AssetDepreciationOptions $assetdepreciationoptions
* @var Translate $langs
* @var ?array<array{mode_key:string,field_key:string,value:string,target:string}> $enabled_field_info
*/
'
@phan-var-force Conf $conf
@phan-var-force DoliDB $db
@phan-var-force ?Form $form
@phan-var-force HookManager $hookmanager
@phan-var-force AssetDepreciationOptions $assetdepreciationoptions
@phan-var-force Translate $langs
@phan-var-force ?array<array{mode_key:string,field_key:string,value:string,target:string}> $enabled_field_info
';

// Protection to avoid direct call of template
if (empty($object) || !is_object($object)) {
Expand Down Expand Up @@ -84,7 +97,7 @@

$assetdepreciationoptions->setInfosForMode($mode_key, $class_type, true);
$prefix_html_name = $mode_key . '_';
$width = ($mode_key == "economic")? "width50p pull-left" : "width50p";
$width = ($mode_key == "economic") ? "width50p pull-left" : "width50p";
print '<table class="border '. $width .'" id="block_' . $mode_key . '">' . "\n";
print '<tr><td class="info-box-title">'.$langs->trans($mode_info['label']).'</td></tr>';
if ($mode_key == "economic") {
Expand Down
8 changes: 7 additions & 1 deletion htdocs/asset/tpl/depreciation_options_view.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@
/**
* @var Form $form
* @var HookManager $hookmanager
* @var AssetDepreciationOptions $assetdepreciationoptions
*/
'
@phan-var-force ?Form $form
@phan-var-force HookManager $hookmanager
@phan-var-force AssetDepreciationOptions $assetdepreciationoptions
';

// Protection to avoid direct call of template
if (empty($object) || !is_object($object)) {
Expand Down Expand Up @@ -103,7 +109,7 @@
if (!empty($field_info['help'])) {
print $form->textwithpicto($langs->trans($field_info['label']), $langs->trans($field_info['help']));
} else {
if (isset($field_info['copytoclipboard']) && $field_info['copytoclipboard'] == 1) {
if (isset($field_info['copytoclipboard']) && $field_info['copytoclipboard'] == 1) { // @phan-suppress-current-line PhanTypeInvalidDimOffset
print showValueWithClipboardCPButton($value, 0, $langs->transnoentitiesnoconv($field_info['label']));
} else {
print $langs->trans($field_info['label']);
Expand Down
2 changes: 1 addition & 1 deletion htdocs/asset/tpl/depreciation_view.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
if (!empty($field_info['help'])) {
print $form->textwithpicto($langs->trans($field_info['label']), $langs->trans($field_info['help']));
} else {
if (isset($field_info['copytoclipboard']) && $field_info['copytoclipboard'] == 1) {
if (isset($field_info['copytoclipboard']) && $field_info['copytoclipboard'] == 1) { // @phan-suppress-current-line PhanTypeInvalidDimOffset
print showValueWithClipboardCPButton($value, 0, $langs->transnoentitiesnoconv($field_info['label']));
} else {
print $langs->trans($field_info['label']);
Expand Down
5 changes: 3 additions & 2 deletions htdocs/categories/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Copyright (C) 2005-2012 Regis Houssin <[email protected]>
* Copyright (C) 2007 Patrick Raguin <[email protected]>
* Copyright (C) 2020-2024 Frédéric France <[email protected]>
* Copyright (C) 2024 MDW <[email protected]>
*
* 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
Expand Down Expand Up @@ -77,7 +78,7 @@

$type = $object->type;
if (is_numeric($type)) {
$type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
$type = Categorie::$MAP_ID_TO_CODE[(int) $type]; // For backward compatibility
}

$extrafields = new ExtraFields($db);
Expand All @@ -89,7 +90,7 @@
/*
* Actions
*/
$parameters = array('id' => $id, 'ref' => $ref, 'cancel'=> $cancel, 'backtopage' => $backtopage, 'socid' => $socid, 'label' => $label, 'description' => $description, 'color' => $color, 'position' => $position, 'visible' => $visible, 'parent' => $parent);
$parameters = array('id' => $id, 'ref' => $ref, 'cancel' => $cancel, 'backtopage' => $backtopage, 'socid' => $socid, 'label' => $label, 'description' => $description, 'color' => $color, 'position' => $position, 'visible' => $visible, 'parent' => $parent);
// Note that $action and $object may be modified by some hooks
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
if ($reshook < 0) {
Expand Down
2 changes: 1 addition & 1 deletion htdocs/categories/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

$categstatic = new Categorie($db);
if (is_numeric($type)) {
$type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
$type = Categorie::$MAP_ID_TO_CODE[(int) $type]; // For backward compatibility
}

// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array array
Expand Down
3 changes: 2 additions & 1 deletion htdocs/categories/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright (C) 2005-2009 Regis Houssin <[email protected]>
* Copyright (C) 2017 Ferran Marcet <[email protected]>
* Copyright (C) 2024 Frédéric France <[email protected]>
* Copyright (C) 2024 MDW <[email protected]>
*
* 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
Expand Down Expand Up @@ -64,7 +65,7 @@

$type = $object->type;
if (is_numeric($type)) {
$type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
$type = Categorie::$MAP_ID_TO_CODE[(int) $type]; // For backward compatibility
}

/*
Expand Down
2 changes: 1 addition & 1 deletion htdocs/categories/photos.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@

$type = $object->type;
if (is_numeric($type)) {
$type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
$type = Categorie::$MAP_ID_TO_CODE[(int) $type]; // For backward compatibility
}

$upload_dir = $conf->categorie->multidir_output[$object->entity];
Expand Down
3 changes: 2 additions & 1 deletion htdocs/categories/traduction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Copyright (C) 2010-2016 Destailleur Laurent <[email protected]>
* Copyright (C) 2015 Raphaël Doursenaud <[email protected]>
* Copyright (C) 2024 Frédéric France <[email protected]>
* Copyright (C) 2024 MDW <[email protected]>
*
* 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
Expand Down Expand Up @@ -65,7 +66,7 @@

$type = $object->type;
if (is_numeric($type)) {
$type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
$type = Categorie::$MAP_ID_TO_CODE[(int) $type]; // For backward compatibility
}

// Security check
Expand Down
2 changes: 1 addition & 1 deletion htdocs/categories/viewcat.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@

$type = $object->type;
if (is_numeric($type)) {
$type = Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility
$type = Categorie::$MAP_ID_TO_CODE[(int) $type]; // For backward compatibility
}

$extrafields = new ExtraFields($db);
Expand Down
4 changes: 2 additions & 2 deletions htdocs/comm/action/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -1826,13 +1826,13 @@
* @param int $year Year
* @param int $monthshown Current month shown in calendar view
* @param string $style Style to use for this day
* @param array $eventarray Array of events
* @param array<int,ActionComm[]> $eventarray Array of events
* @param int $maxprint Nb of actions to show each day on month view (0 means no limit)
* @param int $maxnbofchar Nb of characters to show for event line
* @param string $newparam Parameters on current URL
* @param int $showinfo Add extended information (used by day and week view)
* @param int $minheight Minimum height for each event. 60px by default.
* @param int $nonew 0=Add "new entry button", 1=No "new entry button", -1=Only "new entry button"
* @param int<-1,1> $nonew 0=Add "new entry button", 1=No "new entry button", -1=Only "new entry button"
* @param array{}|array{0:array{0:int,1:int,2:int},1:array{0:int,1:int,2:int},2:array{0:int,1:int,2:int}} $bookcalcalendarsarray Used for Bookcal module array of calendar of bookcal
* @return void
*/
Expand Down
14 changes: 7 additions & 7 deletions htdocs/comm/action/pertype.php
Original file line number Diff line number Diff line change
Expand Up @@ -834,9 +834,9 @@
$sql = "SELECT code, color, libelle as label FROM ".MAIN_DB_PREFIX."c_actioncomm ORDER BY position";
$resql = $db->query($sql);
while ($obj = $db->fetch_object($resql)) {
$typeofevents[$obj->code] = $obj->code;
$colorsbytype[$obj->code] = $obj->color;
$labelbytype[$obj->code] = $obj->label;
$typeofevents[(string) $obj->code] = (string) $obj->code;
$colorsbytype[(string) $obj->code] = (string) $obj->color;
$labelbytype[(string) $obj->code] = (string) $obj->label;
}

// Loop on each user to show calendar
Expand Down Expand Up @@ -961,20 +961,20 @@
/**
* Show event line of a particular day for a user
*
* @param User $username Login
* @param string $username Login
* @param int $day Day
* @param int $month Month
* @param int $year Year
* @param int $monthshown Current month shown in calendar view
* @param string $style Style to use for this day
* @param array $eventarray Array of events
* @param array<int,ActionComm[]> $eventarray Array of events
* @param int $maxprint Nb of actions to show each day on month view (0 means no limit)
* @param int $maxnbofchar Nb of characters to show for event line
* @param string $newparam Parameters on current URL
* @param int $showinfo Add extended information (used by day view)
* @param int $minheight Minimum height for each event. 60px by default.
* @param boolean $showheader Show header
* @param array $colorsbytype Array with colors by type
* @param bool $showheader Show header
* @param array<string,string> $colorsbytype Array with colors by type
* @param bool $var true or false for alternat style on tr/td
* @return void
*/
Expand Down
4 changes: 2 additions & 2 deletions htdocs/comm/action/peruser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1146,14 +1146,14 @@
* @param int $year Year
* @param int $monthshown Current month shown in calendar view
* @param string $style Style to use for this day
* @param array $eventarray Array of events
* @param array<int,ActionComm[]> $eventarray Array of events
* @param int $maxprint Nb of actions to show each day on month view (0 means no limit)
* @param int $maxnbofchar Nb of characters to show for event line
* @param string $newparam Parameters on current URL
* @param int $showinfo Add extended information (used by day view)
* @param int $minheight Minimum height for each event. 60px by default.
* @param boolean $showheader Show header
* @param array $colorsbytype Array with colors by type
* @param array<string,string> $colorsbytype Array with colors by type
* @param bool $var true or false for alternat style on tr/td
* @return void
*/
Expand Down
Loading

0 comments on commit 9ec4618

Please sign in to comment.