Passed
Push — master ( e0c498...d80a24 )
by Nirjhar
04:11
created

autoload.php (11 issues)

1
<?php
2
if ( ! defined( 'ABSPATH' ) ) exit;
3
4
//Main plugin object to define the plugin
5
if ( ! class_exists( 'CGSS_BUILD' ) ) {
6
	
7
	final class CGSS_BUILD {
8
9
10
11
		public function installation() {
12
13
			if (class_exists('CGSS_INSTALL')) {
14
15
				$install = new CGSS_INSTALL();
16
				$install->textDomin = 'cgss';
17
				$install->phpVerAllowed = '5.4';
18
				$install->pluginPageLinks = array(
19
												array(
20
													'slug' => home_url().'/wp-admin/admin.php?page=seo-scan',
0 ignored issues
show
The function home_url 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

20
													'slug' => /** @scrutinizer ignore-call */ home_url().'/wp-admin/admin.php?page=seo-scan',
Loading history...
21
													'label' => __( 'Dashboard', '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

21
													'label' => /** @scrutinizer ignore-call */ __( 'Dashboard', 'cgss' )
Loading history...
22
												),
23
											);
24
				$install->do();
25
			}
26
		}
27
28
29
		public function db_install() {
30
31
			if ( class_exists( 'CGSS_DB' ) ) {
32
				$db = new CGSS_DB();
33
				$db->table = 'cgss_insight';
34
				$db->sql = "ID mediumint(9) NOT NULL AUTO_INCREMENT,
35
							item varchar(256) NOT NULL,
36
							remark varchar(512) NOT NULL,
37
							UNIQUE KEY ID (ID)";
38
				$db->build();
39
40
				$insert_data = $this->insert_prelim_data();
0 ignored issues
show
Are you sure the assignment to $insert_data is correct as $this->insert_prelim_data() targeting CGSS_BUILD::insert_prelim_data() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
The assignment to $insert_data is dead and can be removed.
Loading history...
41
			}
42
		}
43
44
45
		public function db_uninstall() {
46
47
			$tableName = 'cgss_insight';
48
49
			global $wpdb;
50
			$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}$tableName" );
51
		}
52
53
54
		public function insert_prelim_data() {
55
56
			global $wpdb;
57
58
			$result = $wpdb->get_results("SELECT * from {$wpdb->prefix}cgss_insight");
59
    		if(count($result) == 0) {
60
61
			$init_insight = array(
62
					__('Score','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

62
					/** @scrutinizer ignore-call */ 
63
     __('Score','cgss'),
Loading history...
63
					__('Snippet','cgss'),
64
					__('Text','cgss'),
65
					__('Links','cgss'),
66
					__('Keywords','cgss'),
67
					__('Images','cgss'),
68
					__('Responsive','cgss'),
69
					__('Speed','cgss'),
70
					__('Social','cgss')
71
				);
72
			$no_data = __( 'No scan reports are available yet', 'cgss' );
73
			foreach ($init_insight as $key => $value) {
74
				$sql = $wpdb->prepare(
75
					"INSERT INTO {$wpdb->prefix}cgss_insight ( ID, item, remark ) VALUES ( %d, %s, %s )", ($key+1), $value, $no_data
76
					);
77
				$query = $wpdb->query($sql);
0 ignored issues
show
The assignment to $query is dead and can be removed.
Loading history...
78
			}
79
			}
80
		}
81
82
83
		//Include scripts
84
		public function scripts() {
85
86
			if ( class_exists( 'CGSS_SCRIPT' ) ) new CGSS_SCRIPT();
87
		}
88
89
90
91
		//Include settings pages
92
		public function settings() {
93
94
			if ( class_exists( 'CGSS_SETTINGS' ) ) new CGSS_SETTINGS();
95
		}
96
97
98
99
		// Add custom insight action
100
		public function insight() {
101
102
			if ( class_exists( 'CGSS_INSIGHT' ) ) new CGSS_INSIGHT();
103
		}
104
105
106
107
		// Add custom insight action
108
		public function compete() {
109
110
			if ( class_exists( 'CGSS_COMPETE' ) ) new CGSS_COMPETE();
111
		}
112
113
114
115
		// Add custom insight action
116
		public function scan() {
117
118
			if ( class_exists( 'CGSS_SCAN' ) ) new CGSS_SCAN();
119
		}
120
121
122
123
		//Add files for crawling as external resource
124
		public function vendor() {
125
126
			require_once ('vendor/lib/tags.php');
127
			require_once ('vendor/lib/text.php');
128
			require_once ('vendor/lib/keywords.php');
129
			require_once ('vendor/lib/social.php');
130
			require_once ('vendor/lib/server.php');
131
			require_once ('vendor/lib/design.php');
132
			require_once ('vendor/lib/score.php');
133
			require_once ('vendor/crawl.php');
134
		}
135
136
137
138
		//Add functionality files
139
		public function functionality() {
140
141
			require_once ('src/db.php');
142
			require_once ('src/install.php');
143
			require_once ('src/settings.php');
144
		}
145
146
147
148
		//Call the dependency files
149
		public function helpers() {
150
151
			if ( ! class_exists( 'WP_List_Table' ) ) {
152
    			require_once( ABSPATH . 'wp-admin/includes/screen.php' );
0 ignored issues
show
The constant ABSPATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
153
    			require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
154
			}
155
156
			require_once ('lib/table.php');
157
			require_once ('lib/overview-table.php');
158
			require_once ('lib/script.php');
159
160
			require_once ('lib/action/scan.php');
161
			require_once ('lib/action/compete.php');
162
			require_once ('lib/action/insight.php');
163
		}
164
165
166
167
		public function __construct() {
168
169
			$this->vendor();
170
			$this->helpers();
171
			$this->functionality();
172
173
			register_activation_hook( CGSS_FILE, array( $this, 'db_install' ) );
0 ignored issues
show
The function register_activation_hook 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

173
			/** @scrutinizer ignore-call */ 
174
   register_activation_hook( CGSS_FILE, array( $this, 'db_install' ) );
Loading history...
174
			register_uninstall_hook( CGSS_FILE, array( 'CGSS_BUILD', 'db_uninstall' ) ); //$this won't work here.
0 ignored issues
show
The function register_uninstall_hook 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

174
			/** @scrutinizer ignore-call */ 
175
   register_uninstall_hook( CGSS_FILE, array( 'CGSS_BUILD', 'db_uninstall' ) ); //$this won't work here.
Loading history...
175
176
			add_action('init', array($this, 'installation'));
0 ignored issues
show
The function add_action 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

176
			/** @scrutinizer ignore-call */ 
177
   add_action('init', array($this, 'installation'));
Loading history...
177
178
			$this->scripts();
179
180
			$this->settings();
181
182
			// Add custom actions, defined in settings
183
			add_action( 'cgss_scan', array( $this, 'scan' ) );
184
			add_action( 'cgss_compete', array( $this, 'compete' ) );
185
			add_action( 'cgss_fetch_insight', array( $this, 'insight' ) );
186
		}
187
	}
188
} ?>
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...