Skip to content

Commit b0ccacc

Browse files
committed
support all socket_* functions
1 parent 5fbfc32 commit b0ccacc

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

conf/config.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1821,7 +1821,7 @@ services:
18211821
- phpstan.broker.dynamicMethodReturnTypeExtension
18221822

18231823
-
1824-
class: PHPStan\Type\Php\SocketCreateReturnTypeExtension
1824+
class: PHPStan\Type\Php\SocketObjectReturnTypeFunctionExtension
18251825
tags:
18261826
- phpstan.broker.dynamicFunctionReturnTypeExtension
18271827

src/Type/Php/SocketCreateReturnTypeExtension.php renamed to src/Type/Php/SocketObjectReturnTypeFunctionExtension.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,28 @@
1111
use PHPStan\Type\ResourceType;
1212
use PHPStan\Type\Type;
1313
use PHPStan\Type\UnionType;
14-
use function count;
14+
use function in_array;
1515

16-
final class SocketCreateReturnTypeExtension implements DynamicFunctionReturnTypeExtension
16+
final class SocketObjectReturnTypeFunctionExtension implements DynamicFunctionReturnTypeExtension
1717
{
1818

19+
private const FUNCTIONS = [
20+
'socket_accept',
21+
'socket_addrinfo_bind',
22+
'socket_addrinfo_connect',
23+
'socket_create',
24+
'socket_create_listen',
25+
'socket_import_stream',
26+
'socket_wsaprotocol_info_import',
27+
];
28+
1929
public function isFunctionSupported(FunctionReflection $functionReflection): bool
2030
{
21-
return $functionReflection->getName() === 'socket_create';
31+
return in_array($functionReflection->getName(), self::FUNCTIONS, true);
2232
}
2333

2434
public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type
2535
{
26-
if (count($functionCall->getArgs()) < 3) {
27-
return null;
28-
}
29-
3036
if ($scope->getPhpVersion()->socketCreateReturnsObject()->yes()) {
3137
return new UnionType([new ConstantBooleanType(false), new ObjectType('\\Socket')]);
3238
}

0 commit comments

Comments
 (0)