Conditions | 3 |
Paths | 2 |
Total Lines | 94 |
Code Lines | 72 |
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 |
||
50 | public function options() { |
||
51 | |||
52 | $options = array( |
||
53 | static::$type . '_repeatable' => array( |
||
54 | 'label' => __( 'Repeatable Field', 'pods' ), |
||
55 | 'default' => 0, |
||
56 | 'type' => 'boolean', |
||
57 | 'help' => __( 'Making a field repeatable will add controls next to the field which allows users to Add/Remove/Reorder additional values. These values are saved in the database as an array, so searching and filtering by them may require further adjustments".', 'pods' ), |
||
58 | 'boolean_yes_label' => '', |
||
59 | 'dependency' => true, |
||
60 | 'developer_mode' => true, |
||
61 | ), |
||
62 | static::$type . '_type' => array( |
||
63 | 'label' => __( 'Date Format Type', 'pods' ), |
||
64 | 'default' => 'format', |
||
65 | // Backwards compatibility |
||
66 | 'type' => 'pick', |
||
67 | 'help' => __( 'WordPress Default is the format used in Settings, General under "Date Format".', 'pods' ) . '<br>' . __( 'Predefined Format will allow you to select from a list of commonly used date formats.', 'pods' ) . '<br>' . __( 'Custom will allow you to enter your own using PHP Date/Time Strings.', 'pods' ), |
||
68 | 'data' => array( |
||
69 | 'wp' => __( 'WordPress default', 'pods' ) . ': ' . date_i18n( get_option( 'date_format' ) ), |
||
70 | 'format' => __( 'Predefined format', 'pods' ), |
||
71 | 'custom' => __( 'Custom format', 'pods' ), |
||
72 | ), |
||
73 | 'dependency' => true, |
||
74 | ), |
||
75 | static::$type . '_format_custom' => array( |
||
76 | 'label' => __( 'Date format for display', 'pods' ), |
||
77 | 'depends-on' => array( static::$type . '_type' => 'custom' ), |
||
78 | 'default' => '', |
||
79 | 'type' => 'text', |
||
80 | 'help' => sprintf( |
||
81 | '<a href="http://php.net/manual/function.date.php" target="_blank">%s</a>', |
||
82 | esc_html__( 'PHP date documentation', 'pods' ) |
||
83 | ), |
||
84 | ), |
||
85 | static::$type . '_format_custom_js' => array( |
||
86 | 'label' => __( 'Date format for input', 'pods' ), |
||
87 | 'depends-on' => array( static::$type . '_type' => 'custom' ), |
||
88 | 'default' => '', |
||
89 | 'type' => 'text', |
||
90 | 'help' => sprintf( |
||
91 | '<a href="https://api.jqueryui.com/datepicker/" target="_blank">%1$s</a><br />%2$s', |
||
92 | esc_html__( 'jQuery UI datepicker documentation', 'pods' ), |
||
93 | esc_html__( 'Leave empty to auto-generate from PHP format.', 'pods' ) |
||
94 | ), |
||
95 | ), |
||
96 | static::$type . '_format' => array( |
||
97 | 'label' => __( 'Date Format', 'pods' ), |
||
98 | 'depends-on' => array( static::$type . '_type' => 'format' ), |
||
99 | 'default' => 'mdy', |
||
100 | 'type' => 'pick', |
||
101 | 'data' => array( |
||
102 | 'mdy' => date_i18n( 'm/d/Y' ), |
||
103 | 'mdy_dash' => date_i18n( 'm-d-Y' ), |
||
104 | 'mdy_dot' => date_i18n( 'm.d.Y' ), |
||
105 | 'ymd_slash' => date_i18n( 'Y/m/d' ), |
||
106 | 'ymd_dash' => date_i18n( 'Y-m-d' ), |
||
107 | 'ymd_dot' => date_i18n( 'Y.m.d' ), |
||
108 | 'fjy' => date_i18n( 'F j, Y' ), |
||
109 | 'fjsy' => date_i18n( 'F jS, Y' ), |
||
110 | 'y' => date_i18n( 'Y' ), |
||
111 | ), |
||
112 | 'dependency' => true, |
||
113 | ), |
||
114 | static::$type . '_allow_empty' => array( |
||
115 | 'label' => __( 'Allow empty value?', 'pods' ), |
||
116 | 'default' => 1, |
||
117 | 'type' => 'boolean', |
||
118 | ), |
||
119 | static::$type . '_html5' => array( |
||
120 | 'label' => __( 'Enable HTML5 Input Field?', 'pods' ), |
||
121 | 'default' => apply_filters( 'pods_form_ui_field_html5', 0, static::$type ), |
||
122 | 'type' => 'boolean', |
||
123 | ), |
||
124 | ); |
||
125 | |||
126 | // Check if PHP DateTime::createFromFormat exists for additional supported formats |
||
127 | if ( method_exists( 'DateTime', 'createFromFormat' ) || apply_filters( 'pods_form_ui_field_datetime_custom_formatter', false ) ) { |
||
128 | $options[ static::$type . '_format' ]['data'] = array_merge( |
||
129 | $options[ static::$type . '_format' ]['data'], array( |
||
130 | 'dmy' => date_i18n( 'd/m/Y' ), |
||
131 | 'dmy_dash' => date_i18n( 'd-m-Y' ), |
||
132 | 'dmy_dot' => date_i18n( 'd.m.Y' ), |
||
133 | 'dMy' => date_i18n( 'd/M/Y' ), |
||
134 | 'dMy_dash' => date_i18n( 'd-M-Y' ), |
||
135 | ) |
||
136 | ); |
||
137 | } |
||
138 | |||
139 | $options[ static::$type . '_format' ]['data'] = apply_filters( 'pods_form_ui_field_date_format_options', $options[ static::$type . '_format' ]['data'] ); |
||
140 | $options[ static::$type . '_format' ]['default'] = apply_filters( 'pods_form_ui_field_date_format_default', $options[ static::$type . '_format' ]['default'] ); |
||
141 | |||
142 | return $options; |
||
143 | } |
||
144 | |||
163 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.