2
0
forked from Wavyzz/dolibarr

clean code (#35683)

* clean code

* clean code

* clean code

---------

Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
This commit is contained in:
Frédéric FRANCE
2025-10-08 21:32:49 +02:00
committed by GitHub
parent 8e3a185af5
commit 2ed9f1ea98
2 changed files with 13 additions and 19 deletions

View File

@@ -907,19 +907,18 @@ class Documents extends DolibarrApi
throw new RestException(500, 'Modulepart '.$modulepart.' not implemented yet.');
}
if (is_object($object)) {
if ($fetchbyid) {
// @phan-suppress-next-line PhanPluginSuspiciousParamPosition
$result = $object->fetch((int) $ref);
} else {
$result = $object->fetch(0, $ref);
}
// at this step $object is always an object
if ($fetchbyid) {
// @phan-suppress-next-line PhanPluginSuspiciousParamPosition
$result = $object->fetch((int) $ref);
} else {
$result = $object->fetch(0, $ref);
}
if ($result == 0) {
throw new RestException(404, "Object with ref '".$ref."' was not found.");
} elseif ($result < 0) {
throw new RestException(500, 'Error while fetching object: '.$object->error);
}
if ($result == 0) {
throw new RestException(404, "Object with ref '".$ref."' was not found.");
} elseif ($result < 0) {
throw new RestException(500, 'Error while fetching object: '.$object->error);
}
if (!($object->id > 0)) {
@@ -1056,7 +1055,8 @@ class Documents extends DolibarrApi
}
$moreinfo = array('note_private' => 'File uploaded using API /documents from IP '.getUserRemoteIP());
if (!empty($object) && is_object($object) && $object->id > 0) {
// $object may be null
if (is_object($object) && $object->id > 0) {
$moreinfo['src_object_type'] = $object->table_element;
$moreinfo['src_object_id'] = $object->id;
}