| Conditions | 2 |
| Paths | 2 |
| Total Lines | 56 |
| Code Lines | 47 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 6 |
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 |
||
| 97 | protected static function localize( $debug ) { |
||
| 98 | static $localized = false; |
||
| 99 | if ( $localized ) { |
||
| 100 | return; |
||
| 101 | } |
||
| 102 | |||
| 103 | $localized = true; |
||
| 104 | $l10n = array( |
||
| 105 | 'ajax_nonce' => wp_create_nonce( 'ajax_nonce' ), |
||
| 106 | 'ajaxurl' => admin_url( '/admin-ajax.php' ), |
||
| 107 | 'script_debug' => $debug, |
||
| 108 | 'up_arrow_class' => 'dashicons dashicons-arrow-up-alt2', |
||
| 109 | 'down_arrow_class' => 'dashicons dashicons-arrow-down-alt2', |
||
| 110 | 'defaults' => array( |
||
| 111 | 'color_picker' => false, |
||
| 112 | 'date_picker' => array( |
||
| 113 | 'changeMonth' => true, |
||
| 114 | 'changeYear' => true, |
||
| 115 | 'dateFormat' => _x( 'mm/dd/yy', 'Valid formatDate string for jquery-ui datepicker', 'cmb2' ), |
||
| 116 | 'dayNames' => explode( ',', __( 'Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday', 'cmb2' ) ), |
||
| 117 | 'dayNamesMin' => explode( ',', __( 'Su, Mo, Tu, We, Th, Fr, Sa', 'cmb2' ) ), |
||
| 118 | 'dayNamesShort' => explode( ',', __( 'Sun, Mon, Tue, Wed, Thu, Fri, Sat', 'cmb2' ) ), |
||
| 119 | 'monthNames' => explode( ',', __( 'January, February, March, April, May, June, July, August, September, October, November, December', 'cmb2' ) ), |
||
| 120 | 'monthNamesShort' => explode( ',', __( 'Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec', 'cmb2' ) ), |
||
| 121 | 'nextText' => __( 'Next', 'cmb2' ), |
||
| 122 | 'prevText' => __( 'Prev', 'cmb2' ), |
||
| 123 | 'currentText' => __( 'Today', 'cmb2' ), |
||
| 124 | 'closeText' => __( 'Done', 'cmb2' ), |
||
| 125 | 'clearText' => __( 'Clear', 'cmb2' ), |
||
| 126 | ), |
||
| 127 | 'time_picker' => array( |
||
| 128 | 'timeOnlyTitle' => __( 'Choose Time', 'cmb2' ), |
||
| 129 | 'timeText' => __( 'Time', 'cmb2' ), |
||
| 130 | 'hourText' => __( 'Hour', 'cmb2' ), |
||
| 131 | 'minuteText' => __( 'Minute', 'cmb2' ), |
||
| 132 | 'secondText' => __( 'Second', 'cmb2' ), |
||
| 133 | 'currentText' => __( 'Now', 'cmb2' ), |
||
| 134 | 'closeText' => __( 'Done', 'cmb2' ), |
||
| 135 | 'timeFormat' => _x( 'hh:mm TT', 'Valid formatting string, as per http://trentrichardson.com/examples/timepicker/', 'cmb2' ), |
||
| 136 | 'controlType' => 'select', |
||
| 137 | 'stepMinute' => 5, |
||
| 138 | ), |
||
| 139 | ), |
||
| 140 | 'strings' => array( |
||
| 141 | 'upload_file' => __( 'Use this file', 'cmb2' ), |
||
| 142 | 'upload_files' => __( 'Use these files', 'cmb2' ), |
||
| 143 | 'remove_image' => __( 'Remove Image', 'cmb2' ), |
||
| 144 | 'remove_file' => __( 'Remove', 'cmb2' ), |
||
| 145 | 'file' => __( 'File:', 'cmb2' ), |
||
| 146 | 'download' => __( 'Download', 'cmb2' ), |
||
| 147 | 'check_toggle' => __( 'Select / Deselect All', 'cmb2' ), |
||
| 148 | ), |
||
| 149 | ); |
||
| 150 | |||
| 151 | wp_localize_script( self::$handle, self::$js_variable, apply_filters( 'cmb2_localized_data', $l10n ) ); |
||
| 152 | } |
||
| 153 | |||
| 155 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.