Skip to content

Commit 48543d1

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

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
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/Php/PhpVersions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function producesWarningForFinalPrivateMethods(): TrinaryLogic
2828
return IntegerRangeType::fromInterval(80000, null)->isSuperTypeOf($this->phpVersions)->result;
2929
}
3030

31-
public function socketCreateReturnsObject(): TrinaryLogic
31+
public function socketFunctionsUseObject(): TrinaryLogic
3232
{
3333
return IntegerRangeType::fromInterval(80000, null)->isSuperTypeOf($this->phpVersions)->result;
3434
}

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,33 @@
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-
30-
if ($scope->getPhpVersion()->socketCreateReturnsObject()->yes()) {
36+
if ($scope->getPhpVersion()->socketFunctionsUseObject()->yes()) {
3137
return new UnionType([new ConstantBooleanType(false), new ObjectType('\\Socket')]);
3238
}
3339

34-
if ($scope->getPhpVersion()->socketCreateReturnsObject()->no()) {
40+
if ($scope->getPhpVersion()->socketFunctionsUseObject()->no()) {
3541
return new UnionType([new ConstantBooleanType(false), new ResourceType()]);
3642
}
3743

0 commit comments

Comments
 (0)