Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qual: Fix phan notices (workstation) #33280

Merged
merged 1 commit into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions dev/tools/phan/baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -676,10 +676,8 @@ return [
'htdocs/website/index.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'],
'htdocs/website/samples/wrapper.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal'],
'htdocs/website/websiteaccount_card.php' => ['PhanUndeclaredProperty'],
'htdocs/workstation/class/api_workstations.class.php' => ['PhanPluginUnknownArrayMethodReturnType'],
'htdocs/workstation/class/workstation.class.php' => ['PhanUndeclaredProperty'],
'htdocs/workstation/workstation_card.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal', 'PhanUndeclaredProperty'],
'htdocs/workstation/workstation_list.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal'],
'htdocs/workstation/workstation_card.php' => ['PhanUndeclaredProperty'],
'htdocs/zapier/class/api_zapier.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType'],
'htdocs/zapier/class/hook.class.php' => ['PhanUndeclaredProperty'],
'internal' => ['PhanUndeclaredConstant'],
Expand Down
2 changes: 1 addition & 1 deletion htdocs/bom/tpl/objectline_view.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
* @var string $action
*/
'
@phan-var-force CommonObjectLine $line
@phan-var-force BOMLine $line
@phan-var-force int $num
@phan-var-force int $i
@phan-var-force CommonObject $this
Expand Down
2 changes: 1 addition & 1 deletion htdocs/resource/class/html.formresource.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function __construct($db)
/**
* Output html form to select a resource
*
* @param int $selected Preselected resource id
* @param int|int[] $selected Preselected resource id
* @param string $htmlname Name of field in form
* @param string $filter Optional filters criteria (example: 's.rowid <> x')
* @param int<0,1> $showempty Add an empty field
Expand Down
8 changes: 5 additions & 3 deletions htdocs/workstation/class/api_workstations.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2019 Cedric Ancelin <icedo.anc@gmail.com>
* Copyright (C) 2024 Christian Humpel <christian.humpel@gmail.com>
* 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
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -38,7 +38,7 @@
class Workstations extends DolibarrApi
{
/**
* @var Workstation $workstation {@type Workstation}
* @var Workstation {@type Workstation}
*/
public $workstation;

