| 1 | <?php |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 2 | namespace PodloveSubscribeButton; |
||
| 3 | |||
| 4 | if( ! class_exists( 'WP_List_Table' ) ){ |
||
|
0 ignored issues
–
show
|
|||
| 5 | require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ); |
||
|
0 ignored issues
–
show
|
|||
| 6 | } |
||
| 7 | |||
| 8 | class Button_List_Table extends \WP_List_Table { |
||
|
0 ignored issues
–
show
Class name "Button_List_Table" is not in PascalCase format
Classes in PHP are usually named in CamelCase. In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well. Thus the name database provider becomes Loading history...
|
|||
| 9 | |||
| 10 | function __construct(){ |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
It is recommend to declare an explicit visibility for
__construct.
Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed. If you are not sure which visibility to choose, it is a good idea to start with
the most restrictive visibility, and then raise visibility as needed, i.e.
start with Loading history...
|
|||
| 11 | global $status, $page; |
||
| 12 | |||
| 13 | // Set parent defaults |
||
|
0 ignored issues
–
show
|
|||
| 14 | parent::__construct( array( |
||
|
0 ignored issues
–
show
|
|||
| 15 | 'singular' => 'feed', // singular name of the listed records |
||
|
0 ignored issues
–
show
|
|||
| 16 | 'plural' => 'feeds', // plural name of the listed records |
||
|
0 ignored issues
–
show
|
|||
| 17 | 'ajax' => false // does this table support ajax? |
||
|
0 ignored issues
–
show
|
|||
| 18 | ) ); |
||
|
0 ignored issues
–
show
For multi-line function calls, the closing parenthesis should be on a new line.
If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line: someFunctionCall(
$firstArgument,
$secondArgument,
$thirdArgument
); // Closing parenthesis on a new line.
Loading history...
|
|||
| 19 | } |
||
|
0 ignored issues
–
show
|
|||
| 20 | |||
| 21 | function column_name( $button ) { |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
It is recommend to declare an explicit visibility for
column_name.
Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed. If you are not sure which visibility to choose, it is a good idea to start with
the most restrictive visibility, and then raise visibility as needed, i.e.
start with Loading history...
|
|||
| 22 | |||
| 23 | $actions = array( |
||
| 24 | 'edit' => Settings\Buttons::get_action_link( $button, __( 'Edit', 'podlove-subscribe-button' ), 'edit' ), |
||
| 25 | 'delete' => Settings\Buttons::get_action_link( $button, __( 'Delete', 'podlove-subscribe-button' ), 'confirm_delete' ) |
||
|
0 ignored issues
–
show
|
|||
| 26 | ); |
||
| 27 | |||
| 28 | return sprintf('%1$s %2$s', |
||
|
0 ignored issues
–
show
|
|||
| 29 | /*$1%s*/ sanitize_title($button->title) . '<br><code>[podlove-subscribe-button button="' . sanitize_text_field($button->name) . '"]</code>', |
||
|
0 ignored issues
–
show
|
|||
| 30 | /*$3%s*/ $this->row_actions( $actions ) |
||
| 31 | ); |
||
| 32 | } |
||
|
0 ignored issues
–
show
|
|||
| 33 | |||
| 34 | function column_button_preview( $button ) { |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
It is recommend to declare an explicit visibility for
column_button_preview.
Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed. If you are not sure which visibility to choose, it is a good idea to start with
the most restrictive visibility, and then raise visibility as needed, i.e.
start with Loading history...
|
|||
| 35 | |||
| 36 | if ( ! $button->feeds ) { |
||
| 37 | return '<code>' . __( 'No preview. Please set a feed.', 'podlove-subscribe-button' ) . '</code>'; |
||
| 38 | } else { |
||
| 39 | |||
| 40 | $preview = "<div class='podlove-button-preview-container'>"; |
||
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. Loading history...
|
|||
| 41 | $preview .= $button->render( |
||
| 42 | 'big', |
||
| 43 | 'false', |
||
| 44 | get_option( 'podlove_subscribe_button_default_style', 'filled' ), |
||
| 45 | 'rectangle' |
||
| 46 | ); |
||
| 47 | $preview .= "</div>"; |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
</div> does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. Loading history...
|
|||
| 48 | |||
| 49 | return $preview; |
||
| 50 | |||
| 51 | } |
||
| 52 | |||
| 53 | } |
||
| 54 | |||
| 55 | |||
| 56 | function column_id( $button ) { |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
It is recommend to declare an explicit visibility for
column_id.
Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed. If you are not sure which visibility to choose, it is a good idea to start with
the most restrictive visibility, and then raise visibility as needed, i.e.
start with Loading history...
|
|||
| 57 | return $button->id; |
||
| 58 | } |
||
|
0 ignored issues
–
show
|
|||
| 59 | |||
| 60 | function get_columns(){ |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
It is recommend to declare an explicit visibility for
get_columns.
Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed. If you are not sure which visibility to choose, it is a good idea to start with
the most restrictive visibility, and then raise visibility as needed, i.e.
start with Loading history...
|
|||
| 61 | return array( |
||
| 62 | 'name' => __( 'Title & Shortcode', 'podlove-subscribe-button' ), |
||
|
0 ignored issues
–
show
|
|||
| 63 | 'button_preview' => __( 'Preview', 'podlove-subscribe-button' ), |
||
|
0 ignored issues
–
show
|
|||
| 64 | ); |
||
| 65 | } |
||
|
0 ignored issues
–
show
|
|||
| 66 | |||
| 67 | function prepare_items() { |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
It is recommend to declare an explicit visibility for
prepare_items.
Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed. If you are not sure which visibility to choose, it is a good idea to start with
the most restrictive visibility, and then raise visibility as needed, i.e.
start with Loading history...
|
|||
| 68 | // number of items per page |
||
|
0 ignored issues
–
show
|
|||
| 69 | $per_page = 1000; |
||
| 70 | |||
| 71 | // define column headers |
||
|
0 ignored issues
–
show
|
|||
| 72 | $columns = $this->get_columns(); |
||
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 15 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. Loading history...
|
|||
| 73 | $hidden = array(); |
||
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 16 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. Loading history...
|
|||
| 74 | $sortable = $this->get_sortable_columns(); |
||
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 14 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. Loading history...
|
|||
| 75 | $this->_column_headers = array( $columns, $hidden, $sortable ); |
||
| 76 | |||
| 77 | // retrieve data |
||
| 78 | // TODO select data for current page only |
||
|
0 ignored issues
–
show
|
|||
| 79 | $data = ( is_network_admin() ? \PodloveSubscribeButton\Model\NetworkButton::all() : \PodloveSubscribeButton\Model\Button::all() ); |
||
| 80 | |||
| 81 | // get current page |
||
|
0 ignored issues
–
show
|
|||
| 82 | $current_page = $this->get_pagenum(); |
||
| 83 | // get total items |
||
|
0 ignored issues
–
show
|
|||
| 84 | $total_items = count( $data ); |
||
| 85 | // extrage page for current page only |
||
|
0 ignored issues
–
show
|
|||
| 86 | $data = array_slice( $data, ( ( $current_page - 1 ) * $per_page ) , $per_page ); |
||
|
0 ignored issues
–
show
|
|||
| 87 | // add items to table |
||
|
0 ignored issues
–
show
|
|||
| 88 | $this->items = $data; |
||
| 89 | |||
| 90 | // register pagination options & calculations |
||
|
0 ignored issues
–
show
|
|||
| 91 | $this->set_pagination_args( array( |
||
|
0 ignored issues
–
show
|
|||
| 92 | 'total_items' => $total_items, |
||
| 93 | 'per_page' => $per_page, |
||
| 94 | 'total_pages' => ceil( $total_items / $per_page ) |
||
|
0 ignored issues
–
show
|
|||
| 95 | ) ); |
||
|
0 ignored issues
–
show
For multi-line function calls, the closing parenthesis should be on a new line.
If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line: someFunctionCall(
$firstArgument,
$secondArgument,
$thirdArgument
); // Closing parenthesis on a new line.
Loading history...
|
|||
| 96 | } |
||
|
0 ignored issues
–
show
|
|||
| 97 | |||
| 98 | } |
||
| 99 |