@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | if ( ! $table_info ) { |
16 | 16 | $table_info = array(); |
17 | 17 | foreach ( $db->get_tables() as $table ) { |
18 | - $table_info[] = array( |
|
18 | + $table_info[ ] = array( |
|
19 | 19 | 'title' => $table->get_title(), |
20 | 20 | 'count' => $table->count_records(), |
21 | 21 | 'url' => $table->get_url(), |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | |
31 | 31 | // Reports. |
32 | 32 | $reports_table = $db->get_table( \WordPress\Tabulate\DB\Reports::reports_table_name() ); |
33 | - $template->reports = ($reports_table) ? $reports_table->get_records( false ) : array(); |
|
33 | + $template->reports = ( $reports_table ) ? $reports_table->get_records( false ) : array(); |
|
34 | 34 | |
35 | 35 | return $template->render(); |
36 | 36 | } |
@@ -592,7 +592,7 @@ discard block |
||
592 | 592 | /** |
593 | 593 | * Get a count of the number of pages in the currently filtered record set. |
594 | 594 | * |
595 | - * @return integer The page count. |
|
595 | + * @return double The page count. |
|
596 | 596 | */ |
597 | 597 | public function get_page_count() { |
598 | 598 | return ceil( $this->count_records() / $this->get_records_per_page() ); |
@@ -923,7 +923,7 @@ discard block |
||
923 | 923 | /** |
924 | 924 | * Get a list of the names of the foreign keys in this table. |
925 | 925 | * |
926 | - * @return string[] Names of foreign key columns in this table. |
|
926 | + * @return integer[] Names of foreign key columns in this table. |
|
927 | 927 | */ |
928 | 928 | public function get_foreign_key_names() { |
929 | 929 | return array_keys( $this->get_referenced_tables( false ) ); |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | } |
208 | 208 | // Validate the value. |
209 | 209 | $empty_value_allowed = ( strpos( $operator, 'empty' ) === false && ! empty( $value ) ); |
210 | - $valid_value = (strpos( $operator, 'empty' ) !== false) || $empty_value_allowed; |
|
210 | + $valid_value = ( strpos( $operator, 'empty' ) !== false ) || $empty_value_allowed; |
|
211 | 211 | if ( ! $valid_operator ) { |
212 | 212 | // translators: Error message shown when a filter is passed an invalid value. |
213 | 213 | $msg = __( '"%s" is not a valid value.', 'tabulate' ); |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | } |
216 | 216 | // Save the filter for later application (see Table::apply_filters()). |
217 | 217 | if ( $valid_columm && $valid_operator && $valid_value ) { |
218 | - $this->filters[] = array( |
|
218 | + $this->filters[ ] = array( |
|
219 | 219 | 'column' => $column, |
220 | 220 | 'operator' => $operator, |
221 | 221 | 'value' => $value, |
@@ -231,9 +231,9 @@ discard block |
||
231 | 231 | */ |
232 | 232 | public function add_filters( $filters ) { |
233 | 233 | foreach ( $filters as $filter ) { |
234 | - $column = (isset( $filter['column'] )) ? $filter['column'] : false; |
|
235 | - $operator = (isset( $filter['operator'] )) ? $filter['operator'] : false; |
|
236 | - $value = (isset( $filter['value'] )) ? $filter['value'] : false; |
|
234 | + $column = ( isset( $filter[ 'column' ] ) ) ? $filter[ 'column' ] : false; |
|
235 | + $operator = ( isset( $filter[ 'operator' ] ) ) ? $filter[ 'operator' ] : false; |
|
236 | + $value = ( isset( $filter[ 'value' ] ) ) ? $filter[ 'value' ] : false; |
|
237 | 237 | $this->add_filter( $column, $operator, $value ); |
238 | 238 | } |
239 | 239 | } |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | // Add an empty default filter to start with. |
251 | 251 | $title_col = $this->get_title_column(); |
252 | 252 | $first_filter = ( $title_col ) ? $title_col->get_name() : ''; |
253 | - $out[] = array( |
|
253 | + $out[ ] = array( |
|
254 | 254 | 'column' => $first_filter, |
255 | 255 | 'operator' => 'like', |
256 | 256 | 'value' => '', |
@@ -286,49 +286,49 @@ discard block |
||
286 | 286 | $where_clause = ''; |
287 | 287 | $join_clause = ''; |
288 | 288 | foreach ( $this->filters as $filter_idx => $filter ) { |
289 | - $f_column = $filter['column']; |
|
290 | - $param_name = $filter['column'] . $param_num; |
|
289 | + $f_column = $filter[ 'column' ]; |
|
290 | + $param_name = $filter[ 'column' ] . $param_num; |
|
291 | 291 | |
292 | 292 | // Filters on foreign keys need to work on the FKs title column. |
293 | 293 | $column = $this->columns[ $f_column ]; |
294 | - if ( $column->is_foreign_key() && ! $filter['force'] ) { |
|
294 | + if ( $column->is_foreign_key() && ! $filter[ 'force' ] ) { |
|
295 | 295 | $join = $this->join_on( $column ); |
296 | - $f_column = $join['column_alias']; |
|
297 | - $join_clause .= $join['join_clause']; |
|
296 | + $f_column = $join[ 'column_alias' ]; |
|
297 | + $join_clause .= $join[ 'join_clause' ]; |
|
298 | 298 | } else { |
299 | 299 | // The result of join_on() above is quoted, so this must also be. |
300 | 300 | $f_column = "`" . $this->get_name() . "`.`$f_column`"; |
301 | 301 | } |
302 | 302 | |
303 | - if ( 'like' === $filter['operator'] || 'not like' === $filter['operator'] ) { |
|
303 | + if ( 'like' === $filter[ 'operator' ] || 'not like' === $filter[ 'operator' ] ) { |
|
304 | 304 | // LIKE or NOT LIKE. |
305 | - $where_clause .= " AND CONVERT($f_column, CHAR) " . strtoupper( $filter['operator'] ) . " %s "; |
|
306 | - $params[ $param_name ] = '%' . trim( $filter['value'] ) . '%'; |
|
307 | - } elseif ( '=' === $filter['operator'] || '!=' === $filter['operator'] ) { |
|
305 | + $where_clause .= " AND CONVERT($f_column, CHAR) " . strtoupper( $filter[ 'operator' ] ) . " %s "; |
|
306 | + $params[ $param_name ] = '%' . trim( $filter[ 'value' ] ) . '%'; |
|
307 | + } elseif ( '=' === $filter[ 'operator' ] || '!=' === $filter[ 'operator' ] ) { |
|
308 | 308 | // Equals or does-not-equal. |
309 | - $where_clause .= " AND $f_column " . $filter['operator'] . " %s "; |
|
310 | - $params[ $param_name ] = trim( $filter['value'] ); |
|
311 | - } elseif ( 'empty' === $filter['operator'] ) { |
|
309 | + $where_clause .= " AND $f_column " . $filter[ 'operator' ] . " %s "; |
|
310 | + $params[ $param_name ] = trim( $filter[ 'value' ] ); |
|
311 | + } elseif ( 'empty' === $filter[ 'operator' ] ) { |
|
312 | 312 | // IS EMPTY. |
313 | 313 | $where_clause .= " AND ($f_column IS NULL OR $f_column = '')"; |
314 | - } elseif ( 'not empty' === $filter['operator'] ) { |
|
314 | + } elseif ( 'not empty' === $filter[ 'operator' ] ) { |
|
315 | 315 | // IS NOT EMPTY. |
316 | 316 | $where_clause .= " AND ($f_column IS NOT NULL AND $f_column != '')"; |
317 | - } elseif ( 'in' === $filter['operator'] || 'not in' === $filter['operator'] ) { |
|
317 | + } elseif ( 'in' === $filter[ 'operator' ] || 'not in' === $filter[ 'operator' ] ) { |
|
318 | 318 | // IN or NOT IN. |
319 | 319 | $placeholders = array(); |
320 | - foreach ( Util::split_newline( $filter['value'] ) as $vid => $val ) { |
|
321 | - $placeholders[] = "%s"; |
|
320 | + foreach ( Util::split_newline( $filter[ 'value' ] ) as $vid => $val ) { |
|
321 | + $placeholders[ ] = "%s"; |
|
322 | 322 | $params[ $param_name . '_' . $vid ] = $val; |
323 | 323 | // Save the separated filter values for later. |
324 | - $this->filters[ $filter_idx ]['values'][] = $val; |
|
324 | + $this->filters[ $filter_idx ][ 'values' ][ ] = $val; |
|
325 | 325 | } |
326 | - $negate = ( 'not in' === $filter['operator'] ) ? 'NOT' : ''; |
|
326 | + $negate = ( 'not in' === $filter[ 'operator' ] ) ? 'NOT' : ''; |
|
327 | 327 | $where_clause .= " AND ($f_column $negate IN (" . join( ", ", $placeholders ) . "))"; |
328 | 328 | } else { |
329 | 329 | // Other operators. They're already validated in self::addFilter(). |
330 | - $where_clause .= " AND ($f_column " . $filter['operator'] . " %s)"; |
|
331 | - $params[ $param_name ] = trim( $filter['value'] ); |
|
330 | + $where_clause .= " AND ($f_column " . $filter[ 'operator' ] . " %s)"; |
|
331 | + $params[ $param_name ] = trim( $filter[ 'value' ] ); |
|
332 | 332 | } // End if(). |
333 | 333 | |
334 | 334 | $param_num++; |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | $order_by = $this->get_column( $this->get_order_by() ); |
445 | 445 | if ( $order_by ) { |
446 | 446 | $order_by_join = $this->join_on( $order_by ); |
447 | - $sql .= $order_by_join['join_clause'] . ' ORDER BY ' . $order_by_join['column_alias'] . ' ' . $this->get_order_dir(); |
|
447 | + $sql .= $order_by_join[ 'join_clause' ] . ' ORDER BY ' . $order_by_join[ 'column_alias' ] . ' ' . $this->get_order_dir(); |
|
448 | 448 | } |
449 | 449 | } |
450 | 450 | |
@@ -455,7 +455,7 @@ discard block |
||
455 | 455 | $records_per_page = $this->get_records_per_page(); |
456 | 456 | $sql .= ' LIMIT ' . $records_per_page; |
457 | 457 | if ( $this->page() > 1 ) { |
458 | - $sql .= ' OFFSET ' . ($records_per_page * ($this->get_current_page_num() - 1)); |
|
458 | + $sql .= ' OFFSET ' . ( $records_per_page * ( $this->get_current_page_num() - 1 ) ); |
|
459 | 459 | } |
460 | 460 | } |
461 | 461 | |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | |
468 | 468 | $records = array(); |
469 | 469 | foreach ( $rows as $row ) { |
470 | - $records[] = new Record( $this, $row ); |
|
470 | + $records[ ] = new Record( $this, $row ); |
|
471 | 471 | } |
472 | 472 | |
473 | 473 | if ( $save_sql ) { |
@@ -536,9 +536,9 @@ discard block |
||
536 | 536 | $table_name = $this->get_name(); |
537 | 537 | foreach ( $this->get_columns() as $col_name => $col ) { |
538 | 538 | if ( 'point' === $col->get_type() ) { |
539 | - $select[] = "AsText(`$table_name`.`$col_name`) AS `$col_name`"; |
|
539 | + $select[ ] = "AsText(`$table_name`.`$col_name`) AS `$col_name`"; |
|
540 | 540 | } else { |
541 | - $select[] = "`$table_name`.`$col_name`"; |
|
541 | + $select[ ] = "`$table_name`.`$col_name`"; |
|
542 | 542 | } |
543 | 543 | } |
544 | 544 | return join( ', ', $select ); |
@@ -705,17 +705,17 @@ discard block |
||
705 | 705 | foreach ( $this->columns as $col_name => $col ) { |
706 | 706 | if ( $col->is_foreign_key() ) { |
707 | 707 | $col_join = $this->join_on( $col ); |
708 | - $column_name = $col_join['column_alias']; |
|
709 | - $join_clause .= $col_join['join_clause']; |
|
708 | + $column_name = $col_join[ 'column_alias' ]; |
|
709 | + $join_clause .= $col_join[ 'join_clause' ]; |
|
710 | 710 | } elseif ( 'point' === $col->get_type() ) { |
711 | - $columns[] = "IF(`$this->name`.`$col_name` IS NOT NULL, AsText(`$this->name`.`$col_name`), '') AS `$col_name`"; |
|
711 | + $columns[ ] = "IF(`$this->name`.`$col_name` IS NOT NULL, AsText(`$this->name`.`$col_name`), '') AS `$col_name`"; |
|
712 | 712 | } else { |
713 | 713 | $column_name = "`$this->name`.`$col_name`"; |
714 | 714 | } |
715 | 715 | if ( 'point' !== $col->get_type() && isset( $column_name ) ) { |
716 | - $columns[] = "REPLACE(IFNULL($column_name, ''),CONCAT(CHAR(13),CHAR(10)),CHAR(10))"; // 13 = \r and 10 = \n |
|
716 | + $columns[ ] = "REPLACE(IFNULL($column_name, ''),CONCAT(CHAR(13),CHAR(10)),CHAR(10))"; // 13 = \r and 10 = \n |
|
717 | 717 | } |
718 | - $column_headers[] = $col->get_title(); |
|
718 | + $column_headers[ ] = $col->get_title(); |
|
719 | 719 | } |
720 | 720 | |
721 | 721 | // Build basic SELECT statement. |
@@ -857,7 +857,7 @@ discard block |
||
857 | 857 | $sql = $this->get_defining_sql(); |
858 | 858 | $comment_pattern = '/.*\)(?:.*COMMENT[\w=]*\'(.*)\')?/si'; |
859 | 859 | preg_match( $comment_pattern, $sql, $matches ); |
860 | - $this->comment = ( isset( $matches[1] ) ) ? $matches[1] : ''; |
|
860 | + $this->comment = ( isset( $matches[ 1 ] ) ) ? $matches[ 1 ] : ''; |
|
861 | 861 | $this->comment = str_replace( "''", "'", $this->comment ); |
862 | 862 | } |
863 | 863 | if ( empty( $this->comment ) && $this->is_view() ) { |
@@ -875,7 +875,7 @@ discard block |
||
875 | 875 | $cols = array(); |
876 | 876 | foreach ( $this->get_columns() as $column ) { |
877 | 877 | if ( $column->is_unique() ) { |
878 | - $cols[] = $column; |
|
878 | + $cols[ ] = $column; |
|
879 | 879 | } |
880 | 880 | } |
881 | 881 | return $cols; |
@@ -952,8 +952,8 @@ discard block |
||
952 | 952 | $defining_sql = $this->get_defining_sql(); |
953 | 953 | $fk_pattern = '|FOREIGN KEY \(`(.*?)`\) REFERENCES `(.*?)`|'; |
954 | 954 | preg_match_all( $fk_pattern, $defining_sql, $matches ); |
955 | - if ( isset( $matches[1] ) && count( $matches[1] ) > 0 ) { |
|
956 | - foreach ( array_combine( $matches[1], $matches[2] ) as $col_name => $tab_name ) { |
|
955 | + if ( isset( $matches[ 1 ] ) && count( $matches[ 1 ] ) > 0 ) { |
|
956 | + foreach ( array_combine( $matches[ 1 ], $matches[ 2 ] ) as $col_name => $tab_name ) { |
|
957 | 957 | $this->referenced_table_names[ $col_name ] = $tab_name; |
958 | 958 | } |
959 | 959 | } |
@@ -1057,7 +1057,7 @@ discard block |
||
1057 | 1057 | $json = new Services_JSON(); |
1058 | 1058 | $metadata = array(); |
1059 | 1059 | foreach ( $this->get_columns() as $column ) { |
1060 | - $metadata[] = array( |
|
1060 | + $metadata[ ] = array( |
|
1061 | 1061 | 'name' => $column->get_name(), |
1062 | 1062 | ); |
1063 | 1063 | } |
@@ -1125,7 +1125,7 @@ discard block |
||
1125 | 1125 | */ |
1126 | 1126 | public function save_record( $data, $pk_value = null ) { |
1127 | 1127 | // Changeset only created here if not already in progress. |
1128 | - $changeset_comment = isset( $data['changeset_comment'] ) ? $data['changeset_comment'] : null; |
|
1128 | + $changeset_comment = isset( $data[ 'changeset_comment' ] ) ? $data[ 'changeset_comment' ] : null; |
|
1129 | 1129 | $change_tracker = new ChangeTracker( $this->get_database()->get_wpdb(), $changeset_comment ); |
1130 | 1130 | |
1131 | 1131 | $columns = $this->get_columns(); |
@@ -1181,7 +1181,7 @@ discard block |
||
1181 | 1181 | |
1182 | 1182 | } elseif ( $column->is_numeric() ) { |
1183 | 1183 | // Numeric values. |
1184 | - $sql_values[ $field ] = (float) $value; |
|
1184 | + $sql_values[ $field ] = ( float ) $value; |
|
1185 | 1185 | |
1186 | 1186 | } else { |
1187 | 1187 | // Everything else. |
@@ -1199,7 +1199,7 @@ discard block |
||
1199 | 1199 | // Can probably be removed when https://core.trac.wordpress.org/ticket/15158 is resolved. |
1200 | 1200 | $set_items = array(); |
1201 | 1201 | foreach ( $sql_values as $field => $escd_datum ) { |
1202 | - $set_items[] = "`$field` = $escd_datum"; |
|
1202 | + $set_items[ ] = "`$field` = $escd_datum"; |
|
1203 | 1203 | } |
1204 | 1204 | $set_clause = 'SET ' . join( ', ', $set_items ); |
1205 | 1205 | |
@@ -1219,7 +1219,7 @@ discard block |
||
1219 | 1219 | $where_clause = $this->database->get_wpdb()->prepare( "WHERE `$pk_name` = %s", $pk_value ); |
1220 | 1220 | $sql = 'UPDATE ' . $this->get_name() . " $set_clause $where_clause"; |
1221 | 1221 | $this->get_database()->query( $sql, null, 'Unable to update a record' ); |
1222 | - $new_pk_value = (isset( $data[ $pk_name ] ) ) ? $data[ $pk_name ] : $pk_value; |
|
1222 | + $new_pk_value = ( isset( $data[ $pk_name ] ) ) ? $data[ $pk_name ] : $pk_value; |
|
1223 | 1223 | |
1224 | 1224 | } else { |
1225 | 1225 | /* |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * Save a record. |
80 | 80 | * |
81 | 81 | * @param string[] $args The request arguments. |
82 | - * @return boolean |
|
82 | + * @return false|null |
|
83 | 83 | */ |
84 | 84 | public function save( $args ) { |
85 | 85 | $db = new \WordPress\Tabulate\DB\Database( $this->wpdb ); |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | * Delete (or ask for confirmation of deleting) a single record. |
132 | 132 | * |
133 | 133 | * @param string[] $args The request arguments. |
134 | - * @return type |
|
134 | + * @return null|string |
|
135 | 135 | */ |
136 | 136 | public function delete( $args ) { |
137 | 137 | $db = new \WordPress\Tabulate\DB\Database( $this->wpdb ); |
@@ -37,12 +37,12 @@ discard block |
||
37 | 37 | public function index( $args ) { |
38 | 38 | // Get database and table. |
39 | 39 | $db = new \WordPress\Tabulate\DB\Database( $this->wpdb ); |
40 | - $table = $db->get_table( $args['table'] ); |
|
40 | + $table = $db->get_table( $args[ 'table' ] ); |
|
41 | 41 | |
42 | 42 | // Give it all to the template. |
43 | 43 | $template = $this->get_template( $table ); |
44 | - if ( isset( $args['ident'] ) ) { |
|
45 | - $template->record = $table->get_record( $args['ident'] ); |
|
44 | + if ( isset( $args[ 'ident' ] ) ) { |
|
45 | + $template->record = $table->get_record( $args[ 'ident' ] ); |
|
46 | 46 | // Check permission. |
47 | 47 | if ( ! Grants::current_user_can( Grants::UPDATE, $table->get_name() ) ) { |
48 | 48 | $template->add_notice( 'error', 'You do not have permission to update data in this table.' ); |
@@ -55,8 +55,8 @@ discard block |
||
55 | 55 | $template->add_notice( 'error', 'You do not have permission to create records in this table.' ); |
56 | 56 | } |
57 | 57 | // Add query-string values. |
58 | - if ( isset( $args['defaults'] ) ) { |
|
59 | - $template->record->set_multiple( $args['defaults'] ); |
|
58 | + if ( isset( $args[ 'defaults' ] ) ) { |
|
59 | + $template->record->set_multiple( $args[ 'defaults' ] ); |
|
60 | 60 | } |
61 | 61 | } |
62 | 62 | // Don't save to non-updatable views. |
@@ -68,8 +68,8 @@ discard block |
||
68 | 68 | wp_enqueue_script( 'dashboard' ); |
69 | 69 | |
70 | 70 | // Return to URL. |
71 | - if ( isset( $args['return_to'] ) ) { |
|
72 | - $template->return_to = $args['return_to']; |
|
71 | + if ( isset( $args[ 'return_to' ] ) ) { |
|
72 | + $template->return_to = $args[ 'return_to' ]; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | return $template->render(); |
@@ -83,21 +83,21 @@ discard block |
||
83 | 83 | */ |
84 | 84 | public function save( $args ) { |
85 | 85 | $db = new \WordPress\Tabulate\DB\Database( $this->wpdb ); |
86 | - $table = $db->get_table( $args['table'] ); |
|
86 | + $table = $db->get_table( $args[ 'table' ] ); |
|
87 | 87 | if ( ! $table ) { |
88 | 88 | // It shouldn't be possible to get here via the UI, so no message. |
89 | 89 | return false; |
90 | 90 | } |
91 | 91 | |
92 | 92 | // Guard against non-post requests. c.f. wp-comments-post.php. |
93 | - if ( ! isset( $_SERVER['REQUEST_METHOD'] ) || 'POST' !== $_SERVER['REQUEST_METHOD'] ) { |
|
93 | + if ( ! isset( $_SERVER[ 'REQUEST_METHOD' ] ) || 'POST' !== $_SERVER[ 'REQUEST_METHOD' ] ) { |
|
94 | 94 | header( 'Allow: POST' ); |
95 | 95 | header( 'HTTP/1.1 405 Method Not Allowed' ); |
96 | 96 | header( 'Content-Type: text/plain' ); |
97 | 97 | return false; |
98 | 98 | } |
99 | 99 | |
100 | - $record_ident = isset( $args['ident'] ) ? $args['ident'] : false; |
|
100 | + $record_ident = isset( $args[ 'ident' ] ) ? $args[ 'ident' ] : false; |
|
101 | 101 | $this->verify_nonce( 'tabulate-record-' . $record_ident ); |
102 | 102 | $template = $this->get_template( $table ); |
103 | 103 | |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | $existing = $table->get_record( $pk ); |
108 | 108 | if ( ! $record_ident && $existing ) { |
109 | 109 | $template->add_notice( 'updated', "The record identified by '$pk' already exists." ); |
110 | - $_REQUEST['return_to'] = $existing->get_url(); |
|
110 | + $_REQUEST[ 'return_to' ] = $existing->get_url(); |
|
111 | 111 | } else { |
112 | 112 | // Otherwise, create a new one. |
113 | 113 | try { |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | } |
123 | 123 | } |
124 | 124 | // Redirect back to the edit form. |
125 | - $return_to = ( ! empty( $_REQUEST['return_to'] ) ) ? $_REQUEST['return_to'] : $template->record->get_url(); |
|
125 | + $return_to = ( ! empty( $_REQUEST[ 'return_to' ] ) ) ? $_REQUEST[ 'return_to' ] : $template->record->get_url(); |
|
126 | 126 | wp_safe_redirect( $return_to ); |
127 | 127 | exit; |
128 | 128 | } |
@@ -135,15 +135,15 @@ discard block |
||
135 | 135 | */ |
136 | 136 | public function delete( $args ) { |
137 | 137 | $db = new \WordPress\Tabulate\DB\Database( $this->wpdb ); |
138 | - $table = $db->get_table( $args['table'] ); |
|
139 | - $record_ident = isset( $args['ident'] ) ? $args['ident'] : false; |
|
138 | + $table = $db->get_table( $args[ 'table' ] ); |
|
139 | + $record_ident = isset( $args[ 'ident' ] ) ? $args[ 'ident' ] : false; |
|
140 | 140 | if ( ! $record_ident ) { |
141 | 141 | wp_safe_redirect( $table->get_url() ); |
142 | 142 | exit; |
143 | 143 | } |
144 | 144 | |
145 | 145 | // Ask for confirmation. |
146 | - if ( ! isset( $_POST['confirm_deletion'] ) ) { |
|
146 | + if ( ! isset( $_POST[ 'confirm_deletion' ] ) ) { |
|
147 | 147 | $template = new \WordPress\Tabulate\Template( 'record/delete.html' ); |
148 | 148 | $template->table = $table; |
149 | 149 | $template->record = $table->get_record( $record_ident ); |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | /** |
118 | 118 | * Get the valid options for this column; only applies to ENUM and SET. |
119 | 119 | * |
120 | - * @return array The available options. |
|
120 | + * @return string[] The available options. |
|
121 | 121 | */ |
122 | 122 | public function get_options() { |
123 | 123 | return $this->options; |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | /** |
271 | 271 | * Get the default value for this column. |
272 | 272 | * |
273 | - * @return mixed |
|
273 | + * @return string|null |
|
274 | 274 | */ |
275 | 275 | public function get_default() { |
276 | 276 | if ( 'CURRENT_TIMESTAMP' === $this->default_value ) { |
@@ -144,33 +144,33 @@ discard block |
||
144 | 144 | protected function parse_info( $info ) { |
145 | 145 | |
146 | 146 | // Name. |
147 | - $this->name = $info['Field']; |
|
147 | + $this->name = $info[ 'Field' ]; |
|
148 | 148 | |
149 | 149 | // Type. |
150 | - $this->parse_type( $info['Type'] ); |
|
150 | + $this->parse_type( $info[ 'Type' ] ); |
|
151 | 151 | |
152 | 152 | // Default. |
153 | - $this->default_value = $info['Default']; |
|
153 | + $this->default_value = $info[ 'Default' ]; |
|
154 | 154 | |
155 | 155 | // Primary key. |
156 | - if ( 'PRI' === strtoupper( $info['Key'] ) ) { |
|
156 | + if ( 'PRI' === strtoupper( $info[ 'Key' ] ) ) { |
|
157 | 157 | $this->is_primary_key = true; |
158 | - if ( 'auto_increment' === $info['Extra'] ) { |
|
158 | + if ( 'auto_increment' === $info[ 'Extra' ] ) { |
|
159 | 159 | $this->is_auto_increment = true; |
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
163 | 163 | // Unique key. |
164 | - $this->is_unique = ( 'UNI' === strtoupper( $info['Key'] ) ); |
|
164 | + $this->is_unique = ( 'UNI' === strtoupper( $info[ 'Key' ] ) ); |
|
165 | 165 | |
166 | 166 | // Comment. |
167 | - $this->comment = $info['Comment']; |
|
167 | + $this->comment = $info[ 'Comment' ]; |
|
168 | 168 | |
169 | 169 | // Collation. |
170 | - $this->collation = $info['Collation']; |
|
170 | + $this->collation = $info[ 'Collation' ]; |
|
171 | 171 | |
172 | 172 | // Is this column NULL? |
173 | - $this->nullable = ( 'YES' === $info['Null'] ); |
|
173 | + $this->nullable = ( 'YES' === $info[ 'Null' ] ); |
|
174 | 174 | |
175 | 175 | // Is this a foreign key? |
176 | 176 | if ( in_array( $this->get_name(), $this->get_table()->get_foreign_key_names(), true ) ) { |
@@ -302,14 +302,14 @@ discard block |
||
302 | 302 | public function get_xtype() { |
303 | 303 | $xtypes = self::get_xtypes(); |
304 | 304 | if ( $this->is_foreign_key() ) { |
305 | - return $xtypes['fk']; |
|
305 | + return $xtypes[ 'fk' ]; |
|
306 | 306 | } |
307 | 307 | if ( $this->is_boolean() ) { |
308 | - return $xtypes['boolean']; |
|
308 | + return $xtypes[ 'boolean' ]; |
|
309 | 309 | } |
310 | 310 | // Otherwise fall back on the first xtype with a matching type. |
311 | 311 | foreach ( $xtypes as $xtype ) { |
312 | - if ( strtoupper( $this->get_type() ) === $xtype['type'] ) { |
|
312 | + if ( strtoupper( $this->get_type() ) === $xtype[ 'type' ] ) { |
|
313 | 313 | return $xtype; |
314 | 314 | } |
315 | 315 | } |
@@ -506,22 +506,22 @@ discard block |
||
506 | 506 | $this->scale = null; |
507 | 507 | $this->options = null; |
508 | 508 | if ( preg_match( $varchar_pattern, $type_string, $matches ) ) { |
509 | - $this->type = $matches[1]; |
|
510 | - $this->size = (int) $matches[2]; |
|
509 | + $this->type = $matches[ 1 ]; |
|
510 | + $this->size = ( int ) $matches[ 2 ]; |
|
511 | 511 | } elseif ( preg_match( $decimal_pattern, $type_string, $matches ) ) { |
512 | 512 | $this->type = 'decimal'; |
513 | - $this->precision = $matches[1]; |
|
514 | - $this->scale = $matches[2]; |
|
513 | + $this->precision = $matches[ 1 ]; |
|
514 | + $this->scale = $matches[ 2 ]; |
|
515 | 515 | } elseif ( preg_match( $float_pattern, $type_string, $matches ) ) { |
516 | 516 | $this->type = 'float'; |
517 | - $this->precision = $matches[1]; |
|
518 | - $this->scale = $matches[2]; |
|
517 | + $this->precision = $matches[ 1 ]; |
|
518 | + $this->scale = $matches[ 2 ]; |
|
519 | 519 | } elseif ( preg_match( $integer_pattern, $type_string, $matches ) ) { |
520 | - $this->type = $matches[1]; |
|
521 | - $this->size = (int) $matches[2]; |
|
520 | + $this->type = $matches[ 1 ]; |
|
521 | + $this->size = ( int ) $matches[ 2 ]; |
|
522 | 522 | } elseif ( preg_match( $enum_pattern, $type_string, $matches ) ) { |
523 | - $this->type = $matches[1]; |
|
524 | - $values = explode( "','", $matches[2] ); |
|
523 | + $this->type = $matches[ 1 ]; |
|
524 | + $values = explode( "','", $matches[ 2 ] ); |
|
525 | 525 | $this->options = array_combine( $values, $values ); |
526 | 526 | } |
527 | 527 | } |
@@ -532,14 +532,14 @@ discard block |
||
532 | 532 | * @return string |
533 | 533 | */ |
534 | 534 | public function __toString() { |
535 | - $pk = ($this->is_primary_key) ? ' PK' : ''; |
|
536 | - $auto = ($this->is_auto_increment) ? ' AI' : ''; |
|
535 | + $pk = ( $this->is_primary_key ) ? ' PK' : ''; |
|
536 | + $auto = ( $this->is_auto_increment ) ? ' AI' : ''; |
|
537 | 537 | if ( $this->references ) { |
538 | 538 | $ref = ' References ' . $this->references . '.'; |
539 | 539 | } else { |
540 | 540 | $ref = ''; |
541 | 541 | } |
542 | - $size = ($this->size > 0) ? "($this->size)" : ''; |
|
542 | + $size = ( $this->size > 0 ) ? "($this->size)" : ''; |
|
543 | 543 | return $this->name . ' ' . strtoupper( $this->type ) . $size . $pk . $auto . $ref; |
544 | 544 | } |
545 | 545 | |
@@ -551,7 +551,7 @@ discard block |
||
551 | 551 | public function get_current_column_definition() { |
552 | 552 | return self::get_column_definition( |
553 | 553 | $this->get_name(), |
554 | - $this->get_xtype()['name'], |
|
554 | + $this->get_xtype()[ 'name' ], |
|
555 | 555 | $this->get_size(), |
556 | 556 | $this->nullable(), |
557 | 557 | $this->get_default(), |
@@ -580,14 +580,14 @@ discard block |
||
580 | 580 | */ |
581 | 581 | public function alter( $new_name = null, $xtype_name = null, $size = null, $nullable = null, $default = null, $auto_increment = null, $unique = null, $comment = null, $target_table = null, $after = null ) { |
582 | 582 | // Any that have not been set explicitely should be unchanged. |
583 | - $new_name = ! is_null( $new_name ) ? (string) $new_name : $this->get_name(); |
|
584 | - $xtype_name = ! is_null( $xtype_name ) ? (string) $xtype_name : $this->get_xtype()['name']; |
|
583 | + $new_name = ! is_null( $new_name ) ? ( string ) $new_name : $this->get_name(); |
|
584 | + $xtype_name = ! is_null( $xtype_name ) ? ( string ) $xtype_name : $this->get_xtype()[ 'name' ]; |
|
585 | 585 | $size = ! is_null( $size ) ? $size : $this->get_size(); |
586 | - $nullable = ! is_null( $nullable ) ? (boolean) $nullable : $this->nullable(); |
|
587 | - $default = ! is_null( $default ) ? (string) $default : $this->get_default(); |
|
588 | - $auto_increment = ! is_null( $auto_increment ) ? (boolean) $auto_increment : $this->is_auto_increment(); |
|
589 | - $unique = ! is_null( $unique ) ? (boolean) $unique : $this->is_unique(); |
|
590 | - $comment = ! is_null( $comment ) ? (string) $comment : $this->get_comment(); |
|
586 | + $nullable = ! is_null( $nullable ) ? ( boolean ) $nullable : $this->nullable(); |
|
587 | + $default = ! is_null( $default ) ? ( string ) $default : $this->get_default(); |
|
588 | + $auto_increment = ! is_null( $auto_increment ) ? ( boolean ) $auto_increment : $this->is_auto_increment(); |
|
589 | + $unique = ! is_null( $unique ) ? ( boolean ) $unique : $this->is_unique(); |
|
590 | + $comment = ! is_null( $comment ) ? ( string ) $comment : $this->get_comment(); |
|
591 | 591 | $target_table = ! is_null( $target_table ) ? $target_table : $this->get_referenced_table(); |
592 | 592 | |
593 | 593 | // Check the current column definition. |
@@ -602,7 +602,7 @@ discard block |
||
602 | 602 | if ( $this->is_unique() ) { |
603 | 603 | $sql = 'SHOW INDEXES FROM `' . $table->get_name() . '` WHERE Column_name LIKE "' . $this->get_name() . '"'; |
604 | 604 | foreach ( $wpdb->get_results( $sql, ARRAY_A ) as $index ) { |
605 | - $sql = "DROP INDEX `" . $index['Key_name'] . "` ON `" . $table->get_name() . "`"; |
|
605 | + $sql = "DROP INDEX `" . $index[ 'Key_name' ] . "` ON `" . $table->get_name() . "`"; |
|
606 | 606 | $wpdb->query( $sql ); |
607 | 607 | } |
608 | 608 | } |
@@ -660,23 +660,23 @@ discard block |
||
660 | 660 | public static function get_column_definition( $name, $xtype_name = null, $size = null, $nullable = true, $default = null, $auto_increment = null, $unique = null, $comment = null, $target_table = null, $after = null ) { |
661 | 661 | // Type. |
662 | 662 | $xtypes = self::get_xtypes(); |
663 | - $xtype = ( isset( $xtypes[ $xtype_name ] ) ) ? $xtypes[ $xtype_name ] : $xtypes['text_short']; |
|
664 | - $type_str = $xtype['type']; |
|
663 | + $xtype = ( isset( $xtypes[ $xtype_name ] ) ) ? $xtypes[ $xtype_name ] : $xtypes[ 'text_short' ]; |
|
664 | + $type_str = $xtype[ 'type' ]; |
|
665 | 665 | // Size. |
666 | 666 | $size_str = ''; |
667 | - if ( $xtype['sizes'] > 0 ) { |
|
668 | - $size_str = '(' . ( $size ? : 50 ) . ')'; |
|
667 | + if ( $xtype[ 'sizes' ] > 0 ) { |
|
668 | + $size_str = '(' . ( $size ?: 50 ) . ')'; |
|
669 | 669 | } |
670 | 670 | if ( 'boolean' === $xtype_name ) { |
671 | 671 | $size_str = '(1)'; |
672 | 672 | } |
673 | - $null_str = (true === $nullable) ? 'NULL' : 'NOT NULL'; |
|
673 | + $null_str = ( true === $nullable ) ? 'NULL' : 'NOT NULL'; |
|
674 | 674 | $default_str = ''; |
675 | 675 | if ( 'text_long' !== $xtype_name ) { |
676 | 676 | $default_str = ! empty( $default ) ? "DEFAULT '$default'" : ( $nullable ? 'DEFAULT NULL' : '' ); |
677 | 677 | } |
678 | 678 | $auto_increment_str = ''; |
679 | - if ( $auto_increment && 'integer' === $xtype['name'] ) { |
|
679 | + if ( $auto_increment && 'integer' === $xtype[ 'name' ] ) { |
|
680 | 680 | $auto_increment_str = 'AUTO_INCREMENT'; |
681 | 681 | } |
682 | 682 | $unique_str = $unique ? 'UNIQUE' : ''; |
@@ -697,7 +697,7 @@ discard block |
||
697 | 697 | . ' (`' . $pk_col->get_name() . '`)'; |
698 | 698 | $type_str = $pk_col->get_type(); |
699 | 699 | $size_str = '(' . $pk_col->get_size() . ')'; |
700 | - $sign_str = ($pk_col->is_unsigned()) ? 'UNSIGNED' : ''; |
|
700 | + $sign_str = ( $pk_col->is_unsigned() ) ? 'UNSIGNED' : ''; |
|
701 | 701 | } |
702 | 702 | |
703 | 703 | // Put it all together. |
@@ -21,7 +21,7 @@ |
||
21 | 21 | * View a report. |
22 | 22 | * |
23 | 23 | * @param string[] $args The request arguments. |
24 | - * @return type |
|
24 | + * @return null|string |
|
25 | 25 | */ |
26 | 26 | public function index( $args ) { |
27 | 27 | $db = new Database( $this->wpdb ); |
@@ -25,7 +25,7 @@ |
||
25 | 25 | */ |
26 | 26 | public function index( $args ) { |
27 | 27 | $db = new Database( $this->wpdb ); |
28 | - $id = isset( $args['id'] ) ? $args['id'] : Reports::DEFAULT_REPORT_ID; |
|
28 | + $id = isset( $args[ 'id' ] ) ? $args[ 'id' ] : Reports::DEFAULT_REPORT_ID; |
|
29 | 29 | $reports = new Reports( $db ); |
30 | 30 | $template = $reports->get_template( $id ); |
31 | 31 | $out = $template->render(); |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | $db = new Database( $this->wpdb ); |
48 | 48 | $out = array(); |
49 | 49 | foreach ( $db->get_tables( false ) as $table ) { |
50 | - $out[] = array( |
|
50 | + $out[ ] = array( |
|
51 | 51 | 'value' => $table->get_name(), |
52 | 52 | 'label' => $table->get_title(), |
53 | 53 | ); |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | $out = array(); |
66 | 66 | foreach ( $tables as $table ) { |
67 | 67 | if ( Grants::current_user_can( Grants::CREATE, $table->get_name() ) ) { |
68 | - $out[] = $table->get_name(); |
|
68 | + $out[ ] = $table->get_name(); |
|
69 | 69 | } |
70 | 70 | } |
71 | 71 | return $out; |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | * @return array |
82 | 82 | */ |
83 | 83 | public function foreign_key_values( \WP_REST_Request $request ) { |
84 | - if ( ! isset( $this->get['term'] ) ) { |
|
84 | + if ( ! isset( $this->get[ 'term' ] ) ) { |
|
85 | 85 | return array(); |
86 | 86 | } |
87 | 87 | $db = new Database( $this->wpdb ); |
@@ -90,9 +90,9 @@ discard block |
||
90 | 90 | return array(); |
91 | 91 | } |
92 | 92 | // First get any exact matches. |
93 | - $out = $this->foreign_key_values_build( $table, '=', $this->get['term'] ); |
|
93 | + $out = $this->foreign_key_values_build( $table, '=', $this->get[ 'term' ] ); |
|
94 | 94 | // Then get any 'contains' matches. |
95 | - $out += $this->foreign_key_values_build( $table, 'like', '%' . $this->get['term'] . '%' ); |
|
95 | + $out += $this->foreign_key_values_build( $table, 'like', '%' . $this->get[ 'term' ] . '%' ); |
|
96 | 96 | return $out; |
97 | 97 | } |
98 | 98 |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | public static function add_path( $new_path ) { |
83 | 83 | $path = realpath( $new_path ); |
84 | 84 | if ( ! in_array( $path, self::$paths, true ) ) { |
85 | - self::$paths[] = $path; |
|
85 | + self::$paths[ ] = $path; |
|
86 | 86 | } |
87 | 87 | } |
88 | 88 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | foreach ( self::$paths as $path ) { |
106 | 106 | $dir = $path . '/' . ltrim( $directory, '/' ); |
107 | 107 | foreach ( preg_grep( '/^[^\.].*\.(twig|html)$/', scandir( $dir ) ) as $file ) { |
108 | - $templates[] = $directory . '/' . $file; |
|
108 | + $templates[ ] = $directory . '/' . $file; |
|
109 | 109 | } |
110 | 110 | } |
111 | 111 | return $templates; |
@@ -150,11 +150,11 @@ discard block |
||
150 | 150 | * @param string $message The message to display. |
151 | 151 | */ |
152 | 152 | public function add_notice( $type, $message ) { |
153 | - $this->data['notices'][] = array( |
|
153 | + $this->data[ 'notices' ][ ] = array( |
|
154 | 154 | 'type' => $type, |
155 | 155 | 'message' => $message, |
156 | 156 | ); |
157 | - set_transient( $this->transient_notices, $this->data['notices'] ); |
|
157 | + set_transient( $this->transient_notices, $this->data[ 'notices' ] ); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | /** |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | $twig->addFunction( $f, new \Twig_SimpleFunction( $f, $f ) ); |
183 | 183 | } |
184 | 184 | // Handle wp_nonce_field() differently in order to default it to returning the string. |
185 | - $wp_nonce_field = new \Twig_SimpleFunction( 'wp_nonce_field', function ( $action = -1, $name = "_wpnonce", $referer = true, $echo = false ) { |
|
185 | + $wp_nonce_field = new \Twig_SimpleFunction( 'wp_nonce_field', function( $action = -1, $name = "_wpnonce", $referer = true, $echo = false ) { |
|
186 | 186 | return wp_nonce_field( $action, $name, $referer, $echo ); |
187 | 187 | } ); |
188 | 188 | $twig->addFunction( $wp_nonce_field ); |
@@ -135,7 +135,7 @@ |
||
135 | 135 | * Get an item from this template's data. |
136 | 136 | * |
137 | 137 | * @param string $name The name of the template variable. |
138 | - * @return mixed |
|
138 | + * @return string |
|
139 | 139 | */ |
140 | 140 | public function __get( $name ) { |
141 | 141 | return $this->data[ $name ]; |
@@ -163,10 +163,10 @@ |
||
163 | 163 | ); |
164 | 164 | // Daft workaround for https://core.trac.wordpress.org/ticket/15158 . |
165 | 165 | if ( ! is_null( $old_val ) ) { |
166 | - $data['old_value'] = $old_val; |
|
166 | + $data[ 'old_value' ] = $old_val; |
|
167 | 167 | } |
168 | 168 | if ( ! is_null( $new_val ) ) { |
169 | - $data['new_value'] = $new_val; |
|
169 | + $data[ 'new_value' ] = $new_val; |
|
170 | 170 | } |
171 | 171 | // Save the change record. |
172 | 172 | $this->wpdb->insert( $this->changes_name(), $data ); |
@@ -115,8 +115,8 @@ discard block |
||
115 | 115 | * changeset if required, and save the old record for later use. |
116 | 116 | * |
117 | 117 | * @param Table $table The table into which the record is being saved. |
118 | - * @param type $pk_value The primary key of the record being saved. May be null. |
|
119 | - * @return boolean |
|
118 | + * @param string|null $pk_value The primary key of the record being saved. May be null. |
|
119 | + * @return false|null |
|
120 | 120 | */ |
121 | 121 | public function before_save( Table $table, $pk_value ) { |
122 | 122 | // Don't save changes to the changes tables. |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * |
138 | 138 | * @param Table $table The table the record is being saved in. |
139 | 139 | * @param Record $new_record The record, after being saved. |
140 | - * @return boolean |
|
140 | + * @return false|null |
|
141 | 141 | */ |
142 | 142 | public function after_save( Table $table, Record $new_record ) { |
143 | 143 | // Don't save changes to the changes tables. |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function __construct( $table, $data = array() ) { |
43 | 43 | $this->table = $table; |
44 | - $this->data = (object) $data; |
|
44 | + $this->data = ( object ) $data; |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | $title_parts = array(); |
176 | 176 | foreach ( $this->table->get_columns() as $col ) { |
177 | 177 | $col_name = $col->get_name() . self::FKTITLE; |
178 | - $title_parts[] = $this->$col_name(); |
|
178 | + $title_parts[ ] = $this->$col_name(); |
|
179 | 179 | } |
180 | 180 | return '[ ' . join( ' | ', $title_parts ) . ' ]'; |
181 | 181 | } |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | 'table' => $this->table->get_name(), |
228 | 228 | ); |
229 | 229 | if ( $include_ident && false !== $this->get_primary_key() ) { |
230 | - $params['ident'] = $this->get_primary_key(); |
|
230 | + $params[ 'ident' ] = $this->get_primary_key(); |
|
231 | 231 | } |
232 | 232 | if ( is_array( $extra_params ) ) { |
233 | 233 | $params = array_merge( $params, $extra_params ); |