Skip to content

Commit

Permalink
fix: Archive_Zip.php. Change each to foreach
Browse files Browse the repository at this point in the history
  • Loading branch information
RyujiAMANO committed Nov 14, 2024
1 parent ec7839c commit c826d29
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions html/class/Archive_Zip.php
Original file line number Diff line number Diff line change
Expand Up @@ -686,31 +686,27 @@ public function errorCode()
* @param bool $p_with_code If true, gives the name and the int value.
* @return string The error name.
*/
public function errorName($p_with_code=false)
public function errorName($p_with_code = false)
{
$v_const_list = get_defined_constants();

// ----- Extract error constants from all const.
for (reset($v_const_list);
list($v_key, $v_value) = each($v_const_list);) {
if ('ARCHIVE_ZIP_ERR_'
== substr($v_key, 0, strlen('ARCHIVE_ZIP_ERR_'))) {

// ----- Extract error constants from all const.
$v_error_list = [];
foreach ($v_const_list as $v_key => $v_value) {
if (substr($v_key, 0, strlen('ARCHIVE_ZIP_ERR_')) === 'ARCHIVE_ZIP_ERR_') {
$v_error_list[$v_key] = $v_value;
}
}

// ----- Search the name form the code value
$v_key=array_search($this->_error_code, $v_error_list, true);
if (false != $v_key) {
$v_value = $v_key;
} else {
$v_value = 'NoName';
}


// ----- Search the name from the code value
$v_key = array_search($this->_error_code, $v_error_list, true);
$v_value = $v_key !== false ? $v_key : 'NoName';

// ----- Return the error name with or without the error code
if ($p_with_code) {
return($v_value.' ('.$this->_error_code.')');
return $v_value . ' (' . $this->_error_code . ')';
} else {
return($v_value);
return $v_value;
}
}
// }}}
Expand Down Expand Up @@ -914,7 +910,7 @@ public function _add($p_list, &$p_result_list, &$p_params)
}

// ----- Swap the file descriptor
// Here is a trick : I swap the temporary fd with the zip fd, in order to
// Here is a trick : I swap the temporary fd with the zip fd, in order to
// use the following methods on the temporary fil and not the real archive
$v_swap = $this->_zip_fd;
$this->_zip_fd = $v_zip_temp_fd;
Expand Down Expand Up @@ -1419,7 +1415,7 @@ public function _addFile($p_filename, &$p_header, $p_add_dir, $p_remove_dir, $p_
$this->_errorLog(ARCHIVE_ZIP_ERR_READ_OPEN_FAIL, "Unable to open file '$p_filename' in binary read mode");
return Archive_Zip::errorCode();
}

if ($p_params['no_compression']) {
// ----- Read the file content
$v_content_compressed = @fread($v_file, $p_header['size']);
Expand Down Expand Up @@ -3224,14 +3220,14 @@ public function _duplicate($p_archive_filename)
*/
public function _check_parameters(&$p_params, $p_default)
{

// ----- Check that param is an array
if (!is_array($p_params)) {
$this->_errorLog(ARCHIVE_ZIP_ERR_INVALID_PARAMETER,
'Unsupported parameter, waiting for an array');
return Archive_Zip::errorCode();
}

// ----- Check that all the params are valid
for (reset($p_params); list($v_key, $v_value) = each($p_params);) {
if (!isset($p_default[$v_key])) {
Expand All @@ -3248,7 +3244,7 @@ public function _check_parameters(&$p_params, $p_default)
$p_params[$v_key] = $p_default[$v_key];
}
}

// ----- Check specific parameters
$v_callback_list = [
'callback_pre_add', 'callback_post_add',
Expand Down

0 comments on commit c826d29

Please sign in to comment.