| Conditions | 20 |
| Paths | 16 |
| Total Lines | 74 |
| Code Lines | 31 |
| 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 |
||
| 121 | public function register_settings( $settings = array() ) { |
||
| 122 | |||
| 123 | $settings = $settings ? $settings : $this->get_settings(); |
||
| 124 | |||
| 125 | if ( ! empty( $settings ) && is_array( $settings ) ) { |
||
| 126 | |||
| 127 | foreach ( $settings as $tab_id => $settings_page ) { |
||
| 128 | |||
| 129 | if ( isset( $settings_page['sections'] ) ) { |
||
| 130 | |||
| 131 | $sections = $settings_page['sections']; |
||
| 132 | |||
| 133 | if ( ! empty( $sections ) && is_array( $sections ) ) { |
||
| 134 | |||
| 135 | foreach ( $sections as $section_id => $section ) { |
||
| 136 | |||
| 137 | add_settings_section( |
||
| 138 | $section_id, |
||
| 139 | isset( $section['title'] ) ? $section['title'] : '', |
||
| 140 | isset( $section['callback'] ) ? $section['callback'] : '', |
||
| 141 | 'simple-calendar_' . $this->page . '_' . $tab_id |
||
| 142 | ); |
||
| 143 | |||
| 144 | if ( isset( $section['fields'] ) ) { |
||
| 145 | |||
| 146 | $fields = $section['fields']; |
||
| 147 | |||
| 148 | if ( ! empty( $fields ) && is_array( $fields ) ) { |
||
| 149 | |||
| 150 | foreach ( $fields as $field ) { |
||
| 151 | |||
| 152 | if ( isset( $field['id'] ) && isset( $field['type'] ) ) { |
||
| 153 | |||
| 154 | $field_object = simcal_get_field( $field, $field['type'] ); |
||
| 155 | |||
| 156 | if ( $field_object instanceof Field ) { |
||
| 157 | |||
| 158 | add_settings_field( |
||
| 159 | $field['id'], |
||
| 160 | isset( $field['title'] ) ? $field['title'] : '', |
||
| 161 | array( $field_object, 'html' ), |
||
| 162 | 'simple-calendar_' . $this->page . '_' . $tab_id, |
||
| 163 | $section_id |
||
| 164 | ); |
||
| 165 | |||
| 166 | } // add field |
||
| 167 | |||
| 168 | } // is field valid? |
||
| 169 | |||
| 170 | } // loop fields |
||
| 171 | |||
| 172 | } // are fields non empty? |
||
| 173 | |||
| 174 | } // are there fields? |
||
| 175 | |||
| 176 | $page = simcal_get_admin_page( $tab_id ); |
||
| 177 | |||
| 178 | register_setting( |
||
| 179 | 'simple-calendar_' . $this->page . '_' . $tab_id, |
||
| 180 | 'simple-calendar_' . $this->page . '_' . $tab_id, |
||
| 181 | $page instanceof Admin_Page ? array( $page, 'validate' ) : '' |
||
| 182 | ); |
||
| 183 | |||
| 184 | } // loop sections |
||
| 185 | |||
| 186 | } // are sections non empty? |
||
| 187 | |||
| 188 | } // are there sections? |
||
| 189 | |||
| 190 | } // loop settings |
||
| 191 | |||
| 192 | } // are there settings? |
||
| 193 | |||
| 194 | } |
||
| 195 | |||
| 271 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: