From 91115d651f9403cb155b0e3408e6e4dbc98b7790 Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Tue, 8 Dec 2020 11:24:15 -0500 Subject: [PATCH] Use better stubs for Serializable and SoapClient --- src/Psalm/Config.php | 10 + stubs/CoreGenericClasses.phpstub | 13 ++ stubs/soap.php | 308 +++++++++++++++++++++++++++++++ tests/MethodSignatureTest.php | 2 +- 4 files changed, 332 insertions(+), 1 deletion(-) create mode 100644 stubs/soap.php diff --git a/src/Psalm/Config.php b/src/Psalm/Config.php index 1f45b05d0..02467b7e0 100644 --- a/src/Psalm/Config.php +++ b/src/Psalm/Config.php @@ -1840,6 +1840,16 @@ class Config $core_generic_files[] = $ext_pdo_path; } + if (\extension_loaded('soap')) { + $ext_pdo_path = dirname(__DIR__, 2) . '/stubs/soap.php'; + + if (!file_exists($ext_pdo_path)) { + throw new \UnexpectedValueException('Cannot locate soap classes'); + } + + $core_generic_files[] = $ext_pdo_path; + } + if (\extension_loaded('ds')) { $ext_ds_path = dirname(__DIR__, 2) . '/stubs/ext-ds.php'; diff --git a/stubs/CoreGenericClasses.phpstub b/stubs/CoreGenericClasses.phpstub index 2e3dd08e5..8af9c4291 100644 --- a/stubs/CoreGenericClasses.phpstub +++ b/stubs/CoreGenericClasses.phpstub @@ -2285,3 +2285,16 @@ class SimpleXMLElement implements \Stringable, \Countable, \RecursiveIterator { } } + +interface Serializable { + /** + * @return string the string representation of the object or null + */ + public function serialize(); + + /** + * @param string $serialized

+ * @return void + */ + public function unserialize($serialized); +} diff --git a/stubs/soap.php b/stubs/soap.php new file mode 100644 index 000000000..a86ac0b83 --- /dev/null +++ b/stubs/soap.php @@ -0,0 +1,308 @@ + + * URI of the WSDL file or NULL if working in + * non-WSDL mode. + *

+ *

+ * During development, WSDL caching may be disabled by the + * use of the soap.wsdl_cache_ttl php.ini setting + * otherwise changes made to the WSDL file will have no effect until + * soap.wsdl_cache_ttl is expired. + *

+ * @param array $options [optional]

+ * An array of options. If working in WSDL mode, this parameter is optional. + * If working in non-WSDL mode, the location and + * uri options must be set, where location + * is the URL of the SOAP server to send the request to, and uri + * is the target namespace of the SOAP service. + *

+ *

+ * The style and use options only work in + * non-WSDL mode. In WSDL mode, they come from the WSDL file. + *

+ *

+ * The soap_version option should be one of either + * SOAP_1_1 or SOAP_1_2 to + * select SOAP 1.1 or 1.2, respectively. If omitted, 1.1 is used. + *

+ *

+ * For HTTP authentication, the login and + * password options can be used to supply credentials. + * For making an HTTP connection through + * a proxy server, the options proxy_host, + * proxy_port, proxy_login + * and proxy_password are also available. + * For HTTPS client certificate authentication use + * local_cert and passphrase options. An + * authentication may be supplied in the authentication + * option. The authentication method may be either + * SOAP_AUTHENTICATION_BASIC (default) or + * SOAP_AUTHENTICATION_DIGEST. + *

+ *

+ * The compression option allows to use compression + * of HTTP SOAP requests and responses. + *

+ *

+ * The encoding option defines internal character + * encoding. This option does not change the encoding of SOAP requests (it is + * always utf-8), but converts strings into it. + *

+ *

+ * The trace option enables tracing of request so faults + * can be backtraced. This defaults to FALSE + *

+ *

