Skip to content

Commit

Permalink
Qual: Fix phan notices in actions_massactions.inc
Browse files Browse the repository at this point in the history
# Qual: Fix phan notices in actions_massactions.inc

This fixes up the notices in htdocs/core/actions_massactions.inc.php

Separated from Dolibarr#30733.
  • Loading branch information
mdeweerd committed Aug 28, 2024
1 parent f7f4014 commit 83859bd
Showing 1 changed file with 48 additions and 6 deletions.
54 changes: 48 additions & 6 deletions htdocs/core/actions_massactions.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@
// $toselect may be defined
// $diroutputmassaction may be defined

'
@phan-var-force ?string $permissiontoread
@phan-var-force ?string $permissiontodelete
@phan-var-force ?string $permissiontoclose
@phan-var-force ?string $permissiontoapprove
@phan-var-force ?int[] $toselect
@phan-var-force ?string $diroutputmassaction
@phan-var-force ?string $objectlabel
@phan-var-force ?string $option
@phan-var-force ?string $deliveryreceipt
';


// Protection
if (empty($objectclass) || empty($uploaddir)) {
Expand All @@ -47,6 +59,14 @@
}
$error = 0;

// Note: list of strings for objectclass could be extended to accepted/expected classes
'
@phan-var-force "CommonObject"|"CommandeFournisseur"|"ConferenceOrBoothAttendee"|"Contrat"|"Contact"|"Expedition"|"ExpenseReport"|"Facture"|"FactureFournisseur"|"Fichinter"|"Holiday"|"Partnership"|"Project"|"Propal"|"Societe"|"SupplierProposal" $objectclass
@phan-var-force string $massaction
@phan-var-force string $uploaddir
';


