From 6e2358b23208ef7e2119d95b0cea1537d9a863c8 Mon Sep 17 00:00:00 2001 From: Dries Buytaert <dries@buytaert.net> Date: Wed, 18 Jun 2008 03:36:24 +0000 Subject: [PATCH] - Patch #270045 by drewish, Susurrus: clean up return values. --- includes/batch.inc | 6 ++--- includes/cache.inc | 5 ++-- includes/common.inc | 6 ++--- includes/file.inc | 38 ++++++++++++++-------------- includes/path.inc | 2 +- includes/unicode.inc | 4 +-- modules/aggregator/aggregator.module | 6 ++--- modules/comment/comment.module | 3 ++- modules/user/user.module | 2 +- 9 files changed, 37 insertions(+), 35 deletions(-) diff --git a/includes/batch.inc b/includes/batch.inc index 798d2b3ebc7b..c489f9301ec6 100644 --- a/includes/batch.inc +++ b/includes/batch.inc @@ -179,7 +179,7 @@ function _batch_process() { include_once($current_set['file']); } - $finished = 1; + $finished = TRUE; $task_message = ''; if ((list($function, $args) = reset($current_set['operations'])) && function_exists($function)) { // Build the 'context' array, execute the function call, @@ -189,9 +189,9 @@ function _batch_process() { call_user_func_array($function, array_merge($args, array(&$batch_context))); } - if ($finished == 1) { + if ($finished == TRUE) { // Make sure this step isn't counted double when computing $current. - $finished = 0; + $finished = FALSE; // Remove the operation and clear the sandbox. array_shift($current_set['operations']); $current_set['sandbox'] = array(); diff --git a/includes/cache.inc b/includes/cache.inc index 06b03fe2cfbc..e21346a9e830 100644 --- a/includes/cache.inc +++ b/includes/cache.inc @@ -10,6 +10,7 @@ * @param $table * The table $table to store the data in. Valid core values are 'cache_filter', * 'cache_menu', 'cache_page', or 'cache' for the default cache. + * @return The cache or FALSE on failure. */ function cache_get($cid, $table = 'cache') { global $user; @@ -41,7 +42,7 @@ function cache_get($cid, $table = 'cache') { else { if ($user->cache > $cache->created) { // This cache data is too old and thus not valid for us, ignore it. - return 0; + return FALSE; } else { $cache->data = db_decode_blob($cache->data); @@ -52,7 +53,7 @@ function cache_get($cid, $table = 'cache') { } return $cache; } - return 0; + return FALSE; } /** diff --git a/includes/common.inc b/includes/common.inc index 883371ff40e7..3296d98c1068 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -819,7 +819,7 @@ function valid_email_address($mail) { $ipv4 = '[0-9]{1,3}(\.[0-9]{1,3}){3}'; $ipv6 = '[0-9a-fA-F]{1,4}(\:[0-9a-fA-F]{1,4}){7}'; - return preg_match("/^$user@($domain|(\[($ipv4|$ipv6)\]))$/", $mail); + return (bool)preg_match("/^$user@($domain|(\[($ipv4|$ipv6)\]))$/", $mail); } /** @@ -838,10 +838,10 @@ function valid_email_address($mail) { function valid_url($url, $absolute = FALSE) { $allowed_characters = '[a-z0-9\/:_\-_\.\?\$,;~=#&%\+]'; if ($absolute) { - return preg_match("/^(http|https|ftp):\/\/" . $allowed_characters . "+$/i", $url); + return (bool)preg_match("/^(http|https|ftp):\/\/" . $allowed_characters . "+$/i", $url); } else { - return preg_match("/^" . $allowed_characters . "+$/i", $url); + return (bool)preg_match("/^" . $allowed_characters . "+$/i", $url); } } diff --git a/includes/file.inc b/includes/file.inc index a01fad7788c8..2de64c10b543 100644 --- a/includes/file.inc +++ b/includes/file.inc @@ -214,7 +214,7 @@ function file_check_path(&$path) { * * @param $source A string set to the file to check. * @param $directory A string where the file should be located. - * @return 0 for invalid path or the real path of the source. + * @return FALSE for invalid path or the real path of the source. */ function file_check_location($source, $directory = '') { $check = realpath($source); @@ -227,7 +227,7 @@ function file_check_location($source, $directory = '') { } $directory = realpath($directory); if ($directory && strpos($source, $directory) !== 0) { - return 0; + return FALSE; } return $source; } @@ -262,7 +262,7 @@ function file_copy(&$source, $dest = 0, $replace = FILE_EXISTS_RENAME) { $source = is_object($source) ? $source->filepath : $source; drupal_set_message(t('The selected file %file could not be uploaded, because the destination %directory is not properly configured.', array('%file' => $source, '%directory' => $dest)), 'error'); watchdog('file system', 'The selected file %file could not be uploaded, because the destination %directory could not be found, or because its permissions do not allow the file to be written.', array('%file' => $source, '%directory' => $dest), WATCHDOG_ERROR); - return 0; + return FALSE; } // Process a file upload object. @@ -277,7 +277,7 @@ function file_copy(&$source, $dest = 0, $replace = FILE_EXISTS_RENAME) { $source = realpath($source); if (!file_exists($source)) { drupal_set_message(t('The selected file %file could not be copied, because no file by that name exists. Please check that you supplied the correct filename.', array('%file' => $source)), 'error'); - return 0; + return FALSE; } // If the destination file is not specified then use the filename of the source file. @@ -295,7 +295,7 @@ function file_copy(&$source, $dest = 0, $replace = FILE_EXISTS_RENAME) { if (!@copy($source, $dest)) { drupal_set_message(t('The selected file %file could not be copied.', array('%file' => $source)), 'error'); - return 0; + return FALSE; } // Give everyone read access so that FTP'd users or @@ -314,7 +314,7 @@ function file_copy(&$source, $dest = 0, $replace = FILE_EXISTS_RENAME) { $source = $dest; } - return 1; // Everything went ok. + return TRUE; // Everything went ok. } /** @@ -363,7 +363,7 @@ function file_destination($destination, $replace) { * - FILE_EXISTS_REPLACE - Replace the existing file * - FILE_EXISTS_RENAME - Append _{incrementing number} until the filename is unique * - FILE_EXISTS_ERROR - Do nothing and return FALSE. - * @return True for success, FALSE for failure. + * @return TRUE for success, FALSE for failure. */ function file_move(&$source, $dest = 0, $replace = FILE_EXISTS_RENAME) { $path_original = is_object($source) ? $source->filepath : $source; @@ -372,11 +372,11 @@ function file_move(&$source, $dest = 0, $replace = FILE_EXISTS_RENAME) { $path_current = is_object($source) ? $source->filepath : $source; if ($path_original == $path_current || file_delete($path_original)) { - return 1; + return TRUE; } drupal_set_message(t('The removal of the original file %file has failed.', array('%file' => $path_original)), 'error'); } - return 0; + return FALSE; } /** @@ -513,7 +513,7 @@ function file_space_used($uid = NULL) { * destination directory should overwritten. A false value will generate a * new, unique filename in the destination directory. * @return - * An object containing the file information, or 0 in the event of an error. + * An object containing the file information, or FALSE in the event of an error. */ function file_save_upload($source, $validators = array(), $dest = FALSE, $replace = FILE_EXISTS_RENAME) { global $user; @@ -540,17 +540,17 @@ function file_save_upload($source, $validators = array(), $dest = FALSE, $replac case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: drupal_set_message(t('The file %file could not be saved, because it exceeds %maxsize, the maximum allowed size for uploads.', array('%file' => $source, '%maxsize' => format_size(file_upload_max_size()))), 'error'); - return 0; + return FALSE; case UPLOAD_ERR_PARTIAL: case UPLOAD_ERR_NO_FILE: drupal_set_message(t('The file %file could not be saved, because the upload did not complete.', array('%file' => $source)), 'error'); - return 0; + return FALSE; // Unknown error default: drupal_set_message(t('The file %file could not be saved. An unknown error has occurred.', array('%file' => $source)), 'error'); - return 0; + return FALSE; } // Build the list of non-munged extensions. @@ -601,7 +601,7 @@ function file_save_upload($source, $validators = array(), $dest = FALSE, $replac $message .= ' ' . array_pop($errors); } form_set_error($source, $message); - return 0; + return FALSE; } // Move uploaded files from PHP's upload_tmp_dir to Drupal's temporary directory. @@ -610,7 +610,7 @@ function file_save_upload($source, $validators = array(), $dest = FALSE, $replac if (!move_uploaded_file($_FILES['files']['tmp_name'][$source], $file->filepath)) { form_set_error($source, t('File upload error. Could not move uploaded file.')); watchdog('file', 'Upload error. Could not move uploaded file %file to destination %destination.', array('%file' => $file->filename, '%destination' => $file->filepath)); - return 0; + return FALSE; } // If we made it this far it's safe to record this file in the database. @@ -623,7 +623,7 @@ function file_save_upload($source, $validators = array(), $dest = FALSE, $replac $upload_cache[$source] = $file; return $file; } - return 0; + return FALSE; } /** @@ -786,7 +786,7 @@ function file_validate_image_resolution(&$file, $maximum_dimensions = 0, $minimu * - FILE_EXISTS_RENAME - Append _{incrementing number} until the filename is unique * - FILE_EXISTS_ERROR - Do nothing and return FALSE. * - * @return A string containing the resulting filename or 0 on error + * @return A string containing the resulting filename or FALSE on error */ function file_save_data($data, $dest, $replace = FILE_EXISTS_RENAME) { $temp = file_directory_temp(); @@ -794,13 +794,13 @@ function file_save_data($data, $dest, $replace = FILE_EXISTS_RENAME) { $file = tempnam(realpath($temp), 'file'); if (!$fp = fopen($file, 'wb')) { drupal_set_message(t('The file could not be created.'), 'error'); - return 0; + return FALSE; } fwrite($fp, $data); fclose($fp); if (!file_move($file, $dest, $replace)) { - return 0; + return FALSE; } return $file; diff --git a/includes/path.inc b/includes/path.inc index 8f2939c3356f..fd1e3448deda 100644 --- a/includes/path.inc +++ b/includes/path.inc @@ -233,5 +233,5 @@ function drupal_match_path($path, $patterns) { if (!isset($regexps[$patterns])) { $regexps[$patterns] = '/^(' . preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1' . preg_quote(variable_get('site_frontpage', 'node'), '/') . '\2'), preg_quote($patterns, '/')) . ')$/'; } - return preg_match($regexps[$patterns], $path); + return (bool)preg_match($regexps[$patterns], $path); } diff --git a/includes/unicode.inc b/includes/unicode.inc index cb3b0a8fcff0..93a522d09baf 100644 --- a/includes/unicode.inc +++ b/includes/unicode.inc @@ -121,7 +121,7 @@ function unicode_requirements() { * @param &$data * The XML data which will be parsed later. * @return - * An XML parser object. + * An XML parser object or FALSE on error. */ function drupal_xml_parser_create(&$data) { // Default XML encoding is UTF-8 @@ -149,7 +149,7 @@ function drupal_xml_parser_create(&$data) { } else { watchdog('php', 'Could not convert XML encoding %s to UTF-8.', array('%s' => $encoding), WATCHDOG_WARNING); - return 0; + return FALSE; } } diff --git a/modules/aggregator/aggregator.module b/modules/aggregator/aggregator.module index 33796a5a9926..d75c67777173 100644 --- a/modules/aggregator/aggregator.module +++ b/modules/aggregator/aggregator.module @@ -680,7 +680,7 @@ function aggregator_parse_w3cdtf($date_str) { * @param $feed * An associative array describing the feed to be parsed. * @return - * 0 on error, 1 otherwise. + * FALSE on error, TRUE otherwise. */ function aggregator_parse_feed(&$data, $feed) { global $items, $image, $channel; @@ -699,7 +699,7 @@ function aggregator_parse_feed(&$data, $feed) { if (!xml_parse($xml_parser, $data, 1)) { watchdog('aggregator', 'The feed from %site seems to be broken, due to an error "%error" on line %line.', array('%site' => $feed['title'], '%error' => xml_error_string(xml_get_error_code($xml_parser)), '%line' => xml_get_current_line_number($xml_parser)), WATCHDOG_WARNING); drupal_set_message(t('The feed from %site seems to be broken, because of error "%error" on line %line.', array('%site' => $feed['title'], '%error' => xml_error_string(xml_get_error_code($xml_parser)), '%line' => xml_get_current_line_number($xml_parser))), 'error'); - return 0; + return FALSE; } xml_parser_free($xml_parser); @@ -801,7 +801,7 @@ function aggregator_parse_feed(&$data, $feed) { db_query('DELETE FROM {aggregator_item} WHERE fid = %d AND timestamp < %d', $feed['fid'], $age); } - return 1; + return TRUE; } /** diff --git a/modules/comment/comment.module b/modules/comment/comment.module index 635f64192c74..ce84a6e343d4 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -1129,6 +1129,7 @@ function comment_num_replies($pid) { * @param $timestamp * Time to count from (defaults to time of last user access * to node). + * @return The result or FALSE on error. */ function comment_num_new($nid, $timestamp = 0) { global $user; @@ -1146,7 +1147,7 @@ function comment_num_new($nid, $timestamp = 0) { return $result; } else { - return 0; + return FALSE; } } diff --git a/modules/user/user.module b/modules/user/user.module index 18f3dbe01370..dfaccd72dc87 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -91,7 +91,7 @@ function user_external_load($authname) { return user_load($user); } else { - return 0; + return FALSE; } } -- GitLab