+ * The classmap option can be used to map some WSDL + * types to PHP classes. This option must be an array with WSDL types + * as keys and names of PHP classes as values. + *

+ *

+ * Setting the boolean trace option enables use of the + * methods + * SoapClient->__getLastRequest, + * SoapClient->__getLastRequestHeaders, + * SoapClient->__getLastResponse and + * SoapClient->__getLastResponseHeaders. + *

+ *

+ * The exceptions option is a boolean value defining whether + * soap errors throw exceptions of type + * SoapFault. + *

+ *

+ * The connection_timeout option defines a timeout in seconds + * for the connection to the SOAP service. This option does not define a timeout + * for services with slow responses. To limit the time to wait for calls to finish the + * default_socket_timeout setting + * is available. + *

+ *

+ * The typemap option is an array of type mappings. + * Type mapping is an array with keys type_name, + * type_ns (namespace URI), from_xml + * (callback accepting one string parameter) and to_xml + * (callback accepting one object parameter). + *

+ *

+ * The cache_wsdl option is one of + * WSDL_CACHE_NONE, + * WSDL_CACHE_DISK, + * WSDL_CACHE_MEMORY or + * WSDL_CACHE_BOTH. + *

+ *

+ * The user_agent option specifies string to use in + * User-Agent header. + *

+ *

+ * The stream_context option is a resource + * for context. + *

+ *

+ * The features option is a bitmask of + * SOAP_SINGLE_ELEMENT_ARRAYS, + * SOAP_USE_XSI_ARRAY_TYPE, + * SOAP_WAIT_ONE_WAY_CALLS. + *

+ *

+ * The keep_alive option is a boolean value defining whether + * to send the Connection: Keep-Alive header or + * Connection: close. + *

+ *

+ * The ssl_method option is one of + * SOAP_SSL_METHOD_TLS, + * SOAP_SSL_METHOD_SSLv2, + * SOAP_SSL_METHOD_SSLv3 or + * SOAP_SSL_METHOD_SSLv23. + *

