Skip to content

Commit

Permalink
Deprecated array_replace and array_replace_recursive
Browse files Browse the repository at this point in the history
  • Loading branch information
Kharhamel committed Jul 20, 2022
1 parent 0cdbee9 commit 09b43b1
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 112 deletions.
73 changes: 73 additions & 0 deletions deprecated/array.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,79 @@

use Safe\Exceptions\ArrayException;

/**
* array_replace_recursive replaces the values of
* array with the same values from all the following
* arrays. If a key from the first array exists in the second array, its value
* will be replaced by the value from the second array. If the key exists in the
* second array, and not the first, it will be created in the first array.
* If a key only exists in the first array, it will be left as is.
* If several arrays are passed for replacement, they will be processed
* in order, the later array overwriting the previous values.
*
* array_replace_recursive is recursive : it will recurse into
* arrays and apply the same process to the inner value.
*
* When the value in the first array is scalar, it will be replaced
* by the value in the second array, may it be scalar or array.
* When the value in the first array and the second array
* are both arrays, array_replace_recursive will replace
* their respective value recursively.
*
* @param array $array The array in which elements are replaced.
* @param array $replacements Arrays from which elements will be extracted.
* @return array Returns an array.
* @throws ArrayException
*
*/
function array_replace_recursive(array $array, array ...$replacements): array
{
error_clear_last();
if ($replacements !== []) {
$result = \array_replace_recursive($array, ...$replacements);
} else {
$result = \array_replace_recursive($array);
}
if ($result === null) {
throw ArrayException::createFromPhpError();
}
return $result;
}

/**
* array_replace replaces the values of
* array with values having the same keys in each of the following
* arrays. If a key from the first array exists in the second array, its value
* will be replaced by the value from the second array. If the key exists in the
* second array, and not the first, it will be created in the first array.
* If a key only exists in the first array, it will be left as is.
* If several arrays are passed for replacement, they will be processed
* in order, the later arrays overwriting the previous values.
*
* array_replace is not recursive : it will replace
* values in the first array by whatever type is in the second array.
*
* @param array $array The array in which elements are replaced.
* @param array $replacements Arrays from which elements will be extracted.
* Values from later arrays overwrite the previous values.
* @return array Returns an array.
* @throws ArrayException
*
*/
function array_replace(array $array, array ...$replacements): array
{
error_clear_last();
if ($replacements !== []) {
$result = \array_replace($array, ...$replacements);
} else {
$result = \array_replace($array);
}
if ($result === null) {
throw ArrayException::createFromPhpError();
}
return $result;
}

/**
* array_flip returns an array in flip
* order, i.e. keys from array become values and values
Expand Down
2 changes: 2 additions & 0 deletions deprecated/functionsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
'apc_load_constants',
'apc_sma_info',
'arsort',
'array_replace',
'array_replace_recursive',
'array_combine',
'array_flip',
'asort',
Expand Down
75 changes: 0 additions & 75 deletions generated/array.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,81 +4,6 @@

use Safe\Exceptions\ArrayException;

/**
* array_replace_recursive replaces the values of
* array with the same values from all the following
* arrays. If a key from the first array exists in the second array, its value
* will be replaced by the value from the second array. If the key exists in the
* second array, and not the first, it will be created in the first array.
* If a key only exists in the first array, it will be left as is.
* If several arrays are passed for replacement, they will be processed
* in order, the later array overwriting the previous values.
*
* array_replace_recursive is recursive : it will recurse into
* arrays and apply the same process to the inner value.
*
* When the value in the first array is scalar, it will be replaced
* by the value in the second array, may it be scalar or array.
* When the value in the first array and the second array
* are both arrays, array_replace_recursive will replace
* their respective value recursively.
*
* @param array $array The array in which elements are replaced.
* @param array $replacements Arrays from which elements will be extracted.
* @return array Returns an array.
* @throws ArrayException
*
*/
function array_replace_recursive(array $array, array ...$replacements): array
{
error_clear_last();
if ($replacements !== []) {
$result = \array_replace_recursive($array, ...$replacements);
} else {
$result = \array_replace_recursive($array);
}
if ($result === null) {
throw ArrayException::createFromPhpError();
}
return $result;
}


