Skip to content

Commit

Permalink
Use constants instead of hardcoding values
Browse files Browse the repository at this point in the history
Define 3 new constants to replace string values:

- 'success' -> CONFIRMATION_TYPE_SUCCESS,
- 'warning' -> CONFIRMATION_TYPE_WARNING,
- 'failure' -> CONFIRMATION_TYPE_FAILURE.

Issue #21683
  • Loading branch information
dregad committed Sep 21, 2016
1 parent 6d4a5fe commit 750950d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
7 changes: 6 additions & 1 deletion core/constant_inc.php
Expand Up @@ -226,6 +226,11 @@
define( 'BUG_UPDATE_TYPE_REOPEN', 'reopen' );
define( 'BUG_UPDATE_TYPE_CHANGE_STATUS', 'change_status' );

# confirmation message types
define( 'CONFIRMATION_TYPE_SUCCESS', 0 );
define( 'CONFIRMATION_TYPE_WARNING', 1 );
define( 'CONFIRMATION_TYPE_FAILURE', 2 );

# error messages
define( 'ERROR_GENERIC', 0 );
define( 'ERROR_SQL', 1 );
Expand Down Expand Up @@ -623,4 +628,4 @@

# Maximum number of bugs that are treated simutaneously in export procedures,
# to keep memory usage under control. Do not exceed 1000 if using Oracle DB.
define( 'EXPORT_BLOCK_SIZE', 500 );
define( 'EXPORT_BLOCK_SIZE', 500 );
15 changes: 8 additions & 7 deletions core/html_api.php
Expand Up @@ -374,20 +374,21 @@ function html_top_banner() {
* the buttons; if label is null or unspecified,
* the default 'proceed' text will be displayed.
* @param string $p_message Message to display to the user.
* @param string $p_type One of 'success', 'warning', 'failure'
* @param string $p_type One of the constants CONFIRMATION_TYPE_SUCCESS,
* CONFIRMATION_TYPE_WARNING, CONFIRMATION_TYPE_FAILURE
* @return void
*/
function html_operation_successful_buttons( array $p_buttons, $p_message = '', $p_type = 'success' ) {
function html_operation_successful_buttons( array $p_buttons, $p_message = '', $p_type = CONFIRMATION_TYPE_SUCCESS ) {
switch( $p_type ) {
case 'failure':
case CONFIRMATION_TYPE_FAILURE:
$t_alert_css = 'alert-danger';
$t_message = lang_get( 'operation_failed' );
break;
case 'warning':
case CONFIRMATION_TYPE_WARNING:
$t_message = lang_get( 'operation_warnings' );
$t_alert_css = 'alert-warning';
break;
case 'success':
case CONFIRMATION_TYPE_SUCCESS:
default:
$t_alert_css = 'alert-success';
$t_message = lang_get( 'operation_successful' );
Expand Down Expand Up @@ -438,7 +439,7 @@ function html_operation_warning( $p_redirect_url, $p_message = '' ) {
html_operation_successful_buttons(
array( array( $p_redirect_url ) ),
$p_message,
'warning'
CONFIRMATION_TYPE_WARNING
);
}

Expand All @@ -452,7 +453,7 @@ function html_operation_failure( $p_redirect_url, $p_message = '' ) {
html_operation_successful_buttons(
array( array( $p_redirect_url ) ),
$p_message,
'failure'
CONFIRMATION_TYPE_FAILURE
);
}

Expand Down

0 comments on commit 750950d

Please sign in to comment.