Issues (203)

Plugin/Lib/OverviewTable.php (7 issues)

1
<?php
2
namespace NirjharLo\Cgss\Lib;
3
4
if ( ! defined( 'ABSPATH' ) ) exit;
5
6
use \WP_List_Table;
0 ignored issues
show
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...
7
8
/**
9
 * Implimentation of WordPress inbuilt functions for creating an extension of a default table class.
10
 *
11
 * $myPluginNameTable = new CGSS_OVERVIEW_TABLE();
12
 * $myPluginNameTable->prepare_items();
13
 * $myPluginNameTable->display();
14
 *
15
 */
16
17
	final class OverviewTable extends WP_List_Table {
18
19
20
21
		public function __construct() {
22
23
			parent::__construct( [
24
				'singular' => __( 'Insight', 'cgss' ),
0 ignored issues
show
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

24
				'singular' => /** @scrutinizer ignore-call */ __( 'Insight', 'cgss' ),
Loading history...
25
				'plural'   => __( 'Inssight', 'cgss' ),
26
				'ajax'     => false,
27
			] );
28
		}
29
30
31
32
		//fetch the data using custom named method function
33
		public static function get_insight() {
34
35
			global $wpdb;
36
37
			//Build the db query base
38
			$sql = "SELECT * FROM {$wpdb->prefix}cgss_insight";
39
40
			//get the data from database
41
			$result = $wpdb->get_results( $sql, 'ARRAY_A' );
42
43
			return $result;
44
		}
45
46
47
48
		//If there is no data to show
49
		public function no_items() {
50
51
			_e( 'Database is empty. Please reactivate the plugin.', 'cgss' );
0 ignored issues
show
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

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

105
							'item'	=> /** @scrutinizer ignore-call */ __( 'Item', 'cgss' ),
Loading history...
106
							'remark'	=> __( 'Remark', 'cgss' ),
107
						);
108
			return $columns;
109
		}
110
111
112
113
		//Prapare the display variables for screen options
114
		public function prepare_items() {
115
116
			$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...
117
			$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...
118
		}
119
	} ?>
0 ignored issues
show
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...
120