Passed
Push — master ( ab9b1d...ea9273 )
by Nirjhar
04:28
created

CGSS_OVERVIEW_TABLE::no_items()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * Implimentation of WordPress inbuilt functions for creating an extension of a default table class.
4
 *
5
 * $myPluginNameTable = new CGSS_OVERVIEW_TABLE();
6
 * $myPluginNameTable->prepare_items();
7
 * $myPluginNameTable->display();
8
 *
9
 */
10
if ( ! class_exists( 'CGSS_OVERVIEW_TABLE' ) ) {
11
12
	final class CGSS_OVERVIEW_TABLE extends WP_List_Table {
0 ignored issues
show
Bug introduced by
The type WP_List_Table was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
14
15
16
		public function __construct() {
17
18
			parent::__construct( [
19
				'singular' => __( 'Insight', 'textdomain' ),
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

19
				'singular' => /** @scrutinizer ignore-call */ __( 'Insight', 'textdomain' ),
Loading history...
20
				'plural'   => __( 'Inssight', 'textdomain' ),
21
				'ajax'     => false,
22
			] );
23
		}
24
25
26
27
		//fetch the data using custom named method function
28
		public static function get_insight() {
29
30
			global $wpdb;
31
32
			//Build the db query base
33
			$sql = "SELECT * FROM {$wpdb->prefix}cgss_insight";
34
35
			//get the data from database
36
			$result = $wpdb->get_results( $sql, 'ARRAY_A' );
37
38
			return $result;
39
		}
40
41
42
43
		//If there is no data to show
44
		public function no_items() {
45
46
			_e( 'Database is empty. Please reactivate the plugin.', 'cgss' );
0 ignored issues
show
Bug introduced by
The function _e was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
			/** @scrutinizer ignore-call */ 
47
   _e( 'Database is empty. Please reactivate the plugin.', 'cgss' );
Loading history...
47
		}
48
49
50
51
		//How many rows are present there
52
		public static function record_count() {
53
54
			global $wpdb;
55
56
			//Build the db query base
57
			$sql = "SELECT COUNT(*) FROM {$wpdb->prefix}cgss_insight";
58
59
			return $wpdb->get_var( $sql );
60
		}
61
62
63
64
		//Display columns content
65
		public function column_name( $item ) {
66
67
			$title = sprintf( '<strong>%s</strong>', $item['item'] );
68
69
			//Change the page instruction where you want to show it
70
			$actions = array();
71
			return $title . $this->row_actions( $actions );
72
		}
73
74
75
76
		//set coulmns name
77
		public function column_default( $item, $column_name ) {
78
79
			switch ( $column_name ) {
80
81
				case 'item':
82
					//This is the first column
83
					return $this->column_name( $item );
84
				case 'remark':
85
					return $item[ $column_name ];
86
87
				default:
88
89
					//Show the whole array for troubleshooting purposes
90
					return print_r( $item, true );
91
			}
92
		}
93
94
95
96
		//Columns callback
97
		public function get_columns() {
98
99
			$columns = array(
100
							'item'	=> __( 'Item', 'textdomain' ),
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

100
							'item'	=> /** @scrutinizer ignore-call */ __( 'Item', 'textdomain' ),
Loading history...
101
							'remark'	=> __( 'Remark', 'textdomain' ),
102
						);
103
			return $columns;
104
		}
105
106
107
108
		//Prapare the display variables for screen options
109
		public function prepare_items() {
110
111
			$this->_column_headers = $this->get_column_info();
0 ignored issues
show
Bug Best Practice introduced by
The property _column_headers does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
112
			$this->items = self::get_insight();
0 ignored issues
show
Bug Best Practice introduced by
The property items does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
113
		}
114
	}
115
} ?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
116