Skip to content

Commit 032a292

Browse files
committed
adjust and add CURLINFO_* constants
1 parent b2877f1 commit 032a292

File tree

1 file changed

+49
-15
lines changed

1 file changed

+49
-15
lines changed

src/Type/Php/CurlGetinfoFunctionDynamicReturnTypeExtension.php

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PHPStan\DependencyInjection\AutowiredService;
99
use PHPStan\Reflection\FunctionReflection;
1010
use PHPStan\Reflection\ReflectionProvider;
11+
use PHPStan\Type\Accessory\AccessoryArrayListType;
1112
use PHPStan\Type\ArrayType;
1213
use PHPStan\Type\Constant\ConstantArrayTypeBuilder;
1314
use PHPStan\Type\Constant\ConstantBooleanType;
@@ -16,6 +17,7 @@
1617
use PHPStan\Type\DynamicFunctionReturnTypeExtension;
1718
use PHPStan\Type\FloatType;
1819
use PHPStan\Type\IntegerType;
20+
use PHPStan\Type\MixedType;
1921
use PHPStan\Type\NullType;
2022
use PHPStan\Type\StringType;
2123
use PHPStan\Type\Type;
@@ -63,8 +65,10 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
6365
$floatType = new FloatType();
6466
$falseType = new ConstantBooleanType(false);
6567
$stringFalseType = TypeCombinator::union($stringType, $falseType);
66-
$integerStringArrayType = new ArrayType($integerType, $stringType);
67-
$nestedStringStringArrayType = new ArrayType($integerType, new ArrayType($stringType, $stringType));
68+
$integerFalseType = TypeCombinator::union($integerType, $falseType);
69+
$stringListType = TypeCombinator::intersect(new ArrayType($integerType, $stringType), new AccessoryArrayListType());
70+
$nestedArrayInListType = TypeCombinator::intersect(new ArrayType($integerType, new ArrayType($stringType, $stringType)), new AccessoryArrayListType());
71+
$mixedType = new MixedType();
6872

6973
$componentTypesPairedConstants = [
7074
'CURLINFO_EFFECTIVE_URL' => $stringType,
@@ -76,41 +80,42 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
7680
'CURLINFO_STARTTRANSFER_TIME' => $floatType,
7781
'CURLINFO_REDIRECT_COUNT' => $integerType,
7882
'CURLINFO_REDIRECT_TIME' => $floatType,
79-
'CURLINFO_REDIRECT_URL' => $stringType,
83+
'CURLINFO_REDIRECT_URL' => $stringFalseType,
8084
'CURLINFO_PRIMARY_IP' => $stringType,
8185
'CURLINFO_PRIMARY_PORT' => $integerType,
8286
'CURLINFO_LOCAL_IP' => $stringType,
8387
'CURLINFO_LOCAL_PORT' => $integerType,
84-
'CURLINFO_SIZE_UPLOAD' => $integerType,
85-
'CURLINFO_SIZE_DOWNLOAD' => $integerType,
86-
'CURLINFO_SPEED_DOWNLOAD' => $integerType,
87-
'CURLINFO_SPEED_UPLOAD' => $integerType,
88+
'CURLINFO_SIZE_UPLOAD' => $floatType,
89+
'CURLINFO_SIZE_DOWNLOAD' => $floatType,
90+
'CURLINFO_SPEED_DOWNLOAD' => $floatType,
91+
'CURLINFO_SPEED_UPLOAD' => $floatType,
8892
'CURLINFO_HEADER_SIZE' => $integerType,
8993
'CURLINFO_HEADER_OUT' => $stringFalseType,
9094
'CURLINFO_REQUEST_SIZE' => $integerType,
9195
'CURLINFO_SSL_VERIFYRESULT' => $integerType,
9296
'CURLINFO_CONTENT_LENGTH_DOWNLOAD' => $floatType,
9397
'CURLINFO_CONTENT_LENGTH_UPLOAD' => $floatType,
9498
'CURLINFO_CONTENT_TYPE' => $stringFalseType,
95-
'CURLINFO_PRIVATE' => $stringFalseType,
99+
'CURLINFO_PRIVATE' => $mixedType,
96100
'CURLINFO_RESPONSE_CODE' => $integerType,
101+
'CURLINFO_HTTP_CODE' => $integerType,
97102
'CURLINFO_HTTP_CONNECTCODE' => $integerType,
98103
'CURLINFO_HTTPAUTH_AVAIL' => $integerType,
99104
'CURLINFO_PROXYAUTH_AVAIL' => $integerType,
100105
'CURLINFO_OS_ERRNO' => $integerType,
101106
'CURLINFO_NUM_CONNECTS' => $integerType,
102-
'CURLINFO_SSL_ENGINES' => $integerStringArrayType,
103-
'CURLINFO_COOKIELIST' => $integerStringArrayType,
107+
'CURLINFO_SSL_ENGINES' => $stringListType,
108+
'CURLINFO_COOKIELIST' => $stringListType,
104109
'CURLINFO_FTP_ENTRY_PATH' => $stringFalseType,
105110
'CURLINFO_APPCONNECT_TIME' => $floatType,
106-
'CURLINFO_CERTINFO' => $nestedStringStringArrayType,
111+
'CURLINFO_CERTINFO' => $nestedArrayInListType,
107112
'CURLINFO_CONDITION_UNMET' => $integerType,
108113
'CURLINFO_RTSP_CLIENT_CSEQ' => $integerType,
109114
'CURLINFO_RTSP_CSEQ_RECV' => $integerType,
110115
'CURLINFO_RTSP_SERVER_CSEQ' => $integerType,
111-
'CURLINFO_RTSP_SESSION_ID' => $integerType,
116+
'CURLINFO_RTSP_SESSION_ID' => $stringFalseType,
112117
'CURLINFO_HTTP_VERSION' => $integerType,
113-
'CURLINFO_PROTOCOL' => $stringType,
118+
'CURLINFO_PROTOCOL' => $integerType,
114119
'CURLINFO_PROXY_SSL_VERIFYRESULT' => $integerType,
115120
'CURLINFO_SCHEME' => $stringType,
116121
'CURLINFO_CONTENT_LENGTH_DOWNLOAD_T' => $integerType,
@@ -127,6 +132,18 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
127132
'CURLINFO_REDIRECT_TIME_T' => $integerType,
128133
'CURLINFO_STARTTRANSFER_TIME_T' => $integerType,
129134
'CURLINFO_TOTAL_TIME_T' => $integerType,
135+
'CURLINFO_EFFECTIVE_METHOD' => $stringType,
136+
'CURLINFO_PROXY_ERROR' => $integerType,
137+
'CURLINFO_REFERER' => $stringFalseType,
138+
'CURLINFO_RETRY_AFTER' => $integerType,
139+
'CURLINFO_CAINFO' => $stringFalseType,
140+
'CURLINFO_CAPATH' => $stringFalseType,
141+
'CURLINFO_POSTTRANSFER_TIME_T' => $integerFalseType,
142+
'CURLINFO_QUEUE_TIME_T' => $integerFalseType,
143+
'CURLINFO_USED_PROXY' => $integerFalseType,
144+
'CURLINFO_HTTPAUTH_USED' => $integerFalseType,
145+
'CURLINFO_PROXYAUTH_USED' => $integerFalseType,
146+
'CURLINFO_CONN_ID' => $integerFalseType,
130147
];
131148

