Skip to content

Commit f933ac7

Browse files
committed
Add support for nullable values in curl_setopt
1 parent 43492a1 commit f933ac7

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

src/Reflection/ParametersAcceptorSelector.php

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,32 @@ private static function getCurlOptValueType(int $curlOpt): ?Type
918918
}
919919
}
920920

921+
$nullableStringConstants = [
922+
'CURLOPT_ACCEPT_ENCODING',
923+
'CURLOPT_CUSTOMREQUEST',
924+
'CURLOPT_DNS_INTERFACE',
925+
'CURLOPT_DNS_LOCAL_IP4',
926+
'CURLOPT_DNS_LOCAL_IP6',
927+
'CURLOPT_DOH_URL',
928+
'CURLOPT_FTP_ACCOUNT',
929+
'CURLOPT_FTPPORT',
930+
'CURLOPT_HSTS',
931+
'CURLOPT_KRBLEVEL',
932+
'CURLOPT_RANGE',
933+
'CURLOPT_RTSP_SESSION_ID',
934+
'CURLOPT_UNIX_SOCKET_PATH',
935+
'CURLOPT_XOAUTH2_BEARER',
936+
];
937+
foreach ($nullableStringConstants as $constName) {
938+
if (defined($constName) && constant($constName) === $curlOpt) {
939+
return TypeCombinator::intersect(
940+
new NullType(),
941+
new StringType(),
942+
new AccessoryNonEmptyStringType(),
943+
);
944+
}
945+
}
946+
921947
$nonEmptyStringConstants = [
922948
'CURLOPT_ABSTRACT_UNIX_SOCKET',
923949
'CURLOPT_ALTSVC',
@@ -927,15 +953,10 @@ private static function getCurlOptValueType(int $curlOpt): ?Type
927953
'CURLOPT_COOKIE',
928954
'CURLOPT_COOKIEJAR',
929955
'CURLOPT_COOKIELIST',
930-
'CURLOPT_CUSTOMREQUEST',
931956
'CURLOPT_DEFAULT_PROTOCOL',
932-
'CURLOPT_DNS_INTERFACE',
933-
'CURLOPT_DNS_LOCAL_IP4',
934-
'CURLOPT_DNS_LOCAL_IP6',
935957
'CURLOPT_DNS_SERVERS',
936958
'CURLOPT_EGDSOCKET',
937959
'CURLOPT_FTP_ALTERNATIVE_TO_USER',
938-
'CURLOPT_FTPPORT',
939960
'CURLOPT_INTERFACE',
940961
'CURLOPT_KEYPASSWD',
941962
'CURLOPT_KRB4LEVEL',
@@ -966,7 +987,6 @@ private static function getCurlOptValueType(int $curlOpt): ?Type
966987
'CURLOPT_PROXYUSERNAME',
967988
'CURLOPT_PROXYUSERPWD',
968989
'CURLOPT_RANDOM_FILE',
969-
'CURLOPT_RANGE',
970990
'CURLOPT_REDIR_PROTOCOLS_STR',
971991
'CURLOPT_REFERER',
972992
'CURLOPT_REQUEST_TARGET',
@@ -994,12 +1014,10 @@ private static function getCurlOptValueType(int $curlOpt): ?Type
9941014
'CURLOPT_TLSAUTH_TYPE',
9951015
'CURLOPT_TLSAUTH_USERNAME',
9961016
'CURLOPT_TRANSFER_ENCODING',
997-
'CURLOPT_UNIX_SOCKET_PATH',
9981017
'CURLOPT_URL',
9991018
'CURLOPT_USERAGENT',
10001019
'CURLOPT_USERNAME',
10011020
'CURLOPT_USERPWD',
1002-
'CURLOPT_XOAUTH2_BEARER',
10031021
];
10041022
foreach ($nonEmptyStringConstants as $constName) {
10051023
if (defined($constName) && constant($constName) === $curlOpt) {

0 commit comments

Comments
 (0)