Skip to content

Commit

Permalink
Qual: Fix phan notices (recruitment)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdeweerd committed Feb 13, 2025
1 parent 09e1708 commit 7b9e4cb
Show file tree
Hide file tree
Showing 17 changed files with 125 additions and 131 deletions.
32 changes: 12 additions & 20 deletions dev/tools/phan/baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
*/
return [
// # Issue statistics:
// PhanTypeMismatchArgument : 1760+ occurrences
// PhanTypeMismatchArgument : 1740+ occurrences
// PhanUndeclaredProperty : 500+ occurrences
// PhanTypeMismatchArgumentNullable : 360+ occurrences
// PhanTypeMismatchArgumentNullable : 350+ occurrences
// PhanPluginUnknownArrayMethodReturnType : 170+ occurrences
// PhanUndeclaredGlobalVariable : 170+ occurrences
// PhanUndeclaredGlobalVariable : 160+ occurrences
// PhanTypeMismatchProperty : 120+ occurrences
// PhanPluginUnknownArrayMethodParamType : 110+ occurrences
// PhanTypeMismatchArgumentProbablyReal : 75+ occurrences
Expand All @@ -27,15 +27,13 @@ return [
// PhanUndeclaredMethod : 10+ occurrences
// PhanTypeComparisonFromArray : 8 occurrences
// PhanPluginDuplicateExpressionBinaryOp : 6 occurrences
// PhanPluginUnknownObjectMethodCall : 6 occurrences
// PhanTypeArraySuspiciousNull : 6 occurrences
// PhanParamTooMany : 5 occurrences
// PhanPluginDuplicateArrayKey : 4 occurrences
// PhanPluginSuspiciousParamPosition : 4 occurrences
// PhanEmptyFQSENInClasslike : 3 occurrences
// PhanInvalidFQSENInClasslike : 3 occurrences
// PhanPluginBothLiteralsBinaryOp : 3 occurrences
// PhanEmptyForeach : 2 occurrences
// PhanPluginEmptyStatementIf : 2 occurrences
// PhanRedefineFunction : 2 occurrences
// PhanTypeMismatchDimAssignment : 2 occurrences
Expand Down Expand Up @@ -627,23 +625,17 @@ return [
'htdocs/reception/class/api_receptions.class.php' => ['PhanTypeMismatchArgumentNullable'],
'htdocs/reception/class/reception.class.php' => ['PhanUndeclaredProperty'],
'htdocs/reception/list.php' => ['PhanUndeclaredProperty'],
'htdocs/recruitment/admin/setup.php' => ['PhanEmptyForeach'],
'htdocs/recruitment/admin/setup_candidatures.php' => ['PhanEmptyForeach'],
'htdocs/recruitment/class/api_recruitments.class.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'],
'htdocs/recruitment/class/recruitmentcandidature.class.php' => ['PhanUndeclaredProperty'],
'htdocs/recruitment/class/recruitmentjobposition.class.php' => ['PhanUndeclaredProperty'],
'htdocs/recruitment/core/modules/recruitment/doc/pdf_standard_recruitmentjobposition.modules.php' => ['PhanTypeMismatchArgumentNullable', 'PhanUndeclaredProperty'],
'htdocs/recruitment/core/modules/recruitment/mod_recruitmentcandidature_advanced.php' => ['PhanTypeMismatchArgument', 'PhanUndeclaredProperty'],
'htdocs/recruitment/core/modules/recruitment/mod_recruitmentjobposition_advanced.php' => ['PhanTypeMismatchArgument', 'PhanUndeclaredProperty'],
'htdocs/recruitment/index.php' => ['PhanUndeclaredGlobalVariable'],
'htdocs/recruitment/recruitmentcandidature_card.php' => ['PhanTypeMismatchArgumentProbablyReal', 'PhanUndeclaredProperty'],
'htdocs/recruitment/recruitmentcandidature_list.php' => ['PhanPluginUnknownObjectMethodCall', 'PhanTypeMismatchArgument', 'PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'],
'htdocs/recruitment/recruitmentjobposition_agenda.php' => ['PhanPluginUnknownObjectMethodCall', 'PhanTypeMismatchArgument', 'PhanUndeclaredGlobalVariable'],
'htdocs/recruitment/recruitmentjobposition_applications.php' => ['PhanTypeMismatchArgument', 'PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'],
'htdocs/recruitment/recruitmentjobposition_card.php' => ['PhanTypeMismatchArgument', 'PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'],
'htdocs/recruitment/recruitmentjobposition_document.php' => ['PhanPluginUnknownObjectMethodCall', 'PhanTypeMismatchArgument', 'PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'],
'htdocs/recruitment/recruitmentjobposition_list.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal'],
'htdocs/recruitment/recruitmentjobposition_note.php' => ['PhanPluginUnknownObjectMethodCall', 'PhanTypeMismatchArgument', 'PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'],
'htdocs/recruitment/core/modules/recruitment/doc/pdf_standard_recruitmentjobposition.modules.php' => ['PhanUndeclaredProperty'],
'htdocs/recruitment/core/modules/recruitment/mod_recruitmentcandidature_advanced.php' => ['PhanUndeclaredProperty'],
'htdocs/recruitment/core/modules/recruitment/mod_recruitmentjobposition_advanced.php' => ['PhanUndeclaredProperty'],
'htdocs/recruitment/recruitmentcandidature_card.php' => ['PhanUndeclaredProperty'],
'htdocs/recruitment/recruitmentcandidature_list.php' => ['PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'],
'htdocs/recruitment/recruitmentjobposition_applications.php' => ['PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'],
'htdocs/recruitment/recruitmentjobposition_card.php' => ['PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'],
'htdocs/recruitment/recruitmentjobposition_document.php' => ['PhanUndeclaredProperty'],
'htdocs/recruitment/recruitmentjobposition_note.php' => ['PhanUndeclaredProperty'],
'htdocs/resource/card.php' => ['PhanTypeMismatchArgument'],
'htdocs/resource/class/dolresource.class.php' => ['PhanTypeMismatchArgumentNullable'],
'htdocs/resource/class/html.formresource.class.php' => ['PhanTypeMismatchArgument'],
Expand Down
7 changes: 6 additions & 1 deletion dev/tools/phan/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,17 @@
'actioncode' => 'string',
'badgeStatus0' => 'string',
'badgeStatus1' => 'string',
'badgeStatus11' => 'string',
'badgeStatus3' => 'string',
'badgeStatus4' => 'string',
'badgeStatus5' => 'string',
'badgeStatus6' => 'string',
'badgeStatus7' => 'string',
'badgeStatus8' => 'string',
'badgeStatus9' => 'string',
'badgeStatus10' => 'string',
'badgeStatus11' => 'string',
'badgeStatus4b' => 'string',
'badgeStatus8b' => 'string',
'classname' => 'string',
'conf' => '\Conf',
'conffile' => 'string',
Expand Down
2 changes: 1 addition & 1 deletion htdocs/recruitment/admin/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
print '<table class="noborder centpercent">';
print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';

foreach ($arrayofparameters as $key => $val) {
foreach ($arrayofparameters as $key => $val) { // @phan-suppress-current-line PhanEmptyForeach
print '<tr class="oddeven"><td>';
$tooltiphelp = (($langs->trans($key.'Tooltip') != $key.'Tooltip') ? $langs->trans($key.'Tooltip') : '');
print $form->textwithpicto($langs->trans($key), $tooltiphelp);
Expand Down
2 changes: 1 addition & 1 deletion htdocs/recruitment/admin/setup_candidatures.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
print '<table class="noborder centpercent">';
print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';

foreach ($arrayofparameters as $key => $val) {
foreach ($arrayofparameters as $key => $val) { // @phan-suppress-current-line PhanEmptyForeach
print '<tr class="oddeven"><td>';
$tooltiphelp = (($langs->trans($key.'Tooltip') != $key.'Tooltip') ? $langs->trans($key.'Tooltip') : '');
print $form->textwithpicto($langs->trans($key), $tooltiphelp);
Expand Down
46 changes: 24 additions & 22 deletions htdocs/recruitment/class/api_recruitments.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2022 Thibault FOUCART <[email protected]>
* Copyright (C) 2024 MDW <[email protected]>
* Copyright (C) 2024-2025 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 @@ -38,11 +38,11 @@
class Recruitments extends DolibarrApi
{
/**
* @var RecruitmentJobPosition $jobposition {@type RecruitmentJobPosition}
* @var RecruitmentJobPosition {@type RecruitmentJobPosition}
*/
public $jobposition;
/**
* @var RecruitmentCandidature $candidature {@type RecruitmentCandidature}
* @var RecruitmentCandidature {@type RecruitmentCandidature}
*/
public $candidature;

Expand All @@ -51,7 +51,6 @@ class Recruitments extends DolibarrApi
* Constructor
*
* @url GET /
*
*/
public function __construct()
{
Expand Down Expand Up @@ -357,9 +356,9 @@ public function indexCandidature($sortfield = "t.rowid", $sortorder = 'ASC', $li
/**
* Create jobposition object
*
* @param array $request_data Request datas
* @phan-param ?array<string,string> $request_data
* @phpstan-param ?array<string,string> $request_data
* @param array $request_data Request data
* @phan-param ?array<string,mixed> $request_data
* @phpstan-param ?array<string,mixed> $request_data
* @return int ID of jobposition
*
* @throws RestException
Expand Down Expand Up @@ -395,17 +394,17 @@ public function postJobPosition($request_data = null)
}

/**
* Create candidature object
*
* @param array $request_data Request datas
* Create candidature object
*
* @param array $request_data Request data
* @phan-param ?array<string,string> $request_data
* @phpstan-param ?array<string,string> $request_data
* @return int ID of candidature
*
* @throws RestException
*
* @url POST candidature/
*/
* @return int ID of candidature
*
* @throws RestException
*
* @url POST candidature/
*/
public function postCandidature($request_data = null)
{
if (!DolibarrApiAccess::$user->hasRight('recruitment', 'recruitmentjobposition', 'write')) {
Expand Down Expand Up @@ -438,9 +437,9 @@ public function postCandidature($request_data = null)
* Update jobposition
*
* @param int $id Id of jobposition to update
* @param array $request_data Datas
* @phan-param ?array<string,string> $request_data
* @phpstan-param ?array<string,string> $request_data
* @param array $request_data Data
* @phan-param ?array<string,mixed> $request_data
* @phpstan-param ?array<string,mixed> $request_data
* @return Object Object with cleaned properties
*
* @throws RestException
Expand Down Expand Up @@ -478,7 +477,7 @@ public function putJobPosition($id, $request_data = null)
// Clean data
// $this->jobposition->abc = sanitizeVal($this->jobposition->abc, 'alphanohtml');

if ($this->jobposition->update(DolibarrApiAccess::$user, false) > 0) {
if ($this->jobposition->update(DolibarrApiAccess::$user, 0) > 0) {
return $this->getJobPosition($id);
} else {
throw new RestException(500, $this->jobposition->error);
Expand Down Expand Up @@ -529,7 +528,7 @@ public function putCandidature($id, $request_data = null)
// Clean data
// $this->jobposition->abc = sanitizeVal($this->jobposition->abc, 'alphanohtml');

if ($this->candidature->update(DolibarrApiAccess::$user, false) > 0) {
if ($this->candidature->update(DolibarrApiAccess::$user, 0) > 0) {
return $this->getCandidature($id);
} else {
throw new RestException(500, $this->candidature->error);
Expand Down Expand Up @@ -680,13 +679,16 @@ protected function _cleanObjectDatas($object)
/**
* Validate fields before create or update object
*
* @param array<string,mixed> $data Array of data to validate
* @param ?array<string,mixed> $data Array of data to validate
* @return array<string,mixed>
*
* @throws RestException
*/
private function _validate($data)
{
if ($data === null) {
$data = array();
}
$jobposition = array();
foreach ($this->jobposition->fields as $field => $propfield) {
if (in_array($field, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat')) || $propfield['notnull'] != 1) {
Expand Down
38 changes: 19 additions & 19 deletions htdocs/recruitment/class/recruitmentjobposition.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -707,11 +707,11 @@ public function cancel($user, $notrigger = 0)
/**
* Close the recruitment
*
* @param User $user Object user that close
* @param int $status Statut
* @param string $note Complete private note with this note
* @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
* @return int Return integer <0 if KO, >0 if OK
* @param User $user Object user that close
* @param int $status Statut
* @param string $note Complete private note with this note
* @param int<0,1> $notrigger 1=Does not execute triggers, 0=Execute triggers
* @return int Return integer <0 if KO, >0 if OK
*/
public function cloture($user, $status, $note = "", $notrigger = 0)
{
Expand Down Expand Up @@ -792,9 +792,9 @@ public function cloture($user, $status, $note = "", $notrigger = 0)
/**
* Set back to validated status
*
* @param User $user Object user that modify
* @param int $notrigger 1=Does not execute triggers, 0=Execute triggers
* @return int Return integer <0 if KO, 0=Nothing done, >0 if OK
* @param User $user Object user that modify
* @param int<0,1> $notrigger 1=Does not execute triggers, 0=Execute triggers
* @return int Return integer <0 if KO, 0=Nothing done, >0 if OK
*/
public function reopen($user, $notrigger = 0)
{
Expand All @@ -816,12 +816,12 @@ public function reopen($user, $notrigger = 0)
/**
* Return a link to the object card (with optionally the picto)
*
* @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
* @param string $option On what the link point to ('nolink', ...)
* @param int $notooltip 1=Disable tooltip
* @param string $morecss Add more css on link
* @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
* @return string String with URL
* @param int<0,2> $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
* @param string $option On what the link point to ('nolink', ...)
* @param int<0,1> $notooltip 1=Disable tooltip
* @param string $morecss Add more css on link
* @param int<-1,1> $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
* @return string String with URL
*/
public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
{
Expand Down Expand Up @@ -924,8 +924,8 @@ public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss
/**
* Return label of the status
*
* @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
* @return string Label of status
* @param int<0,6> $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
* @return string Label of status
*/
public function getLibStatut($mode = 0)
{
Expand All @@ -936,8 +936,8 @@ public function getLibStatut($mode = 0)
/**
* Return the status
*
* @param int $status Id status
* @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
* @param int $status Id status
* @param int<0,6> $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
* @return string Label of status
*/
public function LibStatut($status, $mode = 0)
Expand Down Expand Up @@ -1015,7 +1015,7 @@ public function initAsSpecimen()
/**
* Create an array of lines
*
* @return array|int array of lines if OK, <0 if KO
* @return CommonObjectLine[]|int array of lines if OK, <0 if KO
*/
public function getLinesArray()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Copyright (C) 2015 Marcos García <[email protected]>
* Copyright (C) 2017 Ferran Marcet <[email protected]>
* Copyright (C) 2018-2024 Frédéric France <[email protected]>
* Copyright (C) 2024-2025 MDW <[email protected]>
* Copyright (C) 2024-2025 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 @@ -666,15 +666,15 @@ public static function liste_modeles($db, $maxfilenamelength = 0)
/**
* Show table for lines
*
* @param tcpdf $pdf Object PDF
* @param float|int $tab_top Top position of table
* @param float|int $tab_height Height of table (rectangle)
* @param int $nexY Y (not used)
* @param TCPDI|TCPDF $pdf Object PDF
* @param float $tab_top Top position of table
* @param float $tab_height Height of table (rectangle)
* @param float $nexY Y (not used)
* @param Translate $outputlangs Langs object
* @param int $hidetop 1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title
* @param int $hidebottom Hide bottom bar of array
* @param int<0,1> $hidetop 1=Hide top bar of array and title, 0=Hide nothing, -1=Hide only title
* @param int<0,1> $hidebottom Hide bottom bar of array
* @param string $currency Currency code
* @param Translate $outputlangsbis Langs object bis
* @param ?Translate $outputlangsbis Langs object bis
* @return void
*/
protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop = 0, $hidebottom = 0, $currency = '', $outputlangsbis = null)
Expand Down Expand Up @@ -718,12 +718,12 @@ protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $
/**
* Show top header of page.
*
* @param TCPDF $pdf Object PDF
* @param TCPDI|TCPDF $pdf Object PDF
* @param RecruitmentJobPosition $object Object to show
* @param int $showaddress 0=no, 1=yes
* @param int<0,1> $showaddress 0=no, 1=yes
* @param Translate $outputlangs Object lang for output
* @param Translate $outputlangsbis Object lang for output bis
* @return float|int Return topshift value
* @param ?Translate $outputlangsbis Object lang for output bis
* @return float Return topshift value
*/
protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $outputlangsbis = null)
{
Expand Down Expand Up @@ -960,10 +960,10 @@ protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $output
/**
* Show footer of page. Need this->emetteur object
*
* @param TCPDF $pdf PDF
* @param TCPDI|TCPDF $pdf PDF
* @param RecruitmentJobPosition $object Object to show
* @param Translate $outputlangs Object lang for output
* @param int $hidefreetext 1=Hide free text
* @param int<0,1> $hidefreetext 1=Hide free text
* @return int Return height of bottom margin including footer text
*/
protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
Expand All @@ -978,9 +978,9 @@ protected function _pagefoot(&$pdf, $object, $outputlangs, $hidefreetext = 0)
*
* @param object $object common object
* @param Translate $outputlangs langs
* @param int $hidedetails Do not show line details
* @param int $hidedesc Do not show desc
* @param int $hideref Do not show ref
* @param int<0,1> $hidedetails Do not show line details
* @param int<0,1> $hidedesc Do not show desc
* @param int<0,1> $hideref Do not show ref
* @return void
*/
public function defineColumnField($object, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
Expand Down
Loading

0 comments on commit 7b9e4cb

Please sign in to comment.