| Conditions | 14 |
| Paths | 5 |
| Total Lines | 54 |
| Code Lines | 21 |
| 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 |
||
| 84 | public static function create_options() { |
||
| 85 | |||
| 86 | $default = ''; |
||
| 87 | $page = 'settings'; |
||
| 88 | $settings_pages = new Pages( $page ); |
||
| 89 | $plugin_settings = $settings_pages->get_settings(); |
||
| 90 | |||
| 91 | if ( $plugin_settings && is_array( $plugin_settings ) ) { |
||
|
|
|||
| 92 | |||
| 93 | foreach ( $plugin_settings as $id => $settings ) { |
||
| 94 | |||
| 95 | $group = 'simple-calendar_' . $page . '_' . $id; |
||
| 96 | |||
| 97 | if ( isset( $settings['sections'] ) ) { |
||
| 98 | |||
| 99 | if ( $settings['sections'] && is_array( $settings['sections'] ) ) { |
||
| 100 | |||
| 101 | foreach ( $settings['sections'] as $section_id => $section ) { |
||
| 102 | |||
| 103 | if ( isset( $section['fields'] ) ) { |
||
| 104 | |||
| 105 | if ( $section['fields'] && is_array( $section['fields'] ) ) { |
||
| 106 | |||
| 107 | foreach ( $section['fields'] as $key => $field ) { |
||
| 108 | |||
| 109 | if ( isset ( $field['type'] ) ) { |
||
| 110 | // Maybe an associative array. |
||
| 111 | if ( is_int( $key ) ) { |
||
| 112 | $default[ $section_id ] = self::get_field_default_value( $field ); |
||
| 113 | } else { |
||
| 114 | $default[ $section_id ][ $key ] = self::get_field_default_value( $field ); |
||
| 115 | } |
||
| 116 | } |
||
| 117 | |||
| 118 | } // Loop fields. |
||
| 119 | |||
| 120 | } // Are fields non empty? |
||
| 121 | |||
| 122 | } // Are there fields? |
||
| 123 | |||
| 124 | } // Loop fields sections. |
||
| 125 | |||
| 126 | } // Are sections non empty? |
||
| 127 | |||
| 128 | } // Are there sections? |
||
| 129 | |||
| 130 | add_option( $group, $default, '', true ); |
||
| 131 | |||
| 132 | // Reset before looping next settings page. |
||
| 133 | $default = ''; |
||
| 134 | } |
||
| 135 | |||
| 136 | } |
||
| 137 | } |
||
| 138 | |||
| 159 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.