// For backward compatibility
if (!empty($permtoread) && empty($permissiontoread)) {
$permissiontoread = $permtoread;
Expand Down Expand Up @@ -88,6 +108,7 @@
$contactidtosend = array();
$attachedfilesThirdpartyObj = array();
$oneemailperrecipient = (GETPOSTINT('oneemailperrecipient') ? 1 : 0);
$thirdparty = null;

if (!$error) {
$objecttmp = new $objectclass($db);
Expand All @@ -108,28 +129,37 @@

foreach ($toselect as $toselectid) {
$objecttmp = new $objectclass($db); // we must create new instance because instance is saved into $listofobjectref array for future use
'@phan-var-force CommonObject $objecttmp';
$result = $objecttmp->fetch($toselectid);
if ($result > 0) {
$listofobjectid[$toselectid] = $toselectid;
$tmpobjectid = ($objecttmp->fk_soc ? $objecttmp->fk_soc : $objecttmp->socid);
if ($objecttmp->element == 'societe') {
'@phan-var-force Societe $objecttmp';
$tmpobjectid = $objecttmp->id;
} elseif ($objecttmp->element == 'contact') {
'@phan-var-force Contact $objecttmp';
$tmpobjectid = $objecttmp->id;
} elseif ($objecttmp->element == 'expensereport') {
'@phan-var-force ExpenseReport $objecttmp';
$tmpobjectid = $objecttmp->fk_user_author;
} elseif ($objecttmp->element == 'partnership' && getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR') == 'member') {
'@phan-var-force Partnership $objecttmp';
$tmpobjectid = $objecttmp->fk_member;
} elseif ($objecttmp->element == 'holiday') {
'@phan-var-force Holiday $objecttmp';
$tmpobjectid = $objecttmp->fk_user;
} elseif ($objecttmp->element == 'conferenceorboothattendee') {
'@phan-var-force ConferenceOrBoothAttendee $objecttmp';
$tmpobjectid = $objecttmp->id;
}
if (empty($tmpobjectid)) {
$tmpobjectid = 0;
}

if ($objectclass == 'Facture') {
'@phan-var-force Facture $objecttmp';
$tmpobjectid = $objecttmp->id;
$tmparraycontact = array();
$tmparraycontact = $objecttmp->liste_contact(-1, 'external', 0, 'BILLING');
if (is_array($tmparraycontact) && count($tmparraycontact) > 0) {
Expand All @@ -138,6 +168,7 @@
}
}
} elseif ($objectclass == 'CommandeFournisseur') {
'@phan-var-force CommandeFournisseur $objecttmp';
$tmparraycontact = array();
$tmparraycontact = $objecttmp->liste_contact(-1, 'external', 0, 'CUSTOMER');
if (is_array($tmparraycontact) && count($tmparraycontact) > 0) {
Expand Down Expand Up @@ -200,7 +231,7 @@
// Recipients are provided into free text
$tmparray[] = trim(GETPOST('sendto', 'alphawithlgt'));
}
if (count($receiver) > 0) {
if (count($receiver) > 0 && is_object($thirdparty)) {
foreach ($receiver as $key => $val) {
// Recipient was provided from combo list
if ($val == 'thirdparty') { // Id of third party or user
Expand Down Expand Up @@ -1135,6 +1166,11 @@
// Generate document foreach object according to model linked to object
// @todo : propose model selection
if (!$error && $massaction == 'generate_doc' && $permissiontoread) {
// Complete with classes that use this massaction
<<<'EOPHAN'
@phan-var-force 'Commande'|'CommandeFournisseur'|'Contrat'|'Expedition'|'ExpenseReport'|'Facture'|'FactureFournisseur'|'Fichinter'|'Project'|'Propal'|'SupplierProposal' $objectclass
EOPHAN;

$db->begin();
$nbok = 0;
foreach ($toselect as $toselectid) {
Expand All @@ -1151,7 +1187,7 @@
$newlang = $objecttmp->thirdparty->default_lang; // for proposal, order, invoice, ...
}
if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && isset($objecttmp->default_lang)) {
$newlang = $objecttmp->default_lang; // for thirdparty
$newlang = $objecttmp->default_lang; // for thirdparty @phan-suppress-current-line PhanUndeclaredProperty
}
if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && empty($objecttmp->thirdparty)) { //load lang from thirdparty
$objecttmp->fetch_thirdparty();
Expand Down Expand Up @@ -1263,6 +1299,8 @@
}

if (!$error && ($action == 'updateprice' && $confirm == 'yes') && $permissiontoadd) {
'@phan-var-force Product|ProductCustomerPrice $obj';
'@phan-var-force Product|ProductCustomerPrice $object';
$nbok = 0;
$db->begin();
if (GETPOSTISSET('pricerate')) {
Expand Down Expand Up @@ -1308,9 +1346,10 @@
}

if (!$error && ($action == 'setsupervisor' && $confirm == 'yes') && $permissiontoadd) {
'@phan-var-force User $object';
$nbok = 0;
$db->begin();
$supervisortoset = GETPOST('supervisortoset');
$supervisortoset = GETPOSTINT('supervisortoset');
if (!empty($supervisortoset)) {
foreach ($toselect as $toselectid) {
$result = $object->fetch($toselectid);
Expand Down Expand Up @@ -1358,7 +1397,7 @@
$res = $object->add_contact($usertoaffect, $projectrole, 'internal');
if ($res >= 0) {
$taskstatic = new Task($db);
$task_array = $taskstatic->getTasksArray(0, 0, $object->id, 0, 0);
$task_array = $taskstatic->getTasksArray(null, null, $object->id, 0, 0);

foreach ($task_array as $task) {
$tasksToAffect = new Task($db);
Expand Down Expand Up @@ -1596,6 +1635,7 @@
$db->begin();

$objecttmp = new $objectclass($db);
'@phan-var-force Holiday $objecttmp';
$nbok = 0;
foreach ($toselect as $toselectid) {
$result = $objecttmp->fetch($toselectid);
Expand All @@ -1605,7 +1645,7 @@
continue;
}
if ($user->id == $objecttmp->fk_validator) {
$objecttmp->oldcopy = dol_clone($objecttmp, 2);
$objecttmp->oldcopy = dol_clone($objecttmp, 2); // @phan-suppress-current-line PhanTypeMismatchProperty

$objecttmp->date_valid = dol_now();
$objecttmp->fk_user_valid = $user->id;
Expand Down Expand Up @@ -1712,7 +1752,8 @@
}
}

if (!$error && ($massaction == 'increaseholiday' || ($action == 'increaseholiday' && $confirm == 'yes')) && $permissiontoapprove) {
if (!$error && ($massaction == 'increaseholiday' || ($action == 'increaseholiday' && $confirm == 'yes')) && $permissiontoapprove && is_array($toselect)) {
'@phan-var-force Holiday $holiday'; // Supposing that $holiday is set, it is needed.
$db->begin();
$objecttmp = new $objectclass($db);
$nbok = 0;
Expand Down Expand Up @@ -1780,6 +1821,7 @@
if (getDolGlobalString('PROJECT_TASK_ADDON') && is_readable(DOL_DOCUMENT_ROOT . "/core/modules/project/task/" . getDolGlobalString('PROJECT_TASK_ADDON') . ".php")) {
require_once DOL_DOCUMENT_ROOT . "/core/modules/project/task/" . getDolGlobalString('PROJECT_TASK_ADDON') . '.php';
$modTask = new $obj();
'@phan-var-force ModeleNumRefTask $modTask';
$defaultref = $modTask->getNextValue(0, $clone_task);
}

Expand Down

0 comments on commit 83859bd

Please sign in to comment.