Skip to content

Commit 552952a

Browse files
authored
Merge branch refs/heads/1.10.x into 1.11.x
2 parents a373c88 + 24c5249 commit 552952a

File tree

9 files changed

+102
-3
lines changed

9 files changed

+102
-3
lines changed

conf/config.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,11 @@ services:
447447
tags:
448448
- phpstan.stubFilesExtension
449449

450+
-
451+
class: PHPStan\PhpDoc\SocketSelectStubFilesExtension
452+
tags:
453+
- phpstan.stubFilesExtension
454+
450455
-
451456
class: PHPStan\PhpDoc\DefaultStubFilesProvider
452457
arguments:

resources/functionMap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10630,7 +10630,7 @@
1063010630
'socket_recv' => ['int|false', 'socket'=>'resource', '&w_buf'=>'string', 'len'=>'int', 'flags'=>'int'],
1063110631
'socket_recvfrom' => ['int|false', 'socket'=>'resource', '&w_buf'=>'string', 'len'=>'int', 'flags'=>'int', '&w_name'=>'string', '&w_port='=>'int'],
1063210632
'socket_recvmsg' => ['int|false', 'socket'=>'resource', '&w_message'=>'string', 'flags='=>'int'],
10633-
'socket_select' => ['int|false', '&rw_read_fds'=>'resource[]|null', '&rw_write_fds'=>'resource[]|null', '&rw_except_fds'=>'resource[]|null', 'tv_sec'=>'int|null', 'tv_usec='=>'int|null'],
10633+
'socket_select' => ['int|false', '&w_read_fds'=>'resource[]|null', '&w_write_fds'=>'resource[]|null', '&w_except_fds'=>'resource[]|null', 'tv_sec'=>'int|null', 'tv_usec='=>'int|null'],
1063410634
'socket_send' => ['int|false', 'socket'=>'resource', 'buf'=>'string', 'len'=>'int', 'flags'=>'int'],
1063510635
'socket_sendmsg' => ['int|false', 'socket'=>'resource', 'message'=>'array', 'flags'=>'int'],
1063610636
'socket_sendto' => ['int|false', 'socket'=>'resource', 'buf'=>'string', 'len'=>'int', 'flags'=>'int', 'addr'=>'string', 'port='=>'int'],

resources/functionMap_php80delta.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
'proc_get_status' => ['array{command: string, pid: int, running: bool, signaled: bool, stopped: bool, exitcode: int, termsig: int, stopsig: int}', 'process'=>'resource'],
9696
'set_error_handler' => ['?callable', 'callback'=>'null|callable(int,string,string,int):bool', 'error_types='=>'int'],
9797
'socket_addrinfo_lookup' => ['AddressInfo[]', 'node'=>'string', 'service='=>'mixed', 'hints='=>'array'],
98-
'socket_select' => ['int|false', '&rw_read'=>'Socket[]|null', '&rw_write'=>'Socket[]|null', '&rw_except'=>'Socket[]|null', 'seconds'=>'int|null', 'microseconds='=>'int'],
98+
'socket_select' => ['int|false', '&w_read'=>'Socket[]|null', '&w_write'=>'Socket[]|null', '&w_except'=>'Socket[]|null', 'seconds'=>'int|null', 'microseconds='=>'int'],
9999
'sodium_crypto_aead_chacha20poly1305_ietf_decrypt' => ['string|false', 'confidential_message'=>'string', 'public_message'=>'string', 'nonce'=>'string', 'key'=>'string'],
100100
'str_contains' => ['bool', 'haystack'=>'string', 'needle'=>'string'],
101101
'str_split' => ['non-empty-list<string>', 'str'=>'string', 'split_length='=>'positive-int'],
@@ -237,7 +237,7 @@
237237
'read_exif_data' => ['array', 'filename'=>'string', 'sections_needed='=>'string', 'sub_arrays='=>'bool', 'read_thumbnail='=>'bool'],
238238
'restore_include_path' => ['void'],
239239
'round' => ['__benevolent<float|false>', 'number'=>'float', 'precision='=>'int', 'mode='=>'1|2|3|4'],
240-
'socket_select' => ['int|false', '&rw_read_fds'=>'resource[]|null', '&rw_write_fds'=>'resource[]|null', '&rw_except_fds'=>'resource[]|null', 'tv_sec'=>'int|null', 'tv_usec='=>'int|null'],
240+
'socket_select' => ['int|false', '&w_read_fds'=>'resource[]|null', '&w_write_fds'=>'resource[]|null', '&w_except_fds'=>'resource[]|null', 'tv_sec'=>'int|null', 'tv_usec='=>'int|null'],
241241
'sodium_crypto_aead_chacha20poly1305_ietf_decrypt' => ['?string|?false', 'confidential_message'=>'string', 'public_message'=>'string', 'nonce'=>'string', 'key'=>'string'],
242242
'SplFileObject::fgetss' => ['string|false', 'allowable_tags='=>'string'],
243243
'strchr' => ['string|false', 'haystack'=>'string', 'needle'=>'string|int', 'before_needle='=>'bool'],
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\PhpDoc;
4+
5+
use PHPStan\Php\PhpVersion;
6+
7+
class SocketSelectStubFilesExtension implements StubFilesExtension
8+
{
9+
10+
public function __construct(private PhpVersion $phpVersion)
11+
{
12+
}
13+
14+
public function getFiles(): array
15+
{
16+
if ($this->phpVersion->getVersionId() >= 80000) {
17+
return [__DIR__ . '/../../stubs/socket_select_php8.stub'];
18+
}
19+
20+
return [__DIR__ . '/../../stubs/socket_select.stub'];
21+
}
22+
23+
}

