Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnusedFunctionCall on socket* functions #8818

Closed
ghost opened this issue Dec 3, 2022 · 2 comments · Fixed by #8835
Closed

UnusedFunctionCall on socket* functions #8818

ghost opened this issue Dec 3, 2022 · 2 comments · Fixed by #8835
Labels
easy problems Issues that can be fixed without background knowledge of Psalm enhancement good first issue Help wanted pure/immutable

Comments

@ghost
Copy link

ghost commented Dec 3, 2022

Hello everyone,

I noticed that Psalm complains about my use of socket functions:

for example:
socket_set_block($socket);
results in:
The call to socket_set_block is not used (see https://psalm.dev/206)

Based on the PHP documentation, the functions socket_bind, socket_set_block and socket_set_nonblock, can be used like that when the return code is irrelevant.
https://www.php.net/manual/en/function.socket-set-nonblock.php

Relevant snippet: https://psalm.dev/r/43f28bcd5d

Thank you.

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/43f28bcd5d
<?php

$socket = socket_create(AF_UNIX, SOCK_STREAM, 0);

socket_bind($socket, "/run/daemon.sock");

socket_set_nonblock($socket);

socket_set_block($socket);
Psalm output (using commit 14d48a0):

ERROR: UnusedFunctionCall - 5:1 - The call to socket_bind is not used

ERROR: UnusedFunctionCall - 7:1 - The call to socket_set_nonblock is not used

ERROR: UnusedFunctionCall - 9:1 - The call to socket_set_block is not used

@weirdan
Copy link
Collaborator

weirdan commented Dec 3, 2022

They need to be added to this list:

public function isCallMapFunctionPure(
Codebase $codebase,
?NodeTypeProvider $type_provider,
string $function_id,
?array $args,
bool &$must_use = true
): bool {
$impure_functions = [
// file io
'chdir', 'chgrp', 'chmod', 'chown', 'chroot', 'copy', 'file_get_contents', 'file_put_contents',
'opendir', 'readdir', 'closedir', 'rewinddir', 'scandir',
'fopen', 'fread', 'fwrite', 'fclose', 'touch', 'fpassthru', 'fputs', 'fscanf', 'fseek', 'flock',

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy problems Issues that can be fixed without background knowledge of Psalm enhancement good first issue Help wanted pure/immutable
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant