Conditions | 7 |
Paths | 48 |
Total Lines | 64 |
Lines | 12 |
Ratio | 18.75 % |
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 |
||
65 | function render_field( $field ) { |
||
66 | |||
67 | // vars |
||
68 | $o = array( 'type', 'id', 'class', 'name', 'value', 'placeholder' ); |
||
69 | $s = array( 'readonly', 'disabled' ); |
||
70 | $e = ''; |
||
71 | |||
72 | |||
73 | // maxlength |
||
74 | if( $field['maxlength'] !== "" ) { |
||
75 | |||
76 | $o[] = 'maxlength'; |
||
77 | |||
78 | } |
||
79 | |||
80 | |||
81 | // prepend |
||
82 | View Code Duplication | if( $field['prepend'] !== "" ) { |
|
83 | |||
84 | $field['class'] .= ' acf-is-prepended'; |
||
85 | $e .= '<div class="acf-input-prepend">' . $field['prepend'] . '</div>'; |
||
86 | |||
87 | } |
||
88 | |||
89 | |||
90 | // append |
||
91 | View Code Duplication | if( $field['append'] !== "" ) { |
|
92 | |||
93 | $field['class'] .= ' acf-is-appended'; |
||
94 | $e .= '<div class="acf-input-append">' . $field['append'] . '</div>'; |
||
95 | |||
96 | } |
||
97 | |||
98 | |||
99 | // populate atts |
||
100 | $atts = array(); |
||
101 | foreach( $o as $k ) { |
||
102 | |||
103 | $atts[ $k ] = $field[ $k ]; |
||
104 | |||
105 | } |
||
106 | |||
107 | |||
108 | // special atts |
||
109 | foreach( $s as $k ) { |
||
110 | |||
111 | if( $field[ $k ] ) { |
||
112 | |||
113 | $atts[ $k ] = $k; |
||
114 | |||
115 | } |
||
116 | |||
117 | } |
||
118 | |||
119 | |||
120 | // render |
||
121 | $e .= '<div class="acf-input-wrap">'; |
||
122 | $e .= '<input ' . acf_esc_attr( $atts ) . ' />'; |
||
123 | $e .= '</div>'; |
||
124 | |||
125 | |||
126 | // return |
||
127 | echo $e; |
||
128 | } |
||
129 | |||
199 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.