stubs/socket_select.stub

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
/**
4+
* @param array<resource>|null &$read
5+
* @param array<resource>|null &$write
6+
* @param array<resource>|null &$except
7+
* @param-out ($read is not null ? array<resource> : null) $read
8+
* @param-out ($write is not null ? array<resource> : null) $write
9+
* @param-out ($except is not null ? array<resource> : null) $except
10+
*/
11+
function socket_select(?array &$read, ?array &$write, ?array &$except, ?int $seconds, int $microseconds = 0): int|false {}

stubs/socket_select_php8.stub

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
/**
4+
* @param array<Socket>|null &$read
5+
* @param array<Socket>|null &$write
6+
* @param array<Socket>|null &$except
7+
* @param-out ($read is not null ? array<Socket> : null) $read
8+
* @param-out ($write is not null ? array<Socket> : null) $write
9+
* @param-out ($except is not null ? array<Socket> : null) $except
10+
*/
11+
function socket_select(?array &$read, ?array &$write, ?array &$except, ?int $seconds, int $microseconds = 0): int|false {}

tests/PHPStan/Analyser/NodeScopeResolverTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,13 @@ public function dataFileAsserts(): iterable
255255
yield from $this->gatherAssertTypes(__DIR__ . '/data/generics-do-not-generalize.php');
256256
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-9985.php');
257257
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-6294.php');
258+
259+
if (PHP_VERSION_ID >= 80000) {
260+
yield from $this->gatherAssertTypes(__DIR__ . '/data/discussion-10285-php8.php');
261+
} else {
262+
yield from $this->gatherAssertTypes(__DIR__ . '/data/discussion-10285.php');
263+
}
264+
258265
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-6462.php');
259266
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-2580.php');
260267
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-9753.php');
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Discussion10285Php8;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class HelloWorld
8+
{
9+
public function sayHello(): void
10+
{
11+
$socket = socket_create(AF_INET, SOCK_STREAM, 0);
12+
if($socket === false) return;
13+
$read = [$socket];
14+
$write = [];
15+
$except = null;
16+
socket_select($read, $write, $except, 0, 1);
17+
assertType('array<Socket>', $read);
18+
assertType('array<Socket>', $write);
19+
assertType('null', $except);
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Discussion10285;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class HelloWorld
8+
{
9+
public function sayHello(): void
10+
{
11+
$socket = socket_create(AF_INET, SOCK_STREAM, 0);
12+
if($socket === false) return;
13+
$read = [$socket];
14+
$write = [];
15+
$except = null;
16+
socket_select($read, $write, $except, 0, 1);
17+
assertType('array<resource>', $read);
18+
assertType('array<resource>', $write);
19+
assertType('null', $except);
20+
}
21+
}

0 commit comments

Comments
 (0)