Conditions | 6 |
Paths | 20 |
Total Lines | 83 |
Code Lines | 50 |
Lines | 42 |
Ratio | 50.6 % |
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 |
||
66 | function _start_table_edit ( $form, $results = true ) { |
||
67 | $api = pods_api(); |
||
68 | $all_pods = $api->load_pods( array( 'names' => true ) ); |
||
69 | |||
70 | $pod_types = array(); |
||
71 | |||
72 | foreach ( $all_pods as $pod_name => $pod_label ) { |
||
73 | $pod_types[ $pod_name ] = $pod_label . ' (' . $pod_name . ')'; |
||
74 | } |
||
75 | ?> |
||
76 | <tr> |
||
77 | <td valign="top"> |
||
78 | <label for="pod_type"><?php _e( 'Pod', 'pods' ); ?></label> |
||
79 | </td> |
||
80 | <td> |
||
81 | <?php |
||
82 | View Code Duplication | if ( 0 < count( $all_pods ) ) |
|
83 | $form->add_drop_down( 'pod_type', $pod_types ); |
||
84 | else |
||
85 | echo '<strong class="red">' . __( 'None Found', 'pods' ) . '</strong>'; |
||
86 | ?> |
||
87 | </td> |
||
88 | </tr> |
||
89 | <tr> |
||
90 | <td valign="top"> |
||
91 | <label for="slug"><?php _e( 'Slug or ID', 'pods' ); ?></label> |
||
92 | </td> |
||
93 | <td> |
||
94 | <?php $form->add_text_box( 'slug' ); ?> |
||
95 | </td> |
||
96 | </tr> |
||
97 | |||
98 | <?php |
||
99 | View Code Duplication | if ( class_exists( 'Pods_Templates' ) ) { |
|
100 | $all_templates = (array) $api->load_templates( array() ); |
||
101 | |||
102 | $templates = array( |
||
103 | '' => '- ' . __( 'Custom Template', 'pods' ) . ' -' |
||
104 | ); |
||
105 | |||
106 | foreach ( $all_templates as $template ) { |
||
107 | $templates[ $template[ 'name' ] ] = $template[ 'name' ]; |
||
108 | } |
||
109 | ?> |
||
110 | <tr> |
||
111 | <td valign="top"> |
||
112 | <label for="template"><?php _e( 'Template', 'pods' ); ?></label> |
||
113 | </td> |
||
114 | <td> |
||
115 | <?php |
||
116 | if ( 0 < count( $all_templates ) ) |
||
117 | $form->add_drop_down( 'template', $templates ); |
||
118 | else |
||
119 | echo '<strong class="red">' . __( 'None Found', 'pods' ) . '</strong>'; |
||
120 | ?> |
||
121 | </td> |
||
122 | </tr> |
||
123 | <?php |
||
124 | } |
||
125 | else { |
||
126 | ?> |
||
127 | <tr> |
||
128 | <td valign="top"> |
||
129 | <label for="template"><?php _e( 'Template', 'pods' ); ?></label> |
||
130 | </td> |
||
131 | <td> |
||
132 | <?php $form->add_text_box( 'template' ); ?> |
||
133 | </td> |
||
134 | </tr> |
||
135 | <?php |
||
136 | } |
||
137 | ?> |
||
138 | |||
139 | <tr> |
||
140 | <td valign="top"> |
||
141 | <label for="template_custom"><?php _e( 'Custom Template', 'pods' ); ?></label> |
||
142 | </td> |
||
143 | <td> |
||
144 | <?php $form->add_text_area( 'template_custom', array( 'style' => 'width:90%; max-width:100%; min-height:100px;', 'rows' => '8' ) ); ?> |
||
145 | </td> |
||
146 | </tr> |
||
147 | <?php |
||
148 | } |
||
149 | |||
169 | new PodsBuilderModuleSingle(); |
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.