132149
foreach ($componentTypesPairedConstants as $constantName => $type) {
@@ -156,7 +173,7 @@ private function createAllComponentsReturnType(): Type
156173
$integerType = new IntegerType();
157174
$floatType = new FloatType();
158175
$stringOrNullType = TypeCombinator::union($stringType, new NullType());
159-
$nestedStringStringArrayType = new ArrayType($integerType, new ArrayType($stringType, $stringType));
176+
$nestedArrayInListType = TypeCombinator::intersect(new ArrayType($integerType, new ArrayType($stringType, $stringType)), new AccessoryArrayListType());
160177

161178
$componentTypesPairedStrings = [
162179
'url' => $stringType,
@@ -181,14 +198,31 @@ private function createAllComponentsReturnType(): Type
181198
'redirect_time' => $floatType,
182199
'redirect_url' => $stringType,
183200
'primary_ip' => $stringType,
184-
'certinfo' => $nestedStringStringArrayType,
201+
'certinfo' => $nestedArrayInListType,
185202
'primary_port' => $integerType,
186203
'local_ip' => $stringType,
187204
'local_port' => $integerType,
188205
'http_version' => $integerType,
189206
'protocol' => $integerType,
190207
'ssl_verifyresult' => $integerType,
191208
'scheme' => $stringType,
209+
'appconnect_time_us' => $integerType,
210+
'queue_time_us' => $integerType,
211+
'connect_time_us' => $integerType,
212+
'namelookup_time_us' => $integerType,
213+
'pretransfer_time_us' => $integerType,
214+
'redirect_time_us' => $integerType,
215+
'starttransfer_time_us' => $integerType,
216+
'posttransfer_time_us' => $integerType,
217+
'total_time_us' => $integerType,
218+
'request_header' => $stringType,
219+
'effective_method' => $stringType,
220+
'capath' => $stringType,
221+
'cainfo' => $stringType,
222+
'used_proxy' => $integerType,
223+
'httpauth_used' => $integerType,
224+
'proxyauth_used' => $integerType,
225+
'conn_id' => $integerType,
192226
];
193227
foreach ($componentTypesPairedStrings as $componentName => $componentValueType) {
194228
$builder->setOffsetValueType(new ConstantStringType($componentName), $componentValueType);

0 commit comments

Comments
 (0)