Versions used : SonarCloud with default configuration
We have an bug detected by sonar on a php8.0 project who is clearly not a bug:
Exemple of code:
match ($action) {
WebhookServiceInterface::CREATE => $this->handleWebhookPostPersist($args->getEntity(), $args, $webhookService),
WebhookServiceInterface::UPDATE => $this->handleWebhookPostUpdate($args->getEntity(), $args, $webhookService),
WebhookServiceInterface::DELETE => $this->handleWebhookPostRemove($entityId, $args, $webhookService),
default => throw new \LogicException("Unexpected webhook action $action")
};
Here there is clearly no assignation but SonarCloud give this error:
Remove this use of the output from “WebhookManagerTrait::handleWebhookPostPersist”; “WebhookManagerTrait::handleWebhookPostPersist” doesn’t return anything.
With this detail:
The output of functions that don’t return anything should not be used
If a function does not return anything, it makes no sense to use its output. Specifically, passing it to another function, or assigning its “result” to a variable is probably a bug because such functions return nothing, which is probably not what was intended.
Noncompliant Code Example
$result = closedir($dir_handle); // Noncompliant, “closedir” does not return anything.
Compliant Solution
closedir($dir_handle);