Button_List_Table::column_button_preview()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 1
dl 0
loc 14
rs 9.9332
c 0
b 0
f 0
1
<?php
0 ignored issues
show
introduced by
Filenames should be all lowercase with hyphens as word separators. Expected buttons-list-table.php, but found buttons_list_table.php.
Loading history...
introduced by
Class file names should be based on the class name with "class-" prepended. Expected class-button-list-table.php, but found buttons_list_table.php.
Loading history...
Coding Style introduced by
This file is missing a doc comment.
Loading history...
2
namespace PodloveSubscribeButton;
3
4
if( ! class_exists( 'WP_List_Table' ) ){
0 ignored issues
show
Coding Style introduced by
Expected 1 space after IF keyword; 0 found
Loading history...
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
introduced by
Space between opening control structure and closing parenthesis is required
Loading history...
5
    require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
0 ignored issues
show
Coding Style introduced by
"require_once" is a statement not a function; no parentheses are required
Loading history...
6
}
7
8
class Button_List_Table extends \WP_List_Table {
0 ignored issues
show
Coding Style introduced by
This class is not in CamelCase 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 DatabaseProvider.

Loading history...
Coding Style Documentation introduced by
Missing class doc comment
Loading history...
9
10
	function __construct(){
0 ignored issues
show
Coding Style Documentation introduced by
Missing function doc comment
Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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 private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
Coding Style introduced by
Expected 1 space before opening brace; found 0
Loading history...
11
		global $status, $page;
12
		        
13
		// Set parent defaults
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
14
		parent::__construct( array(
15
		    'singular'  => 'feed',   // singular name of the listed records
0 ignored issues
show
introduced by
Array double arrow not aligned correctly; expected 1 space(s) between "'singular'" and double arrow, but found 2.
Loading history...
16
		    'plural'    => 'feeds',  // plural name of the listed records
0 ignored issues
show
introduced by
Array double arrow not aligned correctly; expected 3 space(s) between "'plural'" and double arrow, but found 4.
Loading history...
17
		    'ajax'      => false  // does this table support ajax?
0 ignored issues
show
introduced by
Array double arrow not aligned correctly; expected 5 space(s) between "'ajax'" and double arrow, but found 6.
Loading history...
introduced by
Each array item in a multi-line array declaration must end in a comma
Loading history...
18
		) );
19
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
20
	
21
	function column_name( $button ) {
0 ignored issues
show
Coding Style Documentation introduced by
Missing function doc comment
Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
Method name "Button_List_Table::column_name" is not in camel caps format
Loading history...
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 private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

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
introduced by
Each array item in a multi-line array declaration must end in a comma
Loading history...
26
		);
27
	
28
		return sprintf('%1$s %2$s',
29
		    /*$1%s*/ $button->title . '<br><code>[podlove-subscribe-button button="' . $button->name . '"]</code>',
30
		    /*$3%s*/ $this->row_actions( $actions )
31
		);
32
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
33
34
	function column_button_preview( $button ) {
0 ignored issues
show
Coding Style Documentation introduced by
Missing function doc comment
Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
Method name "Button_List_Table::column_button_preview" is not in camel caps format
Loading history...
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 private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
35
		if ( ! $button->feeds )
0 ignored issues
show
Coding Style Best Practice introduced by
It is generally a best practice to always use braces with control structures.

Adding braces to control structures avoids accidental mistakes as your code changes:

// Without braces (not recommended)
if (true)
    doSomething();

// Recommended
if (true) {
    doSomething();
}
Loading history...
36
			return;
37
38
		$is_network = is_network_admin();
0 ignored issues
show
Unused Code introduced by
The assignment to $is_network is dead and can be removed.
Loading history...
39
40
		return "<div class='podlove-button-preview-container'>"
41
			. $button->render(
42
					'big',
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 16 spaces, but found 20.
Loading history...
43
					'false',
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 16 spaces, but found 20.
Loading history...
44
					get_option('podlove_subscribe_button_default_style', 'filled'),
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 16 spaces, but found 20.
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
45
					'rectangle'
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 16 spaces, but found 20.
Loading history...
46
				) 
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 12 spaces, but found 16.
Loading history...
47
			. "</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 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

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 (\') and the backslash (\\). Every other character is displayed as is.

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: Single is Value

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
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
49
	
50
	function column_id( $button ) {
0 ignored issues
show
Coding Style Documentation introduced by
Missing function doc comment
Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
Method name "Button_List_Table::column_id" is not in camel caps format
Loading history...
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 private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
51
		return $button->id;
52
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
53
54
	function get_columns(){
0 ignored issues
show
Coding Style Documentation introduced by
Missing function doc comment
Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
Method name "Button_List_Table::get_columns" is not in camel caps format
Loading history...
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 private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
Coding Style introduced by
Expected 1 space before opening brace; found 0
Loading history...
55
		return array(
56
			'name'    => __( 'Title & Shortcode', 'podlove-subscribe-button' ),
0 ignored issues
show
introduced by
Array double arrow not aligned correctly; expected 11 space(s) between "'name'" and double arrow, but found 4.
Loading history...
57
			'button_preview'    => __( 'Preview', 'podlove-subscribe-button' )
0 ignored issues
show
introduced by
Array double arrow not aligned correctly; expected 1 space(s) between "'button_preview'" and double arrow, but found 4.
Loading history...
introduced by
Each array item in a multi-line array declaration must end in a comma
Loading history...
58
		);
59
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
60
	
61
	function prepare_items() {
0 ignored issues
show
Coding Style Documentation introduced by
Missing function doc comment
Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
Method name "Button_List_Table::prepare_items" is not in camel caps format
Loading history...
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 private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
62
		// number of items per page
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
63
		$per_page = 1000;
64
		
65
		// define column headers
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
66
		$columns = $this->get_columns();
0 ignored issues
show
Coding Style introduced by
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...
67
		$hidden = array();
0 ignored issues
show
Coding Style introduced by
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...
68
		$sortable = $this->get_sortable_columns();
0 ignored issues
show
Coding Style introduced by
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...
69
		$this->_column_headers = array( $columns, $hidden, $sortable );
70
		
71
		// retrieve data
72
		// TODO select data for current page only
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
73
		$data = ( is_network_admin() ? \PodloveSubscribeButton\Model\NetworkButton::all() : \PodloveSubscribeButton\Model\Button::all() );
74
75
		// get current page
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
76
		$current_page = $this->get_pagenum();
77
		// get total items
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
78
		$total_items = count( $data );
79
		// extrage page for current page only
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
80
		$data = array_slice( $data, ( ( $current_page - 1 ) * $per_page ) , $per_page );
0 ignored issues
show
Coding Style introduced by
Space found before comma in function call
Loading history...
81
		// add items to table
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
82
		$this->items = $data;
83
		
84
		// register pagination options & calculations
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
85
		$this->set_pagination_args( array(
86
		    'total_items' => $total_items,
87
		    'per_page'    => $per_page,
88
		    'total_pages' => ceil( $total_items / $per_page )
0 ignored issues
show
introduced by
Each array item in a multi-line array declaration must end in a comma
Loading history...
89
		) );
90
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
91
92
}