diff --git a/generated/datetime.php b/generated/datetime.php index 0d997d4a..9927f06c 100644 --- a/generated/datetime.php +++ b/generated/datetime.php @@ -235,7 +235,17 @@ function date_sun_info(int $time, float $latitude, float $longitude): array function date_sunrise(int $timestamp, int $format = SUNFUNCS_RET_STRING, float $latitude = null, float $longitude = null, float $zenith = null, float $gmt_offset = 0) { error_clear_last(); - $result = \date_sunrise($timestamp, $format, $latitude, $longitude, $zenith, $gmt_offset); + if ($gmt_offset !== 0) { + $result = \date_sunrise($timestamp, $format, $latitude, $longitude, $zenith, $gmt_offset); + } elseif ($zenith !== null) { + $result = \date_sunrise($timestamp, $format, $latitude, $longitude, $zenith); + } elseif ($longitude !== null) { + $result = \date_sunrise($timestamp, $format, $latitude, $longitude); + } elseif ($latitude !== null) { + $result = \date_sunrise($timestamp, $format, $latitude); + } else { + $result = \date_sunrise($timestamp, $format); + } if ($result === false) { throw DatetimeException::createFromPhpError(); } @@ -328,7 +338,17 @@ function date_sunrise(int $timestamp, int $format = SUNFUNCS_RET_STRING, float $ function date_sunset(int $timestamp, int $format = SUNFUNCS_RET_STRING, float $latitude = null, float $longitude = null, float $zenith = null, float $gmt_offset = 0) { error_clear_last(); - $result = \date_sunset($timestamp, $format, $latitude, $longitude, $zenith, $gmt_offset); + if ($gmt_offset !== 0) { + $result = \date_sunset($timestamp, $format, $latitude, $longitude, $zenith, $gmt_offset); + } elseif ($zenith !== null) { + $result = \date_sunset($timestamp, $format, $latitude, $longitude, $zenith); + } elseif ($longitude !== null) { + $result = \date_sunset($timestamp, $format, $latitude, $longitude); + } elseif ($latitude !== null) { + $result = \date_sunset($timestamp, $format, $latitude); + } else { + $result = \date_sunset($timestamp, $format); + } if ($result === false) { throw DatetimeException::createFromPhpError(); } @@ -380,7 +400,21 @@ function date_sunset(int $timestamp, int $format = SUNFUNCS_RET_STRING, float $l function mktime(int $hour = null, int $minute = null, int $second = null, int $month = null, int $day = null, int $year = null): int { error_clear_last(); - $result = \mktime($hour, $minute, $second, $month, $day, $year); + if ($year !== null) { + $result = \mktime($hour, $minute, $second, $month, $day, $year); + } elseif ($day !== null) { + $result = \mktime($hour, $minute, $second, $month, $day); + } elseif ($month !== null) { + $result = \mktime($hour, $minute, $second, $month); + } elseif ($second !== null) { + $result = \mktime($hour, $minute, $second); + } elseif ($minute !== null) { + $result = \mktime($hour, $minute); + } elseif ($hour !== null) { + $result = \mktime($hour); + } else { + $result = \mktime(); + } if ($result === false) { throw DatetimeException::createFromPhpError(); } @@ -489,7 +523,11 @@ function strptime(string $date, string $format): array function strtotime(string $time, int $now = null): int { error_clear_last(); - $result = \strtotime($time, $now); + if ($now !== null) { + $result = \strtotime($time, $now); + } else { + $result = \strtotime($time); + } if ($result === false) { throw DatetimeException::createFromPhpError(); } diff --git a/generated/filesystem.php b/generated/filesystem.php index d93af778..1250afde 100644 --- a/generated/filesystem.php +++ b/generated/filesystem.php @@ -1346,8 +1346,10 @@ function touch(string $filename, int $time = null, int $atime = null): void error_clear_last(); if ($atime !== null) { $result = \touch($filename, $time, $atime); - } else { + } elseif ($time !== null) { $result = \touch($filename, $time); + } else { + $result = \touch($filename); } if ($result === false) { throw FilesystemException::createFromPhpError(); diff --git a/generated/functionsList.php b/generated/functionsList.php index d5624bb2..1a19ca79 100644 --- a/generated/functionsList.php +++ b/generated/functionsList.php @@ -860,6 +860,7 @@ 'pspell_config_repl', 'pspell_config_runtogether', 'pspell_config_save_repl', + 'pspell_new_config', 'pspell_new', 'pspell_save_wordlist', 'pspell_store_replacement', diff --git a/generated/ldap.php b/generated/ldap.php index 9b641994..38adffb9 100644 --- a/generated/ldap.php +++ b/generated/ldap.php @@ -800,7 +800,21 @@ function ldap_get_values($link_identifier, $result_entry_identifier, string $att function ldap_list($link_identifier, string $base_dn, string $filter, array $attributes = null, int $attrsonly = 0, int $sizelimit = -1, int $timelimit = -1, int $deref = LDAP_DEREF_NEVER, array $serverctrls = null) { error_clear_last(); - $result = \ldap_list($link_identifier, $base_dn, $filter, $attributes, $attrsonly, $sizelimit, $timelimit, $deref, $serverctrls); + if ($serverctrls !== null) { + $result = \ldap_list($link_identifier, $base_dn, $filter, $attributes, $attrsonly, $sizelimit, $timelimit, $deref, $serverctrls); + } elseif ($deref !== LDAP_DEREF_NEVER) { + $result = \ldap_list($link_identifier, $base_dn, $filter, $attributes, $attrsonly, $sizelimit, $timelimit, $deref); + } elseif ($timelimit !== -1) { + $result = \ldap_list($link_identifier, $base_dn, $filter, $attributes, $attrsonly, $sizelimit, $timelimit); + } elseif ($sizelimit !== -1) { + $result = \ldap_list($link_identifier, $base_dn, $filter, $attributes, $attrsonly, $sizelimit); + } elseif ($attrsonly !== 0) { + $result = \ldap_list($link_identifier, $base_dn, $filter, $attributes, $attrsonly); + } elseif ($attributes !== null) { + $result = \ldap_list($link_identifier, $base_dn, $filter, $attributes); + } else { + $result = \ldap_list($link_identifier, $base_dn, $filter); + } if ($result === false) { throw LdapException::createFromPhpError(); } @@ -1181,7 +1195,21 @@ function ldap_parse_result($link, $result, int &$errcode, string &$matcheddn = n function ldap_read($link_identifier, string $base_dn, string $filter, array $attributes = null, int $attrsonly = 0, int $sizelimit = -1, int $timelimit = -1, int $deref = LDAP_DEREF_NEVER, array $serverctrls = null) { error_clear_last(); - $result = \ldap_read($link_identifier, $base_dn, $filter, $attributes, $attrsonly, $sizelimit, $timelimit, $deref, $serverctrls); + if ($serverctrls !== null) { + $result = \ldap_read($link_identifier, $base_dn, $filter, $attributes, $attrsonly, $sizelimit, $timelimit, $deref, $serverctrls); + } elseif ($deref !== LDAP_DEREF_NEVER) { + $result = \ldap_read($link_identifier, $base_dn, $filter, $attributes, $attrsonly, $sizelimit, $timelimit, $deref); + } elseif ($timelimit !== -1) { + $result = \ldap_read($link_identifier, $base_dn, $filter, $attributes, $attrsonly, $sizelimit, $timelimit); + } elseif ($sizelimit !== -1) { + $result = \ldap_read($link_identifier, $base_dn, $filter, $attributes, $attrsonly, $sizelimit); + } elseif ($attrsonly !== 0) { + $result = \ldap_read($link_identifier, $base_dn, $filter, $attributes, $attrsonly); + } elseif ($attributes !== null) { + $result = \ldap_read($link_identifier, $base_dn, $filter, $attributes); + } else { + $result = \ldap_read($link_identifier, $base_dn, $filter); + } if ($result === false) { throw LdapException::createFromPhpError(); } @@ -1349,7 +1377,21 @@ function ldap_sasl_bind($link, string $binddn = null, string $password = null, s function ldap_search($link_identifier, string $base_dn, string $filter, array $attributes = null, int $attrsonly = 0, int $sizelimit = -1, int $timelimit = -1, int $deref = LDAP_DEREF_NEVER, array $serverctrls = null) { error_clear_last(); - $result = \ldap_search($link_identifier, $base_dn, $filter, $attributes, $attrsonly, $sizelimit, $timelimit, $deref, $serverctrls); + if ($serverctrls !== null) { + $result = \ldap_search($link_identifier, $base_dn, $filter, $attributes, $attrsonly, $sizelimit, $timelimit, $deref, $serverctrls); + } elseif ($deref !== LDAP_DEREF_NEVER) { + $result = \ldap_search($link_identifier, $base_dn, $filter, $attributes, $attrsonly, $sizelimit, $timelimit, $deref); + } elseif ($timelimit !== -1) { + $result = \ldap_search($link_identifier, $base_dn, $filter, $attributes, $attrsonly, $sizelimit, $timelimit); + } elseif ($sizelimit !== -1) { + $result = \ldap_search($link_identifier, $base_dn, $filter, $attributes, $attrsonly, $sizelimit); + } elseif ($attrsonly !== 0) { + $result = \ldap_search($link_identifier, $base_dn, $filter, $attributes, $attrsonly); + } elseif ($attributes !== null) { + $result = \ldap_search($link_identifier, $base_dn, $filter, $attributes); + } else { + $result = \ldap_search($link_identifier, $base_dn, $filter); + } if ($result === false) { throw LdapException::createFromPhpError(); } diff --git a/generated/mbstring.php b/generated/mbstring.php index 0a66fe93..4530b070 100644 --- a/generated/mbstring.php +++ b/generated/mbstring.php @@ -17,7 +17,11 @@ function mb_check_encoding(string $var = null, string $encoding = null): void { error_clear_last(); - $result = \mb_check_encoding($var, $encoding); + if ($encoding !== null) { + $result = \mb_check_encoding($var, $encoding); + } else { + $result = \mb_check_encoding($var); + } if ($result === false) { throw MbstringException::createFromPhpError(); } @@ -80,7 +84,11 @@ function mb_chr(int $cp, string $encoding = null): string function mb_detect_order($encoding_list = null) { error_clear_last(); - $result = \mb_detect_order($encoding_list); + if ($encoding_list !== null) { + $result = \mb_detect_order($encoding_list); + } else { + $result = \mb_detect_order(); + } if ($result === false) { throw MbstringException::createFromPhpError(); } @@ -309,7 +317,11 @@ function mb_eregi_replace(string $pattern, string $replace, string $string, stri function mb_http_output(string $encoding = null) { error_clear_last(); - $result = \mb_http_output($encoding); + if ($encoding !== null) { + $result = \mb_http_output($encoding); + } else { + $result = \mb_http_output(); + } if ($result === false) { throw MbstringException::createFromPhpError(); } @@ -336,7 +348,11 @@ function mb_http_output(string $encoding = null) function mb_internal_encoding(string $encoding = null) { error_clear_last(); - $result = \mb_internal_encoding($encoding); + if ($encoding !== null) { + $result = \mb_internal_encoding($encoding); + } else { + $result = \mb_internal_encoding(); + } if ($result === false) { throw MbstringException::createFromPhpError(); } @@ -404,7 +420,11 @@ function mb_parse_str(string $encoded_string, array &$result = null): void function mb_regex_encoding(string $encoding = null) { error_clear_last(); - $result = \mb_regex_encoding($encoding); + if ($encoding !== null) { + $result = \mb_regex_encoding($encoding); + } else { + $result = \mb_regex_encoding(); + } if ($result === false) { throw MbstringException::createFromPhpError(); } diff --git a/generated/mysql.php b/generated/mysql.php index eda4d388..c73ab4ee 100644 --- a/generated/mysql.php +++ b/generated/mysql.php @@ -76,7 +76,19 @@ function mysql_close($link_identifier = null): void function mysql_connect(string $server = null, string $username = null, string $password = null, bool $new_link = false, int $client_flags = 0) { error_clear_last(); - $result = \mysql_connect($server, $username, $password, $new_link, $client_flags); + if ($client_flags !== 0) { + $result = \mysql_connect($server, $username, $password, $new_link, $client_flags); + } elseif ($new_link !== false) { + $result = \mysql_connect($server, $username, $password, $new_link); + } elseif ($password !== null) { + $result = \mysql_connect($server, $username, $password); + } elseif ($username !== null) { + $result = \mysql_connect($server, $username); + } elseif ($server !== null) { + $result = \mysql_connect($server); + } else { + $result = \mysql_connect(); + } if ($result === false) { throw MysqlException::createFromPhpError(); } diff --git a/generated/network.php b/generated/network.php index 95356800..8da5fdff 100644 --- a/generated/network.php +++ b/generated/network.php @@ -304,7 +304,11 @@ function dns_get_record(string $hostname, int $type = DNS_ANY, array &$authns = function fsockopen(string $hostname, int $port = -1, int &$errno = null, string &$errstr = null, float $timeout = null) { error_clear_last(); - $result = \fsockopen($hostname, $port, $errno, $errstr, $timeout); + if ($timeout !== null) { + $result = \fsockopen($hostname, $port, $errno, $errstr, $timeout); + } else { + $result = \fsockopen($hostname, $port, $errno, $errstr); + } if ($result === false) { throw NetworkException::createFromPhpError(); } diff --git a/generated/pcntl.php b/generated/pcntl.php index 0bac61b4..784ab6f9 100644 --- a/generated/pcntl.php +++ b/generated/pcntl.php @@ -54,7 +54,13 @@ function pcntl_exec(string $path, array $args = null, array $envs = null): void function pcntl_getpriority(int $pid = null, int $process_identifier = PRIO_PROCESS): int { error_clear_last(); - $result = \pcntl_getpriority($pid, $process_identifier); + if ($process_identifier !== PRIO_PROCESS) { + $result = \pcntl_getpriority($pid, $process_identifier); + } elseif ($pid !== null) { + $result = \pcntl_getpriority($pid); + } else { + $result = \pcntl_getpriority(); + } if ($result === false) { throw PcntlException::createFromPhpError(); } @@ -81,7 +87,13 @@ function pcntl_getpriority(int $pid = null, int $process_identifier = PRIO_PROCE function pcntl_setpriority(int $priority, int $pid = null, int $process_identifier = PRIO_PROCESS): void { error_clear_last(); - $result = \pcntl_setpriority($priority, $pid, $process_identifier); + if ($process_identifier !== PRIO_PROCESS) { + $result = \pcntl_setpriority($priority, $pid, $process_identifier); + } elseif ($pid !== null) { + $result = \pcntl_setpriority($priority, $pid); + } else { + $result = \pcntl_setpriority($priority); + } if ($result === false) { throw PcntlException::createFromPhpError(); } diff --git a/generated/pspell.php b/generated/pspell.php index ae6f028b..76b1add7 100644 --- a/generated/pspell.php +++ b/generated/pspell.php @@ -310,6 +310,26 @@ function pspell_config_save_repl(int $dictionary_link, bool $flag): void } +/** + * + * + * @param int $config The config parameter is the one returned by + * pspell_config_create when the config was created. + * @return int Returns a dictionary link identifier on success, . + * @throws PspellException + * + */ +function pspell_new_config(int $config): int +{ + error_clear_last(); + $result = \pspell_new_config($config); + if ($result === false) { + throw PspellException::createFromPhpError(); + } + return $result; +} + + /** * pspell_new opens up a new dictionary and * returns the dictionary link identifier for use in other pspell diff --git a/generated/stream.php b/generated/stream.php index 4d044104..eea73b9d 100644 --- a/generated/stream.php +++ b/generated/stream.php @@ -334,7 +334,13 @@ function stream_set_timeout($stream, int $seconds, int $microseconds = 0): void function stream_socket_accept($server_socket, float $timeout = null, string &$peername = null) { error_clear_last(); - $result = \stream_socket_accept($server_socket, $timeout, $peername); + if ($peername !== null) { + $result = \stream_socket_accept($server_socket, $timeout, $peername); + } elseif ($timeout !== null) { + $result = \stream_socket_accept($server_socket, $timeout); + } else { + $result = \stream_socket_accept($server_socket); + } if ($result === false) { throw StreamException::createFromPhpError(); } @@ -396,8 +402,12 @@ function stream_socket_client(string $remote_socket, int &$errno = null, string error_clear_last(); if ($context !== null) { $result = \stream_socket_client($remote_socket, $errno, $errstr, $timeout, $flags, $context); - } else { + } elseif ($flags !== STREAM_CLIENT_CONNECT) { $result = \stream_socket_client($remote_socket, $errno, $errstr, $timeout, $flags); + } elseif ($timeout !== null) { + $result = \stream_socket_client($remote_socket, $errno, $errstr, $timeout); + } else { + $result = \stream_socket_client($remote_socket, $errno, $errstr); } if ($result === false) { throw StreamException::createFromPhpError(); diff --git a/generator/src/Parameter.php b/generator/src/Parameter.php index 171eb8de..06095b4e 100644 --- a/generator/src/Parameter.php +++ b/generator/src/Parameter.php @@ -76,7 +76,19 @@ public function isByReference(): bool */ public function isOptionalWithNoDefault(): bool { - return ((string)$this->parameter['choice']) === 'opt' && !$this->hasDefaultValue(); + if (((string)$this->parameter['choice']) !== 'opt') { + return false; + } + if (!$this->hasDefaultValue()) { + return true; + } + + $initializer = $this->getInitializer(); + // Some default value have weird values. For instance, first parameter of "mb_internal_encoding" has default value "mb_internal_encoding()" + if ($initializer !== 'array()' && strpos($initializer, '(') !== false) { + return true; + } + return false; } public function isVariadic(): bool diff --git a/generator/tests/GeneratedFilesTest.php b/generator/tests/GeneratedFilesTest.php index 7dcdbc9f..5c85d1f7 100644 --- a/generator/tests/GeneratedFilesTest.php +++ b/generator/tests/GeneratedFilesTest.php @@ -88,4 +88,18 @@ public function testPregSplit() $keywords = preg_split("/[\s,]+/", "hypertext language, programming", null); $this->assertSame(['hypertext', 'language', 'programming'], $keywords); } + + + /** + * Tests that parameters with "time()" default value are correctly handled. + */ + public function testStrtotime() + { + require_once __DIR__.'/../../generated/datetime.php'; + require_once __DIR__.'/../../lib/Exceptions/SafeExceptionInterface.php'; + require_once __DIR__.'/../../lib/Exceptions/AbstractSafeException.php'; + require_once __DIR__.'/../../generated/Exceptions/DatetimeException.php'; + + $this->assertSame(\strtotime('+1 day'), strtotime('+1 day')); + } } diff --git a/rector-migrate.yml b/rector-migrate.yml index c9834200..05c62fb5 100644 --- a/rector-migrate.yml +++ b/rector-migrate.yml @@ -861,6 +861,7 @@ services: pspell_config_repl: 'Safe\pspell_config_repl' pspell_config_runtogether: 'Safe\pspell_config_runtogether' pspell_config_save_repl: 'Safe\pspell_config_save_repl' + pspell_new_config: 'Safe\pspell_new_config' pspell_new: 'Safe\pspell_new' pspell_save_wordlist: 'Safe\pspell_save_wordlist' pspell_store_replacement: 'Safe\pspell_store_replacement'