/**
* array_replace replaces the values of
* array with values having the same keys in each of the following
* arrays. If a key from the first array exists in the second array, its value
* will be replaced by the value from the second array. If the key exists in the
* second array, and not the first, it will be created in the first array.
* If a key only exists in the first array, it will be left as is.
* If several arrays are passed for replacement, they will be processed
* in order, the later arrays overwriting the previous values.
*
* array_replace is not recursive : it will replace
* values in the first array by whatever type is in the second array.
*
* @param array $array The array in which elements are replaced.
* @param array $replacements Arrays from which elements will be extracted.
* Values from later arrays overwrite the previous values.
* @return array Returns an array.
* @throws ArrayException
*
*/
function array_replace(array $array, array ...$replacements): array
{
error_clear_last();
if ($replacements !== []) {
$result = \array_replace($array, ...$replacements);
} else {
$result = \array_replace($array);
}
if ($result === null) {
throw ArrayException::createFromPhpError();
}
return $result;
}


/**
* Applies the user-defined callback function to each
* element of the array. This function will recurse
Expand Down
2 changes: 1 addition & 1 deletion generated/curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -2588,7 +2588,7 @@ function curl_multi_setopt(\CurlMultiHandle $multi_handle, int $option, $value):
*
* CURLOPT_PROXY_TLSAUTH_USERNAME
*
* Tusername to use for the HTTPS proxy TLS authentication method specified with the
* The username to use for the HTTPS proxy TLS authentication method specified with the
* CURLOPT_PROXY_TLSAUTH_TYPE option. Requires that the
* CURLOPT_PROXY_TLSAUTH_PASSWORD option to also be set.
*
Expand Down
6 changes: 3 additions & 3 deletions generated/exec.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ function passthru(string $command, ?int &$result_code = null): void
* @param int $priority The new priority value, the value of this may differ on platforms.
*
* On Unix, a low value, such as -20 means high priority
* wheras a positive value have a lower priority.
* whereas positive values have a lower priority.
*
* For Windows the priority parameter have the
* following meanings:
* For Windows the priority parameter has the
* following meaning:
* @throws ExecException
*
*/
Expand Down
11 changes: 9 additions & 2 deletions generated/filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,13 @@ function lstat(string $filename): array
* Attempts to create the directory specified by directory.
*
* @param string $directory The directory path.
* A URL can be used as a
* filename with this function if the fopen wrappers have been enabled.
* See fopen for more details on how to specify the
* filename. See the for links to information
* about what abilities the various wrappers have, notes on their usage,
* and information on any predefined variables they may
* provide.
* @param int $permissions The permissions are 0777 by default, which means the widest possible
* access. For more information on permissions, read the details
* on the chmod page.
Expand All @@ -1250,8 +1257,8 @@ function lstat(string $filename): array
* which means it should have a leading zero. The permissions is also modified
* by the current umask, which you can change using
* umask.
* @param bool $recursive Allows the creation of nested directories specified in the
* directory.
* @param bool $recursive If TRUE, then any parent directories to the directory specified will
* also be created, with the same permissions.
* @param resource $context A context stream
* resource.
* @throws FilesystemException
Expand Down
2 changes: 0 additions & 2 deletions generated/functionsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
'apcu_inc',
'apcu_sma_info',
'apc_fetch',
'array_replace',
'array_replace_recursive',
'array_walk_recursive',
'assert_options',
'base64_decode',
Expand Down
7 changes: 6 additions & 1 deletion generated/json.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@

