diff --git a/dev/build/phpstan/phpstan-baseline.neon b/dev/build/phpstan/phpstan-baseline.neon index a719087735f..32aec6d0659 100644 --- a/dev/build/phpstan/phpstan-baseline.neon +++ b/dev/build/phpstan/phpstan-baseline.neon @@ -1182,12 +1182,6 @@ parameters: count: 1 path: ../../../htdocs/ai/admin/setup.php - - - message: '#^Call to function is_object\(\) with ActionComm\|Adherent\|Commande\|CommandeFournisseur\|Contact\|Contrat\|Expedition\|ExpenseReport\|Facture\|FactureFournisseur\|Fichinter\|Mo\|Product\|Project\|Propal\|Task will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 2 - path: ../../../htdocs/api/class/api_documents.class.php - - message: '#^Variable \$modulepart in empty\(\) always exists and is not falsy\.$#' identifier: empty.variable diff --git a/htdocs/api/class/api_documents.class.php b/htdocs/api/class/api_documents.class.php index b96ca75da94..a1a66cfb469 100644 --- a/htdocs/api/class/api_documents.class.php +++ b/htdocs/api/class/api_documents.class.php @@ -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; }