Conditions | 20 |
Paths | 6150 |
Total Lines | 64 |
Code Lines | 42 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
67 | public function save( $args ) { |
||
68 | if ( ! isset( $args['table'] ) || ! current_user_can( 'promote_users' ) ) { |
||
69 | $url = admin_url( 'admin.php?page=tabulate' ); |
||
70 | wp_safe_redirect( $url ); |
||
71 | exit; |
||
72 | } |
||
73 | $db = new Database( $this->wpdb ); |
||
74 | $table = $db->get_table( $args['table'] ); |
||
75 | if ( isset( $args['delete'] ) ) { |
||
76 | wp_safe_redirect( $table->get_url( 'delete', null, 'schema' ) ); |
||
77 | exit; |
||
78 | } |
||
79 | |||
80 | // Rename. |
||
81 | $new_name = $args['table']; |
||
82 | if ( $table instanceof Table && ! empty( $args['new_name'] ) ) { |
||
83 | $table->rename( $args['new_name'] ); |
||
84 | $new_name = $table->get_name(); |
||
85 | } |
||
86 | |||
87 | // Set comment. |
||
88 | if ( isset( $args['new_comment'] ) ) { |
||
89 | $table->set_comment( $args['new_comment'] ); |
||
90 | } |
||
91 | |||
92 | // Update columns. |
||
93 | $previous_column_name = ''; |
||
94 | foreach ( $args['columns'] as $col_info ) { |
||
95 | // Validate inputs. |
||
96 | $old_col_name = isset( $col_info['old_name'] ) ? $col_info['old_name'] : null; |
||
97 | $new_col_name = isset( $col_info['new_name'] ) ? $col_info['new_name'] : null; |
||
98 | $xtype = isset( $col_info['xtype'] ) ? $col_info['xtype'] : null; |
||
99 | $size = isset( $col_info['size'] ) ? wp_unslash( $col_info['size'] ) : null; |
||
100 | $nullable = isset( $col_info['nullable'] ); |
||
101 | $default = isset( $col_info['default'] ) ? $col_info['default'] : null; |
||
102 | $auto_increment = isset( $args['auto_increment'] ) && $args['auto_increment'] === $old_col_name; |
||
103 | $unique = isset( $col_info['unique'] ); |
||
104 | $comment = isset( $col_info['comment'] ) ? $col_info['comment'] : null; |
||
105 | $target_table = isset( $col_info['target_table'] ) ? $db->get_table( $col_info['target_table'] ) : null; |
||
106 | |||
107 | // Change existing or insert new column. |
||
108 | $altered = false; |
||
109 | if ( $old_col_name ) { |
||
110 | $col = $table->get_column( $col_info['old_name'] ); |
||
111 | if ( $col instanceof Column ) { |
||
112 | $col->alter( $new_col_name, $xtype, $size, $nullable, $default, $auto_increment, $unique, $comment, $target_table, $previous_column_name ); |
||
113 | $altered = true; |
||
114 | } |
||
115 | } |
||
116 | if ( ! $altered && ! empty( $new_col_name ) ) { |
||
117 | $table->add_column( $new_col_name, $xtype, $size, $nullable, $default, $auto_increment, $unique, $comment, $target_table, $previous_column_name ); |
||
118 | } |
||
119 | |||
120 | // Put the next column after this one. |
||
121 | $previous_column_name = $new_col_name; |
||
122 | } |
||
123 | |||
124 | // Finish up. |
||
125 | $template = new Template( 'table/schema.html' ); |
||
126 | $template->add_notice( 'updated', 'Schema updated.' ); |
||
127 | $url = admin_url( 'admin.php?page=tabulate&controller=schema&table=' . $new_name ); |
||
128 | wp_safe_redirect( $url ); |
||
129 | exit; |
||
130 | } |
||
131 | |||
155 |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.