+ * @throws SoapFault A SoapFault exception will be thrown if the wsdl URI cannot be loaded. + * @since 5.0.1 + */ + public function __construct ($wsdl, array $options = null) {} + + /** + * Calls a SOAP function (deprecated) + * @link https://php.net/manual/en/soapclient.call.php + * @param string $function_name + * @param array $arguments + * @return mixed + * @since 5.0.1 + */ + public function __call ($function_name, $arguments) {} + + /** + * Calls a SOAP function + * @link https://php.net/manual/en/soapclient.soapcall.php + * @param string $function_name

+ * The name of the SOAP function to call. + *

+ * @param array $arguments

+ * An array of the arguments to pass to the function. This can be either + * an ordered or an associative array. Note that most SOAP servers require + * parameter names to be provided, in which case this must be an + * associative array. + *

+ * @param array $options [optional]

+ * An associative array of options to pass to the client. + *

+ *

+ * The location option is the URL of the remote Web service. + *

+ *

+ * The uri option is the target namespace of the SOAP service. + *

+ *

+ * The soapaction option is the action to call. + *

+ * @param mixed $input_headers [optional]

+ * An array of headers to be sent along with the SOAP request. + *

+ * @param array $output_headers [optional]

+ * If supplied, this array will be filled with the headers from the SOAP response. + *

+ * @return mixed SOAP functions may return one, or multiple values. If only one value is returned + * by the SOAP function, the return value of __soapCall will be + * a simple value (e.g. an integer, a string, etc). If multiple values are + * returned, __soapCall will return + * an associative array of named output parameters. + *

+ *

+ * On error, if the SoapClient object was constructed with the exceptions + * option set to FALSE, a SoapFault object will be returned. + * @since 5.0.1 + */ + public function __soapCall (string $function_name, array $arguments, array $options = null, $input_headers = null, &$output_headers = null) {} + + /** + * Returns last SOAP request + * @link https://php.net/manual/en/soapclient.getlastrequest.php + * @return string The last SOAP request, as an XML string. + * @since 5.0.1 + */ + public function __getLastRequest () {} + + /** + * Returns last SOAP response + * @link https://php.net/manual/en/soapclient.getlastresponse.php + * @return string The last SOAP response, as an XML string. + * @since 5.0.1 + */ + public function __getLastResponse () {} + + /** + * Returns the SOAP headers from the last request + * @link https://php.net/manual/en/soapclient.getlastrequestheaders.php + * @return string The last SOAP request headers. + * @since 5.0.1 + */ + public function __getLastRequestHeaders () {} + + /** + * Returns the SOAP headers from the last response + * @link https://php.net/manual/en/soapclient.getlastresponseheaders.php + * @return string The last SOAP response headers. + * @since 5.0.1 + */ + public function __getLastResponseHeaders () {} + + /** + * Returns list of available SOAP functions + * @link https://php.net/manual/en/soapclient.getfunctions.php + * @return array The array of SOAP function prototypes, detailing the return type, + * the function name and type-hinted parameters. + * @since 5.0.1 + */ + public function __getFunctions () {} + + /** + * Returns a list of SOAP types + * @link https://php.net/manual/en/soapclient.gettypes.php + * @return array The array of SOAP types, detailing all structures and types. + * @since 5.0.1 + */ + public function __getTypes () {} + + /** + * Returns a list of all cookies + * @link https://php.net/manual/en/soapclient.getcookies.php + * @return array The array of all cookies + * @since 5.4.3 + */ + public function __getCookies () {} + + /** + * Performs a SOAP request + * @link https://php.net/manual/en/soapclient.dorequest.php + * @param string $request

+ * The XML SOAP request. + *

+ * @param string $location

+ * The URL to request. + *

+ * @param string $action

+ * The SOAP action. + *

+ * @param int $version

+ * The SOAP version. + *

+ * @param int $one_way [optional]

+ * If one_way is set to 1, this method returns nothing. + * Use this where a response is not expected. + *

+ * @return string The XML SOAP response. + * @since 5.0.1 + */ + public function __doRequest ($request, $location, $action, $version, $one_way = 0) {} + + /** + * The __setCookie purpose + * @link https://php.net/manual/en/soapclient.setcookie.php + * @param string $name

+ * The name of the cookie. + *

+ * @param string $value [optional]

+ * The value of the cookie. If not specified, the cookie will be deleted. + *

+ * @return void No value is returned. + * @since 5.0.4 + */ + public function __setCookie ($name, $value = null) {} + + /** + * Sets the location of the Web service to use + * @link https://php.net/manual/en/soapclient.setlocation.php + * @param string $new_location [optional]

+ * The new endpoint URL. + *

+ * @return string The old endpoint URL. + * @since 5.0.1 + */ + public function __setLocation ($new_location = null) {} + + /** + * Sets SOAP headers for subsequent calls + * @link https://php.net/manual/en/soapclient.setsoapheaders.php + * @param mixed $soapheaders [optional]

+ * The headers to be set. It could be SoapHeader + * object or array of SoapHeader objects. + * If not specified or set to NULL, the headers will be deleted. + *

+ * @return bool TRUE on success or FALSE on failure. + * @since 5.0.5 + */ + public function __setSoapHeaders ($soapheaders = null) {} + +} diff --git a/tests/MethodSignatureTest.php b/tests/MethodSignatureTest.php index 434514c70..b8649b292 100644 --- a/tests/MethodSignatureTest.php +++ b/tests/MethodSignatureTest.php @@ -1255,7 +1255,7 @@ class MethodSignatureTest extends TestCase public function unserialize(string $serialized) {} public function serialize() {} }', - 'error_message' => 'MethodSignatureMismatch', + 'error_message' => 'InvalidReturnType', ], 'preventImplementingSerializableWithWrongDocblockType' => [ '