Skip to content

Commit

Permalink
Fix most PhanTypeMismatchDimAssignment notices (#28739)
Browse files Browse the repository at this point in the history
* Qual: Add typing to fix PhanTypeMismatchDimAssignment notice

* Fix: Initialise array for code in somme

* Qual: Update type hint for  argument in _Set_Format

* Qual: Update type hint for childtables

* Qual: Add typing to attributes

* Qual: Add typing for _msgContent

* Qual: Suppress PhanTypeMismatchDimAssignment

* Qual: Add typing for liste

* Qual: Add typing to fields

* Qual: Add typing hint for $objMod

* Qual: Modify assignment of array with bool keys for phan typing

Demonstration:
```
php -r '$a=[true=>"yes",false=>"no"];var_dump($a);'
# Result demonstrates bool keys are converted to int.
Command line code:1:
array(2) {
  [1] =>
  string(3) "yes"
  [0] =>
  string(2) "no"
}
```

* Qual: Add typing hint to indicate value is not null

* Force non-null type on $paramname

* Qual: Add typing hint to getCats()

* Update inc.php

---------

Co-authored-by: Laurent Destailleur <[email protected]>
  • Loading branch information
mdeweerd and eldy authored Mar 10, 2024
1 parent c95bab2 commit 37afba9
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 84 deletions.
2 changes: 1 addition & 1 deletion htdocs/accountancy/class/accountancycategory.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,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|int Array of groups or -1 if error
* @return array<array{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
2 changes: 1 addition & 1 deletion htdocs/accountancy/class/bookkeeping.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2464,7 +2464,7 @@ public function loadFiscalPeriods($force = false, $mode = 'active')
* Get list of fiscal period
*
* @param string $filter Filter
* @return array|int Return integer <0 if KO, Fiscal periods : [[id, date_start, date_end, label], ...]
* @return array<array{id:int,data_start:string,date_end:string,label:string}>|int Return integer <0 if KO, Fiscal periods : [[id, date_start, date_end, label], ...]
*/
public function getFiscalPeriods($filter = '')
{
Expand Down
42 changes: 22 additions & 20 deletions htdocs/admin/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
// if we set another view list mode, we keep it (till we change one more time)
if (GETPOSTISSET('mode')) {
$mode = GETPOST('mode', 'alpha');
if ($mode =='common' || $mode =='commonkanban') {
if ($mode == 'common' || $mode == 'commonkanban') {
dolibarr_set_const($db, "MAIN_MODULE_SETUP_ON_LIST_BY_DEFAULT", $mode, 'chaine', 0, '', $conf->entity);
}
} else {
Expand Down Expand Up @@ -78,18 +78,18 @@
}

$familyinfo = array(
'hr'=>array('position'=>'001', 'label'=>$langs->trans("ModuleFamilyHr")),
'crm'=>array('position'=>'006', 'label'=>$langs->trans("ModuleFamilyCrm")),
'srm'=>array('position'=>'007', 'label'=>$langs->trans("ModuleFamilySrm")),
'financial'=>array('position'=>'009', 'label'=>$langs->trans("ModuleFamilyFinancial")),
'products'=>array('position'=>'012', 'label'=>$langs->trans("ModuleFamilyProducts")),
'projects'=>array('position'=>'015', 'label'=>$langs->trans("ModuleFamilyProjects")),
'ecm'=>array('position'=>'018', 'label'=>$langs->trans("ModuleFamilyECM")),
'technic'=>array('position'=>'021', 'label'=>$langs->trans("ModuleFamilyTechnic")),
'portal'=>array('position'=>'040', 'label'=>$langs->trans("ModuleFamilyPortal")),
'interface'=>array('position'=>'050', 'label'=>$langs->trans("ModuleFamilyInterface")),
'base'=>array('position'=>'060', 'label'=>$langs->trans("ModuleFamilyBase")),
'other'=>array('position'=>'100', 'label'=>$langs->trans("ModuleFamilyOther")),
'hr' => array('position' => '001', 'label' => $langs->trans("ModuleFamilyHr")),
'crm' => array('position' => '006', 'label' => $langs->trans("ModuleFamilyCrm")),
'srm' => array('position' => '007', 'label' => $langs->trans("ModuleFamilySrm")),
'financial' => array('position' => '009', 'label' => $langs->trans("ModuleFamilyFinancial")),
'products' => array('position' => '012', 'label' => $langs->trans("ModuleFamilyProducts")),
'projects' => array('position' => '015', 'label' => $langs->trans("ModuleFamilyProjects")),
'ecm' => array('position' => '018', 'label' => $langs->trans("ModuleFamilyECM")),
'technic' => array('position' => '021', 'label' => $langs->trans("ModuleFamilyTechnic")),
'portal' => array('position' => '040', 'label' => $langs->trans("ModuleFamilyPortal")),
'interface' => array('position' => '050', 'label' => $langs->trans("ModuleFamilyInterface")),
'base' => array('position' => '060', 'label' => $langs->trans("ModuleFamilyBase")),
'other' => array('position' => '100', 'label' => $langs->trans("ModuleFamilyOther")),
);

$param = '';
Expand Down Expand Up @@ -360,7 +360,7 @@
// Search modules dirs
$modulesdir = dolGetModulesDirs();

$arrayofnatures = array('core'=>$langs->transnoentitiesnoconv("NativeModules"), 'external'=>$langs->transnoentitiesnoconv("External").' - ['.$langs->trans("AllPublishers").']');
$arrayofnatures = array('core' => $langs->transnoentitiesnoconv("NativeModules"), 'external' => $langs->transnoentitiesnoconv("External").' - ['.$langs->trans("AllPublishers").']');
$arrayofwarnings = array(); // Array of warning each module want to show when activated
$arrayofwarningsext = array(); // Array of warning each module want to show when we activate an external module
$filename = array();
Expand Down Expand Up @@ -395,6 +395,7 @@
$res = include_once $dir.$file; // A class already exists in a different file will send a non catchable fatal error.
if (class_exists($modName)) {
$objMod = new $modName($db);
'@phan-var-force DolibarrModules $objMod';
$modNameLoaded[$modName] = $dir;
if (!$objMod->numero > 0 && $modName != 'modUser') {
dol_syslog('The module descriptor '.$modName.' must have a numero property', LOG_ERR);
Expand Down Expand Up @@ -443,6 +444,7 @@
} else {
$familykey = $objMod->family;
}
'@phan-var-force string $familykey'; // if not, phan considers $familykey may be null

$moduleposition = ($objMod->module_position ? $objMod->module_position : '50');
if ($objMod->isCoreOrExternalModule() == 'external' && $moduleposition < 100000) {
Expand Down Expand Up @@ -603,10 +605,10 @@
$moreforfilter = '<div class="valignmiddle">';

$moreforfilter .= '<div class="floatright right pagination paddingtop --module-list"><ul><li>';
$moreforfilter .= dolGetButtonTitle($langs->trans('CheckForModuleUpdate'), $langs->trans('CheckForModuleUpdate').'<br>'.$langs->trans('CheckForModuleUpdateHelp'), 'fa fa-sync', $_SERVER["PHP_SELF"].'?action=checklastversion&token='.newToken().'&mode='.$mode.$param, '', 1, array('morecss'=>'reposition'));
$moreforfilter .= dolGetButtonTitle($langs->trans('CheckForModuleUpdate'), $langs->trans('CheckForModuleUpdate').'<br>'.$langs->trans('CheckForModuleUpdateHelp'), 'fa fa-sync', $_SERVER["PHP_SELF"].'?action=checklastversion&token='.newToken().'&mode='.$mode.$param, '', 1, array('morecss' => 'reposition'));
$moreforfilter .= dolGetButtonTitleSeparator();
$moreforfilter .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.$param, '', ($mode == 'common' ? 2 : 1), array('morecss'=>'reposition'));
$moreforfilter .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=commonkanban'.$param, '', ($mode == 'commonkanban' ? 2 : 1), array('morecss'=>'reposition'));
$moreforfilter .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.$param, '', ($mode == 'common' ? 2 : 1), array('morecss' => 'reposition'));
$moreforfilter .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=commonkanban'.$param, '', ($mode == 'commonkanban' ? 2 : 1), array('morecss' => 'reposition'));
$moreforfilter .= '</li></ul></div>';

$moreforfilter .= '<div class="divfilteralone colorbacktimesheet float valignmiddle">';
Expand All @@ -618,7 +620,7 @@
$moreforfilter .= '</div>';

if (getDolGlobalInt('MAIN_FEATURES_LEVEL')) {
$array_version = array('stable'=>$langs->transnoentitiesnoconv("Stable"));
$array_version = array('stable' => $langs->transnoentitiesnoconv("Stable"));
if (getDolGlobalInt('MAIN_FEATURES_LEVEL') < 0) {
$array_version['deprecated'] = $langs->trans("Deprecated");
}
Expand All @@ -632,7 +634,7 @@
$moreforfilter .= $form->selectarray('search_version', $array_version, $search_version, $langs->transnoentitiesnoconv('Version'), 0, 0, '', 0, 0, 0, '', 'maxwidth150', 1);
$moreforfilter .= '</div>';
}
$array_status = array('active'=>$langs->transnoentitiesnoconv("Enabled"), 'disabled'=>$langs->transnoentitiesnoconv("Disabled"));
$array_status = array('active' => $langs->transnoentitiesnoconv("Enabled"), 'disabled' => $langs->transnoentitiesnoconv("Disabled"));
$moreforfilter .= '<div class="divsearchfield paddingtop paddingbottom valignmiddle inline-block">';
$moreforfilter .= $form->selectarray('search_status', $array_status, $search_status, $langs->transnoentitiesnoconv('Status'), 0, 0, '', 0, 0, 0, '', 'maxwidth150', 1);
$moreforfilter .= '</div>';
Expand Down Expand Up @@ -717,7 +719,7 @@
|| ($moduledesc && preg_match('/'.preg_quote($search_keyword, '/').'/i', $moduledesc))
|| ($moduledesclong && preg_match('/'.preg_quote($search_keyword, '/').'/i', $moduledesclong))
|| ($moduleauthor && preg_match('/'.preg_quote($search_keyword, '/').'/i', $moduleauthor))
) {
) {
$qualified = 1;
}
if (!$qualified) {
Expand Down
10 changes: 8 additions & 2 deletions htdocs/compta/resultat/result.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@
//$calcmode.='<br>('.$langs->trans("SeeReportInDueDebtMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=CREANCES-DETTES">','</a>').')';
//$calcmode.='<br>('.$langs->trans("SeeReportInInputOutputMode",'<a href="'.$_SERVER["PHP_SELF"].'?year_start='.$year_start.'&modecompta=RECETTES-DEPENSES">','</a>').')';
$period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0);
$arraylist = array('no'=>$langs->trans("None"), 'yes'=>$langs->trans("AccountWithNonZeroValues"), 'all'=>$langs->trans("All"));
$arraylist = array('no' => $langs->trans("None"), 'yes' => $langs->trans("AccountWithNonZeroValues"), 'all' => $langs->trans("All"));
$period .= ' &nbsp; &nbsp; <span class="opacitymedium">'.$langs->trans("DetailBy").'</span> '.$form->selectarray('showaccountdetail', $arraylist, $showaccountdetail, 0);
$periodlink = $textprevyear.$textnextyear;
$exportlink = '';
Expand All @@ -240,7 +240,7 @@
$builddate = dol_now();
}

report_header($name, '', $period, $periodlink ?? '', $description, $builddate, $exportlink ?? '', array('modecompta'=>$modecompta, 'action' => ''), $calcmode);
report_header($name, '', $period, $periodlink ?? '', $description, $builddate, $exportlink ?? '', array('modecompta' => $modecompta, 'action' => ''), $calcmode);


if (isModEnabled('accounting') && $modecompta != 'BOOKKEEPING') {
Expand Down Expand Up @@ -356,6 +356,9 @@
print '<td class="liste_total right"><span class="amount">'.price($r).'</span></td>';
}

if (!isset($sommes[$code])) {
$sommes[$code] = array();
}
// Year N
$code = $cat['code']; // code of categorie ('VTE', 'MAR', ...)
if (empty($sommes[$code]['NP'])) {
Expand Down Expand Up @@ -438,6 +441,9 @@
foreach ($months as $k => $v) {
$totCat['M'][$k] = 0;
}
if (!isset($sommes[$code])) {
$sommes[$code] = array();
}

// Set $cpts with array of accounts in the category/group
$cpts = $AccCat->getCptsCat($cat['rowid']);
Expand Down
5 changes: 3 additions & 2 deletions htdocs/core/class/commonobject.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ abstract class CommonObject
*/
public $array_options = array();


/**
* @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
* @var array<string,array{type:string,label:string,enabled:int<0,2>,position:int,notnull:int,visible:int,noteditable?:int,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int,css?:string,help?:string,showoncombobox?:int,disabled?:int,arrayofkeyval?:array<int,string>,comment?:string}> Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
*/
public $fields = array();

Expand Down Expand Up @@ -775,7 +776,7 @@ abstract class CommonObject
public $extraparams = array();

/**
* @var array List of child tables. To test if we can delete object.
* @var array<string,string[]|array{parent:string,parentkey:string}> List of child tables. To test if we can delete object.
*/
protected $childtables = array();

Expand Down
2 changes: 1 addition & 1 deletion htdocs/core/class/commonstickergenerator.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ protected function _Get_Height_Chars($pt)
* protected Set format
*
* @param TCPDF $pdf PDF reference
* @param string $format Format
* @param array{metric:string,name:string,code:string,marginLeft:float,marginTip:float,SpaceX:float,SpaceY:float,NX:int,NY:int,width:float,height:float,font-size:float} $format Format
* @return void
*/
protected function _Set_Format(&$pdf, $format)
Expand Down
Loading

0 comments on commit 37afba9

Please sign in to comment.