Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improved return type generation #149

Merged
merged 2 commits into from
Oct 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions generated/apc.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,18 @@ function apc_delete_file($keys)
/**
* Removes a stored variable from the cache.
*
* @param string|string[]|APCIterator $key The key used to store the value (with
* @param string|string[]|\APCIterator $key The key used to store the value (with
* apc_store).
* @throws ApcException
*
*/
function apc_delete($key)
function apc_delete($key): void
{
error_clear_last();
$result = \apc_delete($key);
if ($result === false) {
throw ApcException::createFromPhpError();
}
return $result;
}


Expand Down
2 changes: 1 addition & 1 deletion generated/apcu.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function apcu_dec(string $key, int $step = 1, ?bool &$success = null, int $ttl =
/**
* Removes a stored variable from the cache.
*
* @param string|string[]|APCUIterator $key A key used to store the value as a
* @param string|string[]|\APCUIterator $key A key used to store the value as a
* string for a single key,
* or as an array of strings for several keys,
* or as an APCUIterator object.
Expand Down
6 changes: 3 additions & 3 deletions generated/array.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function array_combine(array $keys, array $values): array
* used as its value, and all others will be lost.
*
* @param array $array An array of key/value pairs to be flipped.
* @return array Returns the flipped array on success and NULL on failure.
* @return array Returns the flipped array on success.
* @throws ArrayException
*
*/
Expand Down Expand Up @@ -153,7 +153,7 @@ function array_multisort(array &$array1, $array1_sort_order = SORT_ASC, $array1_
*
* @param array $array1 The array in which elements are replaced.
* @param array $params Optional. Arrays from which elements will be extracted.
* @return array|null Returns an array, or NULL if an error occurs.
* @return array Returns an array.
* @throws ArrayException
*
*/
Expand Down Expand Up @@ -188,7 +188,7 @@ function array_replace_recursive(array $array1, array ...$params): array
* @param array $array1 The array in which elements are replaced.
* @param array $params Arrays from which elements will be extracted.
* Values from later arrays overwrite the previous values.
* @return array|null Returns an array, or NULL if an error occurs.
* @return array Returns an array.
* @throws ArrayException
*
*/
Expand Down
1 change: 0 additions & 1 deletion generated/gmp.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ function gmp_import(string $data, int $word_size = 1, int $options = GMP_MSW_FIR
* gmp_random_range functions.
*
* Either a GMP number resource in PHP 5.5 and earlier, a GMP object in PHP 5.6 and later, or a numeric string provided that it is possible to convert the latter to a number.
* @return \GMP Returns NULL on success.
* @throws GmpException
*
*/
Expand Down
4 changes: 1 addition & 3 deletions generated/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,6 @@ function imagecolormatch($image1, $image2): void
* @param array $matrix A 3x3 matrix: an array of three arrays of three floats.
* @param float $div The divisor of the result of the convolution, used for normalization.
* @param float $offset Color offset.
* @return resource Returns TRUE on success.
* @throws ImageException
*
*/
Expand Down Expand Up @@ -2614,7 +2613,6 @@ function imagettfbbox(float $size, float $angle, string $fontfile, string $text)
* right, upper right, upper left. The points are relative to the text
* regardless of the angle, so "upper left" means in the top left-hand
* corner when you see the text horizontally.
* Returns FALSE on error.
* @throws ImageException
*
*/
Expand Down Expand Up @@ -2718,7 +2716,7 @@ function imagexbm($image, ?string $filename = null, int $foreground = null): voi
* @param string $jpeg_file_name Path to the JPEG image.
* @param int $spool Spool flag. If the spool flag is less than 2 then the JPEG will be
* returned as a string. Otherwise the JPEG will be printed to STDOUT.
* @return array If spool is less than 2, the JPEG will be returned. Otherwise returns TRUE on success.
* @return string|bool If spool is less than 2, the JPEG will be returned. Otherwise returns TRUE on success.
* @throws ImageException
*
*/
Expand Down
6 changes: 3 additions & 3 deletions generated/imap.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function imap_append($imap_stream, string $mailbox, string $message, string $opt
* @throws ImapException
*
*/
function imap_check($imap_stream): object
function imap_check($imap_stream): \stdClass
{
error_clear_last();
$result = \imap_check($imap_stream);
Expand Down Expand Up @@ -419,7 +419,7 @@ function imap_gc($imap_stream, int $caches): void
* @throws ImapException
*
*/
function imap_headerinfo($imap_stream, int $msg_number, int $fromlength = 0, int $subjectlength = 0, string $defaulthost = null): object
function imap_headerinfo($imap_stream, int $msg_number, int $fromlength = 0, int $subjectlength = 0, string $defaulthost = null): \stdClass
{
error_clear_last();
$result = \imap_headerinfo($imap_stream, $msg_number, $fromlength, $subjectlength, $defaulthost);
Expand Down Expand Up @@ -581,7 +581,7 @@ function imap_mail(string $to, string $subject, string $message, string $additio
* @throws ImapException
*
*/
function imap_mailboxmsginfo($imap_stream): object
function imap_mailboxmsginfo($imap_stream): \stdClass
{
error_clear_last();
$result = \imap_mailboxmsginfo($imap_stream);
Expand Down
2 changes: 1 addition & 1 deletion generated/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function dl(string $library): void
*
* @return int Returns the time of the last modification of the current
* page. The value returned is a Unix timestamp, suitable for
* feeding to date. Returns FALSE on error.
* feeding to date.
* @throws InfoException
*
*/
Expand Down
2 changes: 1 addition & 1 deletion generated/libxml.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* Retrieve last error from libxml.
*
* @return libXMLError Returns a LibXMLError object if there is any error in the
* @return \LibXMLError Returns a LibXMLError object if there is any error in the
* buffer, FALSE otherwise.
* @throws LibxmlException
*
Expand Down
2 changes: 0 additions & 2 deletions generated/mailparse.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
*
* If callbackfunc is set to NULL, returns the
* extracted section as a string.
*
* Returns FALSE on error.
* @throws MailparseException
*
*/
Expand Down
6 changes: 3 additions & 3 deletions generated/mbstring.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ function mb_eregi_replace(string $pattern, string $replace, string $string, stri
* If encoding is omitted,
* mb_http_output returns the current HTTP output
* character encoding.
* @return string If encoding is omitted,
* @return string|bool If encoding is omitted,
* mb_http_output returns the current HTTP output
* character encoding. Otherwise,
* Returns TRUE on success.
Expand Down Expand Up @@ -312,7 +312,7 @@ function mb_http_output(string $encoding = null)
* character encoding conversion, and the default character encoding
* for string functions defined by the mbstring module.
* You should notice that the internal encoding is totally different from the one for multibyte regex.
* @return string If encoding is set, then
* @return string|bool If encoding is set, then
* Returns TRUE on success.
* In this case, the character encoding for multibyte regex is NOT changed.
* If encoding is omitted, then
Expand Down Expand Up @@ -388,7 +388,7 @@ function mb_parse_str(string $encoded_string, ?array &$result = null): void
* @param string $encoding The encoding
* parameter is the character encoding. If it is omitted, the internal character
* encoding value will be used.
* @return string
* @return string|bool
* @throws MbstringException
*
*/
Expand Down
8 changes: 4 additions & 4 deletions generated/misc.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function define(string $name, $value, bool $case_insensitive = false): void
* @param string $filename Path to the PHP file to be highlighted.
* @param bool $return Set this parameter to TRUE to make this function return the
* highlighted code.
* @return string If return is set to TRUE, returns the highlighted
* @return string|bool If return is set to TRUE, returns the highlighted
* code as a string instead of printing it out. Otherwise, it will return
* TRUE on success, FALSE on failure.
* @throws MiscException
Expand All @@ -75,7 +75,7 @@ function highlight_file(string $filename, bool $return = false)
* @param string $str The PHP code to be highlighted. This should include the opening tag.
* @param bool $return Set this parameter to TRUE to make this function return the
* highlighted code.
* @return string If return is set to TRUE, returns the highlighted
* @return string|bool If return is set to TRUE, returns the highlighted
* code as a string instead of printing it out. Otherwise, it will return
* TRUE on success, FALSE on failure.
* @throws MiscException
Expand All @@ -101,7 +101,7 @@ function highlight_string(string $str, bool $return = false)
* Either the codepage name or identifier.
* @param string $subject The string to convert.
* @return string The subject string converted to
* out_codepage, or NULL on failure.
* out_codepage.
* @throws MiscException
*
*/
Expand Down Expand Up @@ -195,7 +195,7 @@ function sleep(int $seconds): int
*
* @param int $seconds Must be a non-negative integer.
* @param int $nanoseconds Must be a non-negative integer less than 1 billion.
* @return array{0:int,1:int} Returns TRUE on success.
* @return array{0:int,1:int}|bool Returns TRUE on success.
*
* If the delay was interrupted by a signal, an associative array will be
* returned with the components:
Expand Down
13 changes: 3 additions & 10 deletions generated/oci8.php
Original file line number Diff line number Diff line change
Expand Up @@ -1265,11 +1265,11 @@ function oci_pconnect(string $username, string $password, string $connection_str
* describes the column as, which is uppercase for columns created
* case insensitively.
* @return string Returns everything as strings except for abstract types (ROWIDs, LOBs and
* FILEs). Returns FALSE on error.
* FILEs).
* @throws Oci8Exception
*
*/
function oci_result($statement, $field)
function oci_result($statement, $field): string
{
error_clear_last();
$result = \oci_result($statement, $field);
Expand Down Expand Up @@ -1686,14 +1686,7 @@ function oci_set_prefetch($statement, int $rows): void
*
*
*
* UNKNOWN
*
*
*
*
*
*
* Returns FALSE on error.
* UNKNOW.
* @throws Oci8Exception
*
*/
Expand Down
9 changes: 4 additions & 5 deletions generated/pgsql.php
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ function pg_last_error($connection = null): string
* @throws PgsqlException
*
*/
function pg_last_notice($connection, int $option = PGSQL_NOTICE_LAST)
function pg_last_notice($connection, int $option = PGSQL_NOTICE_LAST): string
{
error_clear_last();
$result = \pg_last_notice($connection, $option);
Expand Down Expand Up @@ -1485,11 +1485,11 @@ function pg_query($connection = null, string $query = null)
* PGSQL_DIAG_CONTEXT, PGSQL_DIAG_SOURCE_FILE,
* PGSQL_DIAG_SOURCE_LINE or
* PGSQL_DIAG_SOURCE_FUNCTION.
* @return string|null A string containing the contents of the error field.
* @return string|null A string containing the contents of the error field, NULL if the field does not exist.
* @throws PgsqlException
*
*/
function pg_result_error_field($result, int $fieldcode): string
function pg_result_error_field($result, int $fieldcode): ?string
{
error_clear_last();
$result = \pg_result_error_field($result, $fieldcode);
Expand Down Expand Up @@ -1859,8 +1859,7 @@ function pg_update($connection, string $table_name, array $data, array $conditio
* is used. The default connection is the last connection made by
* pg_connect or pg_pconnect.
* @return array Returns an array with client, protocol
* and server keys and values (if available). Returns
* FALSE on error or invalid connection.
* and server keys and values (if available) or invalid connection.
* @throws PgsqlException
*
*/
Expand Down
6 changes: 3 additions & 3 deletions generated/sockets.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function socket_accept($socket)
* value of this function may be used with socket_listen.
*
* @param resource $addr Resource created from socket_addrinfo_lookup().
* @return resource|null Returns a Socket resource on success or NULL on failure.
* @return resource Returns a Socket resource on success.
* @throws SocketsException
*
*/
Expand All @@ -70,7 +70,7 @@ function socket_addrinfo_bind($addr)
* value of this function may be used with the rest of the socket functions.
*
* @param resource $addr Resource created from socket_addrinfo_lookup()
* @return resource|null Returns a Socket resource on success or NULL on failure.
* @return resource Returns a Socket resource on success.
* @throws SocketsException
*
*/
Expand Down Expand Up @@ -380,7 +380,7 @@ function socket_getsockname($socket, ?string &$addr, ?int &$port = null): void
* Imports a stream that encapsulates a socket into a socket extension resource.
*
* @param resource $stream The stream resource to import.
* @return resource Returns FALSE or NULL on failure.
* @return resource|false Returns FALSE.
* @throws SocketsException
*
*/
Expand Down
6 changes: 3 additions & 3 deletions generated/sqlsrv.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ function sqlsrv_get_field($stmt, int $fieldIndex, int $getAsType = null)
* @throws SqlsrvException
*
*/
function sqlsrv_next_result($stmt)
function sqlsrv_next_result($stmt): ?bool
{
error_clear_last();
$result = \sqlsrv_next_result($stmt);
Expand All @@ -297,7 +297,7 @@ function sqlsrv_next_result($stmt)
* @throws SqlsrvException
*
*/
function sqlsrv_num_fields($stmt)
function sqlsrv_num_fields($stmt): int
{
error_clear_last();
$result = \sqlsrv_num_fields($stmt);
Expand Down Expand Up @@ -325,7 +325,7 @@ function sqlsrv_num_fields($stmt)
* @throws SqlsrvException
*
*/
function sqlsrv_num_rows($stmt)
function sqlsrv_num_rows($stmt): int
{
error_clear_last();
$result = \sqlsrv_num_rows($stmt);
Expand Down
2 changes: 1 addition & 1 deletion generated/stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ function stream_socket_client(string $remote_socket, int &$errno = null, string
* @throws StreamException
*
*/
function stream_socket_pair(int $domain, int $type, int $protocol): array
function stream_socket_pair(int $domain, int $type, int $protocol): iterable
{
error_clear_last();
$result = \stream_socket_pair($domain, $type, $protocol);
Expand Down
2 changes: 1 addition & 1 deletion generated/uodbc.php
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ function odbc_longreadlen($result_id, int $length): void
* see odbc_connect for details.
* @param string $query_string The query string statement being prepared.
* @return resource Returns an ODBC result identifier if the SQL command was prepared
* successfully. Returns FALSE on error.
* successfully.
* @throws UodbcException
*
*/
Expand Down
2 changes: 1 addition & 1 deletion generated/xmlrpc.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* Sets xmlrpc type, base64 or datetime, for a PHP string value.
*
* @param string|DateTime $value Value to set the type
* @param string|\DateTime $value Value to set the type
* @param string $type 'base64' or 'datetime'
* @throws XmlrpcException
*
Expand Down
11 changes: 5 additions & 6 deletions generator/src/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,22 @@ protected function execute(InputInterface $input, OutputInterface $output)

$paths = $scanner->getFunctionsPaths();

[
'functions' => $functions,
'overloadedFunctions' => $overloadedFunctions
] = $scanner->getMethods($paths);
/** @var Method[] $functions */
/** @var string[] $overloadedFunctions */
['functions' => $functions,'overloadedFunctions' => $overloadedFunctions] = $scanner->getMethods($paths);

$output->writeln('These functions have been ignored and must be dealt with manually: '.\implode(', ', $overloadedFunctions));

$fileCreator = new FileCreator();
//$fileCreator->generateXlsFile($protoFunctions, __DIR__ . '/../generated/lib.xls');
$fileCreator->generatePhpFile($functions, __DIR__ . '/../../generated/');
$fileCreator->generateFunctionsList($functions, __DIR__ . '/../../generated/functionsList.php');
$fileCreator->generateRectorFile($functions, __DIR__ . '/../../rector-migrate.yml');


$modules = [];
foreach ($functions as $function) {
$modules[$function->getModuleName()] = $function->getModuleName();
$moduleName = $function->getModuleName();
$modules[$moduleName] = $moduleName;
}

foreach ($modules as $moduleName => $foo) {
Expand Down
Loading