@@ -219,7 +219,6 @@ static zend_result php_tidy_apply_config(TidyDoc doc, const zend_string *str_str
219
219
static zend_result _php_tidy_set_tidy_opt (TidyDoc doc , const char * optname , zval * value , uint32_t arg )
220
220
{
221
221
TidyOption opt = tidyGetOptionByName (doc , optname );
222
- zend_string * str , * tmp_str ;
223
222
zend_long lval ;
224
223
225
224
if (!opt ) {
@@ -236,36 +235,21 @@ static zend_result _php_tidy_set_tidy_opt(TidyDoc doc, const char *optname, zval
236
235
return FAILURE ;
237
236
}
238
237
239
- switch (tidyOptGetType (opt )) {
240
- case TidyString :
241
- str = zval_get_tmp_string (value , & tmp_str );
242
- if (tidyOptSetValue (doc , tidyOptGetId (opt ), ZSTR_VAL (str ))) {
243
- zend_tmp_string_release (tmp_str );
244
- return SUCCESS ;
245
- }
246
- zend_tmp_string_release (tmp_str );
247
- break ;
248
-
249
- case TidyInteger :
250
- lval = zval_get_long (value );
251
- if (tidyOptSetInt (doc , tidyOptGetId (opt ), lval )) {
252
- return SUCCESS ;
253
- }
254
- break ;
255
-
256
- case TidyBoolean :
257
- lval = zval_get_long (value );
258
- if (tidyOptSetBool (doc , tidyOptGetId (opt ), lval )) {
259
- return SUCCESS ;
260
- }
261
- break ;
262
-
263
- default :
264
- php_error_docref (NULL , E_WARNING , "Unable to determine type of configuration option" );
265
- break ;
238
+ TidyOptionType type = tidyOptGetType (opt );
239
+ if (type == TidyString ) {
240
+ zend_string * tmp_str ;
241
+ const zend_string * str = zval_get_tmp_string (value , & tmp_str );
242
+ const bool result = tidyOptSetValue (doc , tidyOptGetId (opt ), ZSTR_VAL (str ));
243
+ zend_tmp_string_release (tmp_str );
244
+ return result ? SUCCESS : FAILURE ;
245
+ } else if (type == TidyInteger ) {
246
+ lval = zval_get_long (value );
247
+ return tidyOptSetInt (doc , tidyOptGetId (opt ), lval ) ? SUCCESS : FAILURE ;
248
+ } else {
249
+ ZEND_ASSERT (type == TidyBoolean );
250
+ lval = zval_get_long (value );
251
+ return tidyOptSetBool (doc , tidyOptGetId (opt ), lval ) ? SUCCESS : FAILURE ;
266
252
}
267
-
268
- return FAILURE ;
269
253
}
270
254
271
255
static void tidy_create_node_object (zval * zv , PHPTidyDoc * ptdoc , TidyNode node )
@@ -720,28 +704,19 @@ static void *php_tidy_get_opt_val(const PHPTidyDoc *ptdoc, TidyOption opt, TidyO
720
704
{
721
705
* type = tidyOptGetType (opt );
722
706
723
- switch (* type ) {
724
- case TidyString : {
725
- const char * val = tidyOptGetValue (ptdoc -> doc , tidyOptGetId (opt ));
726
- if (val ) {
727
- return (void * ) zend_string_init (val , strlen (val ), 0 );
728
- } else {
729
- return (void * ) ZSTR_EMPTY_ALLOC ();
730
- }
707
+ if (* type == TidyString ) {
708
+ const char * val = tidyOptGetValue (ptdoc -> doc , tidyOptGetId (opt ));
709
+ if (val ) {
710
+ return (void * ) zend_string_init (val , strlen (val ), 0 );
711
+ } else {
712
+ return (void * ) ZSTR_EMPTY_ALLOC ();
731
713
}
732
- break ;
733
-
734
- case TidyInteger :
735
- return (void * ) (uintptr_t ) tidyOptGetInt (ptdoc -> doc , tidyOptGetId (opt ));
736
- break ;
737
-
738
- case TidyBoolean :
739
- return (void * ) tidyOptGetBool (ptdoc -> doc , tidyOptGetId (opt ));
740
- break ;
714
+ } else if (* type == TidyInteger ) {
715
+ return (void * ) (uintptr_t ) tidyOptGetInt (ptdoc -> doc , tidyOptGetId (opt ));
716
+ } else {
717
+ ZEND_ASSERT (* type == TidyBoolean );
718
+ return (void * ) tidyOptGetBool (ptdoc -> doc , tidyOptGetId (opt ));
741
719
}
742
-
743
- /* should not happen */
744
- return NULL ;
745
720
}
746
721
747
722
static void php_tidy_create_node (INTERNAL_FUNCTION_PARAMETERS , tidy_base_nodetypes node_type )
@@ -1322,18 +1297,10 @@ PHP_FUNCTION(tidy_getopt)
1322
1297
1323
1298
case TidyInteger :
1324
1299
RETURN_LONG ((zend_long )optval );
1325
- break ;
1326
1300
1327
1301
case TidyBoolean :
1328
1302
RETURN_BOOL (optval );
1329
- break ;
1330
-
1331
- default :
1332
- php_error_docref (NULL , E_WARNING , "Unable to determine type of configuration option" );
1333
- break ;
1334
1303
}
1335
-
1336
- RETURN_FALSE ;
1337
1304
}
1338
1305
/* }}} */
1339
1306
0 commit comments