| Conditions | 2 |
| Paths | 2 |
| Total Lines | 51 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 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 |
||
| 26 | function field_options( $field_options, $template_id, $field_id, $context, $input_type ) { |
||
| 27 | |||
| 28 | if( 'edit' === $context ) { |
||
| 29 | return $field_options; |
||
| 30 | } |
||
| 31 | |||
| 32 | // No "Link to single entry"; all the items will be links to entries! |
||
| 33 | unset( $field_options['show_as_link'] ); |
||
| 34 | |||
| 35 | $new_options = array(); |
||
| 36 | |||
| 37 | $new_options['link_format'] = array( |
||
| 38 | 'type' => 'text', |
||
| 39 | 'label' => __( 'Entry link text (required)', 'gravityview' ), |
||
| 40 | 'value' => __('Entry #{entry_id}', 'gravityview'), |
||
| 41 | 'merge_tags' => 'force', |
||
| 42 | ); |
||
| 43 | |||
| 44 | $new_options['after_link'] = array( |
||
| 45 | 'type' => 'textarea', |
||
| 46 | 'label' => __( 'Text or HTML to display after the link (optional)', 'gravityview' ), |
||
| 47 | 'desc' => __('This content will be displayed below each entry link.', 'gravityview'), |
||
| 48 | 'value' => '', |
||
| 49 | 'merge_tags' => 'force', |
||
| 50 | 'class' => 'widefat code', |
||
| 51 | ); |
||
| 52 | |||
| 53 | $new_options['page_size'] = array( |
||
| 54 | 'type' => 'number', |
||
| 55 | 'label' => __( 'Entries to Display', 'gravityview' ), |
||
| 56 | 'desc' => __( 'What is the maximum number of entries that should be shown?', 'gravityview' ), |
||
| 57 | 'value' => '10', |
||
| 58 | 'merge_tags' => false, |
||
| 59 | ); |
||
| 60 | |||
| 61 | $new_options['no_entries_hide'] = array( |
||
| 62 | 'type' => 'checkbox', |
||
| 63 | 'label' => __( 'Hide if no entries', 'gravityview' ), |
||
| 64 | 'desc' => __( 'Don\'t display this field if the entry creator has no other entries', 'gravityview' ), |
||
| 65 | 'value' => false, |
||
| 66 | ); |
||
| 67 | |||
| 68 | $new_options['no_entries_text'] = array( |
||
| 69 | 'type' => 'text', |
||
| 70 | 'label' => __( 'No Entries Text', 'gravityview' ), |
||
| 71 | 'desc' => __( 'The text that is shown if the entry creator has no other entries (and "Hide if no entries" is disabled).', 'gravityview' ), |
||
| 72 | 'value' => __( 'This user has no other entries.', 'gravityview' ), |
||
| 73 | ); |
||
| 74 | |||
| 75 | return $new_options + $field_options; |
||
| 76 | } |
||
| 77 | |||
| 81 |
This check looks for access to properties that are not accessible from the current context.
If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.