|
11 | 11 | use PHPStan\Type\ResourceType; |
12 | 12 | use PHPStan\Type\Type; |
13 | 13 | use PHPStan\Type\UnionType; |
14 | | -use function count; |
| 14 | +use function in_array; |
15 | 15 |
|
16 | | -final class SocketCreateReturnTypeExtension implements DynamicFunctionReturnTypeExtension |
| 16 | +final class SocketObjectReturnTypeFunctionExtension implements DynamicFunctionReturnTypeExtension |
17 | 17 | { |
18 | 18 |
|
| 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 | + |
19 | 29 | public function isFunctionSupported(FunctionReflection $functionReflection): bool |
20 | 30 | { |
21 | | - return $functionReflection->getName() === 'socket_create'; |
| 31 | + return in_array($functionReflection->getName(), self::FUNCTIONS, true); |
22 | 32 | } |
23 | 33 |
|
24 | 34 | public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type |
25 | 35 | { |
26 | | - if (count($functionCall->getArgs()) < 3) { |
27 | | - return null; |
28 | | - } |
29 | | - |
30 | | - if ($scope->getPhpVersion()->socketCreateReturnsObject()->yes()) { |
| 36 | + if ($scope->getPhpVersion()->socketFunctionsUseObject()->yes()) { |
31 | 37 | return new UnionType([new ConstantBooleanType(false), new ObjectType('\\Socket')]); |
32 | 38 | } |
33 | 39 |
|
34 | | - if ($scope->getPhpVersion()->socketCreateReturnsObject()->no()) { |
| 40 | + if ($scope->getPhpVersion()->socketFunctionsUseObject()->no()) { |
35 | 41 | return new UnionType([new ConstantBooleanType(false), new ResourceType()]); |
36 | 42 | } |
37 | 43 |
|
|
0 commit comments