Conditions | 12 |
Paths | 24 |
Total Lines | 26 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
67 | final private function add_settings( $args = array() ) { |
||
68 | |||
69 | // Get the classname we'll be using to create our setting(s). |
||
70 | $classname = false; |
||
71 | if ( isset( $args['option_type'] ) && array_key_exists( $args['option_type'], $this->setting_types ) ) { |
||
72 | $classname = $this->setting_types[ $args['option_type'] ]; |
||
73 | } |
||
74 | if ( ! isset( $args['type'] ) || ! array_key_exists( $args['type'], $this->setting_types ) ) { |
||
75 | $args['type'] = 'default'; |
||
76 | } |
||
77 | $classname = ! $classname ? $this->setting_types[ $args['type'] ] : $classname; |
||
78 | |||
79 | // If settings are defined as an array, then we need to go through them |
||
80 | // and call add_setting for each one of them separately. |
||
81 | if ( isset( $args['settings'] ) && is_array( $args['settings'] ) ) { |
||
82 | |||
83 | // Make sure defaults have been defined. |
||
84 | if ( ! isset( $args['default'] ) || ! is_array( $args['default'] ) ) { |
||
85 | $args['default'] = array(); |
||
86 | } |
||
87 | foreach ( $args['settings'] as $key => $value ) { |
||
88 | $default = ( isset( $defaults[ $key ] ) ) ? $defaults[ $key ] : ''; |
||
|
|||
89 | $this->add_setting( $classname, $value, $default, $args['option_type'], $args['capability'], $args['transport'], $args['sanitize_callback'] ); |
||
90 | } |
||
91 | } |
||
92 | $this->add_setting( $classname, $args['settings'], $args['default'], $args['option_type'], $args['capability'], $args['transport'], $args['sanitize_callback'] ); |
||
93 | } |
||
152 |