Expand Down Expand Up @@ -104,6 +104,8 @@ public function getByRef($ref)
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.tobuy:=:0) and (t.tosell:=:1)"
* @param string $properties Restrict the data returned to these properties. Ignored if empty. Comma separated list of properties names
* @return array Array of workstation objects
* @phan-return Workstation[]|array{data:Workstation[],pagination:array{total:int,page:int,pagecount:int,limit:int}}
* @phpstan-return Workstation[]|array{data:Workstation[],pagination:array{total:int,page:int,pagecount:int,limit:int}}
*/
public function index($sortfield = "t.ref", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '', $properties = '')
{
Expand Down Expand Up @@ -171,7 +173,7 @@ public function index($sortfield = "t.ref", $sortorder = 'ASC', $limit = 100, $p
$obj_ret['pagination'] = array(
'total' => (int) $total,
'page' => $page, //count starts from 0
'page_count' => ceil((int) $total / $limit),
'page_count' => (int) ceil((int) $total / $limit),
'limit' => $limit
);
}
Expand Down
8 changes: 4 additions & 4 deletions htdocs/workstation/workstation_card.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,15 @@
print '</td>';
print '<td>';
print img_picto('', 'group');
print $form->select_dolgroups($groups, 'groups', 1, '', 0, '', '', $object->entity, true, 'quatrevingtpercent widthcentpercentminusx');
print $form->select_dolgroups($groups, 'groups', 1, '', 0, '', array(), (string) $object->entity, true, 'quatrevingtpercent widthcentpercentminusx');
print '</td></tr>';

print '<tr id="wsresources"><td>';
print $langs->trans('Machines');
print '</td>';
print '<td>';
print img_picto('', 'resource');
print $formresource->select_resource_list($resources, 'resources', [], '', 0, '', '', $object->entity, true, 0, 'quatrevingtpercent widthcentpercentminusx', true);
print $formresource->select_resource_list($resources, 'resources', '', 0, 0, 0, array(), (string) $object->entity, 1, 0, 'quatrevingtpercent widthcentpercentminusx', true);
print '</td></tr>';

// Other attributes
Expand Down Expand Up @@ -293,15 +293,15 @@
print '</td>';
print '<td>';
print img_picto('', 'group');
print $form->select_dolgroups(empty($groups) ? $object->usergroups : $groups, 'groups', 1, '', 0, '', '', $object->entity, true, 'quatrevingtpercent widthcentpercentminusx');
print $form->select_dolgroups(empty($groups) ? $object->usergroups : $groups, 'groups', 1, '', 0, '', array(), (string) $object->entity, true, 'quatrevingtpercent widthcentpercentminusx');
print '</td></tr>';

print '<tr id="wsresources"><td>';
print $langs->trans('Machines');
print '</td>';
print '<td>';
print img_picto('', 'resource');
print $formresource->select_resource_list(empty($resources) ? $object->resources : $resources, 'resources', [], '', 0, '', '', $object->entity, true, 0, 'quatrevingtpercent widthcentpercentminusx', true);
print $formresource->select_resource_list(empty($resources) ? $object->resources : $resources, 'resources', '', 0, 0, 0, array(), (string) $object->entity, 1, 0, 'quatrevingtpercent widthcentpercentminusx', true);
print '</td></tr>';

// Other attributes
Expand Down
25 changes: 12 additions & 13 deletions htdocs/workstation/workstation_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2020 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024-2025 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
Expand Down Expand Up @@ -127,8 +127,8 @@
$visible = (int) dol_eval((string) $val['visible'], 1);
$arrayfields['t.'.$key] = array(
'label' => $val['label'],
'checked' => (($visible < 0) ? 0 : 1),
'enabled' => (abs($visible) != 3 && (bool) dol_eval($val['enabled'], 1)),
'checked' => (($visible < 0) ? '0' : '1'),
'enabled' => (string) (int) (abs($visible) != 3 && (bool) dol_eval($val['enabled'], 1)),
'position' => $val['position'],
'help' => isset($val['help']) ? $val['help'] : ''
);
Expand All @@ -137,8 +137,8 @@

$arrayfields['wug.fk_usergroup'] = array(
'label' => $langs->trans('UserGroups'),
'checked' => (($visible < 0) ? 0 : 1),
'enabled' => (abs($visible) != 3 && (bool) dol_eval($val['enabled'], 1)),
'checked' => (($visible < 0) ? '0' : '1'),
'enabled' => (string) (int) (abs($visible) != 3 && (bool) dol_eval($val['enabled'], 1)),
'position' => 1000,
'help' => empty($val['help']) ? '' : $val['help'],
'csslist' => 'minwidth100'
Expand All @@ -147,8 +147,8 @@
/* disabled because adding resources to workstation seems not yet available in GUI
$arrayfields['wr.fk_resource'] = array(
'label'=>$langs->trans('Resources'),
'checked'=>(($visible < 0) ? 0 : 1),
'enabled'=>(abs($visible) != 3 && (bool) dol_eval($val['enabled'], 1)),
'checked'=>(($visible < 0) ? '0' : '1'),
'enabled'=>(string)(int)(abs($visible) != 3 && (bool) dol_eval($val['enabled'], 1)),
'position'=>1001,
'help' => empty($val['help']) ? '' : $val['help']
);
Expand All @@ -159,7 +159,6 @@

$object->fields = dol_sort_array($object->fields, 'position');
$arrayfields = dol_sort_array($arrayfields, 'position');
'@phan-var-force array<string,array{label:string,checked?:int<0,1>,position?:int,help?:string}> $arrayfields'; // dol_sort_array looses type for Phan

// Permissions
$permissiontoread = $user->hasRight('workstation', 'workstation', 'read');
Expand Down Expand Up @@ -553,7 +552,7 @@
} elseif ($key == 'lang') {
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
$formadmin = new FormAdmin($db);
print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth100imp maxwidth125', 2);
print $formadmin->select_language($search[$key], 'search_lang', 0, array(), 1, 0, 0, 'minwidth100imp maxwidth125', 2);
} else {
print '<input type="text" class="flat maxwidth'.($val['type'] == 'integer' ? '50' : '75').'" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
}
Expand All @@ -564,14 +563,14 @@
// usergroups
if (!empty($arrayfields['wug.fk_usergroup']['checked'])) {
print '<td class="liste_titre minwidth100">';
print $form->select_dolgroups($groups, 'groups', 1, '', 0, '', '', $conf->entity, true);
print $form->select_dolgroups($groups, 'groups', 1, '', 0, '', array(), (string) $conf->entity, true);
print '</td>';
}

// resources
if (!empty($arrayfields['wr.fk_resource']['checked'])) {
print '<td class="liste_titre">';
print $formresource->select_resource_list($resources, 'resources', [], '', 0, '', '', $conf->entity, true, 0, '', true);
print $formresource->select_resource_list($resources, 'resources', '', 0, 0, 0, array(), (string) $conf->entity, 1, 0, '', true);
print '</td>';
}

Expand Down Expand Up @@ -734,13 +733,13 @@
if (!empty($arrayfields['t.'.$key]['checked'])) {
print '<td'.($cssforfield ? ' class="'.$cssforfield.(preg_match('/tdoverflow/', $cssforfield) ? ' classfortooltip' : '').'"' : '');
if (preg_match('/tdoverflow/', $cssforfield) && !in_array($val['type'], array('ip', 'url')) && !is_numeric($object->$key)) {
print ' title="'.dol_escape_htmltag($object->$key).'"';
print ' title="'.dol_escape_htmltag((string) $object->$key).'"';
}
print '>';
if ($key == 'status') {
print $object->getLibStatut(5);
} elseif ($key == 'rowid') {
print $object->showOutputField($val, $key, $object->id, '');
print $object->showOutputField($val, $key, (string) $object->id, '');
} else {
print $object->showOutputField($val, $key, $object->$key, '');
}
Expand Down