/**
* Returns a string containing the JSON representation of the supplied
* value.
* value. If the parameter is an array or object,
* it will be serialized recursively.
*
* If a value to be serialized is an object, then by default only publicly visible
* properties will be included. Alternatively, a class may implement JsonSerializable
* to control how its values are serialized to JSON.
*
* The encoding is affected by the supplied flags
* and additionally the encoding of float values depends on the value of
Expand Down
40 changes: 20 additions & 20 deletions generated/ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,36 +239,36 @@ function ldap_exop_whoami($ldap)


/**
* Performs an extended operation on the specified link with
* reqoid the OID of the operation and
* reqdata the data.
* Performs an extended operation on the specified ldap with
* request_oid the OID of the operation and
* request_data the data.
*
* @param resource $ldap An LDAP\Connection instance, returned by ldap_connect.
* @param string $reqoid The extended operation request OID. You may use one of LDAP_EXOP_START_TLS, LDAP_EXOP_MODIFY_PASSWD, LDAP_EXOP_REFRESH, LDAP_EXOP_WHO_AM_I, LDAP_EXOP_TURN, or a string with the OID of the operation you want to send.
* @param string $reqdata The extended operation request data. May be NULL for some operations like LDAP_EXOP_WHO_AM_I, may also need to be BER encoded.
* @param array|null $serverctrls Array of LDAP Controls to send with the request.
* @param string|null $retdata Will be filled with the extended operation response data if provided.
* @param string $request_oid The extended operation request OID. You may use one of LDAP_EXOP_START_TLS, LDAP_EXOP_MODIFY_PASSWD, LDAP_EXOP_REFRESH, LDAP_EXOP_WHO_AM_I, LDAP_EXOP_TURN, or a string with the OID of the operation you want to send.
* @param string $request_data The extended operation request data. May be NULL for some operations like LDAP_EXOP_WHO_AM_I, may also need to be BER encoded.
* @param array|null $controls Array of LDAP Controls to send with the request.
* @param string|null $response_data Will be filled with the extended operation response data if provided.
* If not provided you may use ldap_parse_exop on the result object
* later to get this data.
* @param string|null $retoid Will be filled with the response OID if provided, usually equal to the request OID.
* @return resource|bool When used with retdata, returns TRUE on success.
* When used without retdata, returns a result identifier.
* @param string|null $response_oid Will be filled with the response OID if provided, usually equal to the request OID.
* @return resource|bool When used with response_data, returns TRUE on success.
* When used without response_data, returns a result identifier.
* @throws LdapException
*
*/
function ldap_exop($ldap, string $reqoid, string $reqdata = null, ?array $serverctrls = null, ?string &$retdata = null, ?string &$retoid = null)
function ldap_exop($ldap, string $request_oid, string $request_data = null, ?array $controls = null, ?string &$response_data = null, ?string &$response_oid = null)
{
error_clear_last();
if ($retoid !== null) {
$result = \ldap_exop($ldap, $reqoid, $reqdata, $serverctrls, $retdata, $retoid);
} elseif ($retdata !== null) {
$result = \ldap_exop($ldap, $reqoid, $reqdata, $serverctrls, $retdata);
} elseif ($serverctrls !== null) {
$result = \ldap_exop($ldap, $reqoid, $reqdata, $serverctrls);
} elseif ($reqdata !== null) {
$result = \ldap_exop($ldap, $reqoid, $reqdata);
if ($response_oid !== null) {
$result = \ldap_exop($ldap, $request_oid, $request_data, $controls, $response_data, $response_oid);
} elseif ($response_data !== null) {
$result = \ldap_exop($ldap, $request_oid, $request_data, $controls, $response_data);
} elseif ($controls !== null) {
$result = \ldap_exop($ldap, $request_oid, $request_data, $controls);
} elseif ($request_data !== null) {
$result = \ldap_exop($ldap, $request_oid, $request_data);
} else {
$result = \ldap_exop($ldap, $reqoid);
$result = \ldap_exop($ldap, $request_oid);
}
if ($result === false) {
throw LdapException::createFromPhpError();
Expand Down
10 changes: 6 additions & 4 deletions generated/pcntl.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
* man page for specific details.
*
* @param int $process_id If NULL, the process id of the current process is used.
* @param int $mode One of PRIO_PGRP, PRIO_USER
* or PRIO_PROCESS.
* @param int $mode One of PRIO_PGRP, PRIO_USER,
* PRIO_PROCESS,
* PRIO_DARWIN_BG or PRIO_DARWIN_THREAD.
* @return int pcntl_getpriority returns the priority of the process. A lower numerical value causes more favorable
* scheduling.
* @throws PcntlException
Expand Down Expand Up @@ -46,8 +47,9 @@ function pcntl_getpriority(int $process_id = null, int $mode = PRIO_PROCESS): in
* system types and kernel versions, please see your system's setpriority(2)
* man page for specific details.
* @param int $process_id If NULL, the process id of the current process is used.
* @param int $mode One of PRIO_PGRP, PRIO_USER
* or PRIO_PROCESS.
* @param int $mode One of PRIO_PGRP, PRIO_USER,
* PRIO_PROCESS,
* PRIO_DARWIN_BG or PRIO_DARWIN_THREAD.
* @throws PcntlException
*
*/
Expand Down
2 changes: 0 additions & 2 deletions generator/tests/DocPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ public function testDetectFalsyFunction()
public function testDetectNullsyFunction()
{
$implode = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/strings/functions/implode.xml');
$arrayReplace = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/array/functions/array-replace.xml');

$this->assertFalse($implode->detectNullsyFunction());
$this->assertTrue($arrayReplace->detectNullsyFunction());
}

public function testDetectEmptyFunction()
Expand Down
2 changes: 0 additions & 2 deletions rector-migrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
'apcu_inc' => 'Safe\apcu_inc',
'apcu_sma_info' => 'Safe\apcu_sma_info',
'apc_fetch' => 'Safe\apc_fetch',
'array_replace' => 'Safe\array_replace',
'array_replace_recursive' => 'Safe\array_replace_recursive',
'array_walk_recursive' => 'Safe\array_walk_recursive',
'assert_options' => 'Safe\assert_options',
'base64_decode' => 'Safe\base64_decode',
Expand Down

0 comments on commit 09b43b1

Please # to comment.