| Conditions | 1 |
| Paths | 1 |
| Total Lines | 55 |
| Code Lines | 29 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 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 |
||
| 11 | public function __construct() { |
||
| 12 | |||
| 13 | $options = array( |
||
| 14 | 'textdomain' => 'super-duper', |
||
| 15 | // textdomain of the plugin/theme (used to prefix the Gutenberg block) |
||
| 16 | 'block-icon' => 'fas fa-globe-americas', |
||
| 17 | // Dash icon name for the block: https://developer.wordpress.org/resource/dashicons/#arrow-right |
||
| 18 | // OR font-awesome 5 class name: fas fa-globe-americas |
||
| 19 | 'block-category' => 'widgets', |
||
| 20 | // the category for the block, 'common', 'formatting', 'layout', 'widgets', 'embed'. |
||
| 21 | 'block-keywords' => "['hello','world']", |
||
| 22 | // used in the block search, MAX 3 |
||
| 23 | 'block-output' => array( // the block visual output elements as an array |
||
| 24 | array( |
||
| 25 | 'element' => 'p', |
||
| 26 | 'title' => __( 'Placeholder', 'hello-world' ), |
||
| 27 | 'class' => '[%className%]', |
||
| 28 | 'content' => 'Hello: [%after_text%]' // block properties can be added by wrapping them in [%name%] |
||
| 29 | ) |
||
| 30 | ), |
||
| 31 | 'block-wrap' => '', // You can specify the type of element to wrap the block `div` or `span` etc.. Or blank for no wrap at all. |
||
| 32 | 'class_name' => __CLASS__, |
||
| 33 | // The calling class name |
||
| 34 | 'base_id' => 'hello_world', |
||
| 35 | // this is used as the widget id and the shortcode id. |
||
| 36 | 'name' => __( 'Hello World', 'hello-world' ), |
||
| 37 | // the name of the widget/block |
||
| 38 | 'widget_ops' => array( |
||
| 39 | 'classname' => 'hello-world-class', |
||
| 40 | // widget class |
||
| 41 | 'description' => esc_html__( 'This is an example that will take a text parameter and output it after `Hello:`.', 'hello-world' ), |
||
| 42 | // widget description |
||
| 43 | ), |
||
| 44 | 'no_wrap' => true, // This will prevent the widget being wrapped in the containing widget class div. |
||
| 45 | 'arguments' => array( // these are the arguments that will be used in the widget, shortcode and block settings. |
||
| 46 | 'after_text' => array( // this is the input name='' |
||
| 47 | 'title' => __( 'Text after hello:', 'hello-world' ), |
||
| 48 | // input title |
||
| 49 | 'desc' => __( 'This is the text that will appear after `Hello:`.', 'hello-world' ), |
||
| 50 | // input description |
||
| 51 | 'type' => 'text', |
||
| 52 | // the type of input, test, select, checkbox etc. |
||
| 53 | 'placeholder' => 'World', |
||
| 54 | // the input placeholder text. |
||
| 55 | 'desc_tip' => true, |
||
| 56 | // if the input should show the widget description text as a tooltip. |
||
| 57 | 'default' => 'World', |
||
| 58 | // the input default value. |
||
| 59 | 'advanced' => false |
||
| 60 | // not yet implemented |
||
| 61 | ), |
||
| 62 | ) |
||
| 63 | ); |
||
| 64 | |||
| 65 | parent::__construct( $options ); |
||
| 66 | } |
||
| 136 | //add_filter( 'wp_super_duper_options_hello_world', '_my_extra_arguments' ); |