Conditions | 6 |
Paths | 4 |
Total Lines | 55 |
Code Lines | 25 |
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 |
||
23 | private function set_toottip_args( $args ) { |
||
24 | $args = wp_parse_args( |
||
25 | $args, |
||
26 | array( |
||
27 | // Tooltip tag. |
||
28 | 'tag' => 'span', |
||
29 | 'tag_content' => '', |
||
30 | |||
31 | // Set to link of anchor if tooltip tag is anchor. |
||
32 | 'link' => '#', |
||
33 | |||
34 | // Text for tooltip |
||
35 | 'label' => '', |
||
36 | |||
37 | // Value: top-right, top, top-left, right, left, bottom-right, bottom, bottom-left. |
||
38 | 'position' => 'top', |
||
39 | |||
40 | // Value: error, warning, info, success. |
||
41 | 'status' => '', |
||
42 | |||
43 | // Value: small, medium, large. |
||
44 | 'size' => '', |
||
45 | |||
46 | // Value: true/false. |
||
47 | 'show_always' => false, |
||
48 | |||
49 | // Value: true/false |
||
50 | 'round_edges' => false, |
||
51 | |||
52 | // Value: true/false |
||
53 | 'animate' => true, |
||
54 | |||
55 | // Attributes. |
||
56 | 'attributes' => array(), |
||
57 | |||
58 | // Value: true/false |
||
59 | 'auto_width' => true, |
||
60 | ) |
||
61 | ); |
||
62 | |||
63 | // Auto set width of tooltip. |
||
64 | if ( |
||
65 | ! empty( $args['auto_width'] ) && |
||
66 | ! empty( $args['label'] ) && |
||
67 | empty( $args['size'] ) |
||
68 | ) { |
||
69 | if ( 15 < str_word_count( $args['label'] ) ) { |
||
70 | $args['size'] = 'large'; |
||
71 | } elseif ( 7 < str_word_count( $args['label'] ) ) { |
||
72 | $args['size'] = 'medium'; |
||
73 | } |
||
74 | } |
||
75 | |||
76 | return $args; |
||
77 | } |
||
78 | |||
200 | } |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.