Passed
Push — master ( de22c5...c65969 )
by Nirjhar
02:47 queued 20s
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->execute();
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 scan() {
109
110
			if ( class_exists( 'CGSS_SCAN' ) ) new CGSS_SCAN();
111
		}
112
113
114
115
		//Add files for crawling as external resource
116
		public function vendor() {
117
118
			require_once ('vendor/lib/tags.php');
119
			require_once ('vendor/lib/text.php');
120
			require_once ('vendor/lib/keywords.php');
121
			require_once ('vendor/lib/social.php');
122
			require_once ('vendor/lib/server.php');
123
			require_once ('vendor/lib/design.php');
124
			require_once ('vendor/lib/score.php');
125
			require_once ('vendor/crawl.php');
126
		}
127
128
129
130
		//Add functionality files
131
		public function functionality() {
132
133
			require_once ('src/db.php');
134
			require_once ('src/install.php');
135
			require_once ('src/settings.php');
136
		}
137
138
139
140
		//Call the dependency files
141
		public function helpers() {
142
143
			if ( ! class_exists( 'WP_List_Table' ) ) {
144
    			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...
145
    			require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
146
			}
147
148
			require_once ('lib/table.php');
149
			require_once ('lib/overview-table.php');
150
			require_once ('lib/script.php');
151
152
			require_once ('lib/action/scan.php');
153
			require_once ('lib/action/insight.php');
154
		}
155
156
157
158
		public function __construct() {
159
160
			$this->vendor();
161
			$this->helpers();
162
			$this->functionality();
163
164
			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

164
			/** @scrutinizer ignore-call */ 
165
   register_activation_hook( CGSS_FILE, array( $this, 'db_install' ) );
Loading history...
165
			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

165
			/** @scrutinizer ignore-call */ 
166
   register_uninstall_hook( CGSS_FILE, array( 'CGSS_BUILD', 'db_uninstall' ) ); //$this won't work here.
Loading history...
166
167
			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

167
			/** @scrutinizer ignore-call */ 
168
   add_action('init', array($this, 'installation'));
Loading history...
168
169
			$this->scripts();
170
			$this->settings();
171
172
			// Add custom actions, defined in settings
173
			add_action( 'cgss_scan', array( $this, 'scan' ) );
174
			add_action( 'cgss_fetch_insight', array( $this, 'insight' ) );
175
		}
176
	}
177
} ?>
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...
178