Passed
Push — master ( 27be6d...bb494a )
by Nirjhar
02:28
created

CGSS_SCAN::snippet_display()   B

Complexity

Conditions 6
Paths 1

Size

Total Lines 29
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 18
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 29
rs 8.439
1
<?php
2
if ( ! defined( 'ABSPATH' ) ) exit;
3
4
/**
5
 * Perform scan action
6
 */
7
if ( ! class_exists( 'CGSS_SCAN' ) ) {
8
9
	final class CGSS_SCAN {
10
11
12
		public function __construct() {
13
14
			$post_id = intval($_GET['scan']);
15
			$url = get_permalink( $post_id );
0 ignored issues
show
Bug introduced by
The function get_permalink 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

15
			$url = /** @scrutinizer ignore-call */ get_permalink( $post_id );
Loading history...
16
17
			if (class_exists('CGSS_CRAWL')) {
18
19
				$crawl = new CGSS_CRAWL();
0 ignored issues
show
Bug introduced by
The type CGSS_CRAWL 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...
20
				$crawl->url = esc_url_raw($url);
0 ignored issues
show
Bug introduced by
The function esc_url_raw 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
				$crawl->url = /** @scrutinizer ignore-call */ esc_url_raw($url);
Loading history...
21
				$crawl->do();
22
				$this->result = $crawl->result();
0 ignored issues
show
Bug Best Practice introduced by
The property result does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
23
24
				update_post_meta( $post_id, 'cgss_scan_result', $this->result );
0 ignored issues
show
Bug introduced by
The function update_post_meta 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
				/** @scrutinizer ignore-call */ 
25
    update_post_meta( $post_id, 'cgss_scan_result', $this->result );
Loading history...
25
26
				$this->render();
27
			}
28
		}
29
30
31
		//Display the score
32
		public function score_html() {
33
34
			$score = $this->result['score'];
35
			$social = $this->result['social'];
36
			$gplus = $social['gplus'];
37
			$fb_share = $social['fb_share'];
38
			$fb_like = $social['fb_like'];
39
40
			$score_html = 
41
			'<span>'.sprintf(__('Overall SEO score %d out of 10. Total gPlus shares: %d Facebook shares: %d and likes: %d', 'cgss' ), $score, $gplus, $fb_share, $fb_like ).'</span>';
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

41
			'<span>'.sprintf(/** @scrutinizer ignore-call */ __('Overall SEO score %d out of 10. Total gPlus shares: %d Facebook shares: %d and likes: %d', 'cgss' ), $score, $gplus, $fb_share, $fb_like ).'</span>';
Loading history...
42
43
			return $score_html;
44
		}
45
46
47
		// Display the snippets
48
		public function snippet_display() {
49
50
			$snippet = $this->result['snip'];
51
			$title = $snippet['title'];
52
			$desc = $snippet['desc'];
53
54
			$social_snippet = $this->result['social_tags'];
55
			$social_title = $social_snippet['title'];
56
			$social_desc = $social_snippet['description'];
57
			$social_image = $social_snippet['image'];
58
59
			$not_found = __('NOT_FOUND', 'cgss');
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

59
			$not_found = /** @scrutinizer ignore-call */ __('NOT_FOUND', 'cgss');
Loading history...
60
			$snippet_html = 
61
			'<ul>
62
				<li><strong>'.__('Search snippet', 'cgss').':</strong>
63
					<ul>
64
						<li>'.sprintf(__('Title: %s', 'cgss'),($title ? $title : $not_found)).'</li>
65
						<li>'.sprintf(__('Description: %s', 'cgss'),($desc ? $desc : $not_found)).'</li>
66
					</ul>
67
				</li>
68
				<li><strong>'.__('Social snippet(OGP)', 'cgss').':</strong>
69
					<ul>
70
						<li>'.sprintf(__('Title: %s', 'cgss'),($social_title ? $social_title : $not_found)).'</li>
71
						<li>'.sprintf(__('Description: %s', 'cgss'),( $social_desc ? $social_desc : $not_found)).'</li>
72
						<li>'.sprintf(__('Image: %s', 'cgss'),( $social_image ? $social_image : $not_found)).'</li>
73
					</ul></li>
74
			</ul>';
75
76
			return $snippet_html;
77
		}
78
79
80
		// Display text and link data
81
		public function text_display() {
82
83
			$text = $this->result['text'];
84
			$keys = implode(', ', array_keys($text['keys']));
85
			$count = $text['count'];
86
			$ratio = $text['ratio'];
87
88
			$htags = $text['htags'];
89
			$headings = implode( ', ', $htags['names'] );
90
91
			$links = $text['links'];
92
			$link_count = $links['count'];
93
			$link_nofollow = $links['nofollow'];
94
			$link_external = $links['external'];
95
96
			$text_html = 
97
			'<ul>
98
				<li>'.sprintf(__('Keywords: %s','cgss'), $keys).'</li>
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

98
				<li>'.sprintf(/** @scrutinizer ignore-call */ __('Keywords: %s','cgss'), $keys).'</li>
Loading history...
99
				<li>'.sprintf(__('Number of words: %s','cgss'), $count).'</li>
100
				<li>'.sprintf(__('Text to html ratio: %s percent','cgss'), $ratio).'</li>
101
				<li>'.sprintf(__('Heading tags in text hierarchy: %s','cgss'), $headings).'</li>
102
				<li>'.sprintf(__('Total Links: %d, Nofollow Links %d, External Links: %d','cgss'), $link_count, $link_nofollow, $link_external).'</li>
103
			</ul>';
104
105
			return $text_html;
106
		}
107
108
109
		// Display design data
110
		public function design_display() {
111
112
113
			$design = $this->result['design'];
114
115
			$iframe = $design['iframe'];
116
117
			$tag_style = $design['tag_style'];
118
			$tag_style_count = $tag_style['count'];
119
			$tag_style_attributes = implode( ', ', $tag_style['tags'] );
120
121
			$nested_table = $design['nested_table'];
122
			$vport = $design['vport'];
123
			$media = $design['media'];
124
			$image = $design['image'];
125
			$image_count = $image['count'];
126
			$image_no_alt_count = $image['no_alt_count'];
127
128
			$design_html = 
129
			'<ul>
130
				<li>'.sprintf(__('Total images: %d and images without alt tags: %d','cgss'), $image_count, $image_no_alt_count).'</li>
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

130
				<li>'.sprintf(/** @scrutinizer ignore-call */ __('Total images: %d and images without alt tags: %d','cgss'), $image_count, $image_no_alt_count).'</li>
Loading history...
131
				<li>'.sprintf(__('iframe: %d','cgss'), $iframe).'</li>
132
				<li>'.sprintf(__('Nested Tables: %d','cgss'), $nested_table).'</li>
133
				<li>'.sprintf(__('Tags with style attribute: %s(%s)','cgss'), $tag_style_count, $tag_style_attributes).'</li>
134
				<li>'.sprintf(__('Mobile optimization: Viewport Tag: %d, @media Queries: %d','cgss'), $vport, $media).'</li>
135
			</ul>';
136
137
			return $design_html;
138
		}
139
140
141
		// Display crawl data
142
		public function crawl_display() {
143
144
			$crawl = $this->result['crawl'];
145
146
			$ssl = $crawl['ssl'];
147
			$dynamic = $crawl['dynamic'];
148
			$underscore = $crawl['underscore'];
149
150
			$ip = $crawl['ip'];
151
			$cano = $crawl['cano'];
152
			$if_mod = $crawl['if_mod'];
153
			$alive = $crawl['alive'];
154
			$robot = $crawl['meta_robot'];
155
156
			$on = __( 'on', 'cgss' );
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

156
			$on = /** @scrutinizer ignore-call */ __( 'on', 'cgss' );
Loading history...
157
			$off = __( 'off', 'cgss' );
158
159
			$crawl_html = 
160
			'<ul>
161
				<li>'.sprintf(__('Your URL parameters: SSL security: %s, Static url: %s, underscores in Url: %s','cgss'), (!$ssl ? $off : $on ), (!$dynamic ? $off : $on ), (!$underscore ? $off : $on )).'</li>
162
				<li>'.sprintf(__('If modified since header: %s','cgss'), ($if_mod == 0 ? $off : $on )).'</li>
163
				<li>'.sprintf(__('Canonical Url: %s','cgss'), ($cano == 0 ? $off : $on )).'</li>
164
				<li>'.sprintf(__('Meta Robot: %s','cgss'), (!$robot['ok'] ? $off : $on )).'</li>
165
				<li>'.sprintf(__('IP Forward: %s','cgss'), ($ip ? $ip : $off )).'</li>
166
				<li>'.sprintf(__('Keep alive connection: %s','cgss'), ($alive == 0 ? $off : $on )).'</li>
167
			</ul>';
168
169
			return $crawl_html;
170
		}
171
172
173
		// Display speed data
174
		public function speed_display() {
175
176
			$speed = $this->result['speed'];
177
178
			$res_time = $speed['res_time'];
179
			$down_time = $speed['down_time'];
180
			$gzip = $speed['gzip'];
181
			$cache = $speed['cache'];
182
			$css = $speed['css'];
183
			$js = $speed['js'];
184
185
			$on = __( 'on', 'cgss' );
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

185
			$on = /** @scrutinizer ignore-call */ __( 'on', 'cgss' );
Loading history...
186
			$off = __( 'off', 'cgss' );
187
188
			$speed_html = 
189
			'<ul>
190
				<li>'. sprintf( __( 'Header response time %s s and page downloading time %s s', 'cgss' ), $res_time, $down_time ). '</li>
191
				<li>'.sprintf(__('gZip compression: %s','cgss'), ($gzip ? $off : $on )).'</li>
192
				<li>'.sprintf(__('Browser caching: %s','cgss'), ($cache ? $off : $on )).'</li>
193
				<li>'.sprintf(__('Requests made by CSS is %s and by JS is %s','cgss'), $css['count'], $js['count']).'</li>
194
				<li>'.sprintf(__('Resources can be compressed by %s kb for CSS and %s kb for JS','cgss'), $css['compress_num'], $js['compress_num']).'</li>
195
			</ul>';
196
197
			return $speed_html;
198
		}
199
200
201
		// Render the HTML
202
		public function render() {
203
204
			$this->score_html	= $this->score_html();
0 ignored issues
show
Bug Best Practice introduced by
The property score_html does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
205
			$this->snippets_html	= $this->snippet_display();
0 ignored issues
show
Bug Best Practice introduced by
The property snippets_html does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
206
			$this->text_html = $this->text_display();
0 ignored issues
show
Bug Best Practice introduced by
The property text_html does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
207
			$this->design_html = $this->design_display();
0 ignored issues
show
Bug Best Practice introduced by
The property design_html does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
208
			$this->crawl_html = $this->crawl_display();
0 ignored issues
show
Bug Best Practice introduced by
The property crawl_html does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
209
			$this->speed_html = $this->speed_display();
0 ignored issues
show
Bug Best Practice introduced by
The property speed_html does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
210
211
			$this->box( null, null, $this->score_html );
212
			$this->box( __( 'Snippets', 'cgss' ), $this->dashicon('align-none'), $this->snippets_html );
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

212
			$this->box( /** @scrutinizer ignore-call */ __( 'Snippets', 'cgss' ), $this->dashicon('align-none'), $this->snippets_html );
Loading history...
213
			$this->box( __( 'Text & Links', 'cgss' ), $this->dashicon('text'), $this->text_html );
214
			$this->box( __( 'Design', 'cgss' ), $this->dashicon('smartphone'), $this->design_html );
215
			$this->box( __( 'Crawl', 'cgss' ), $this->dashicon('randomize'), $this->crawl_html );
216
			$this->box( __( 'Speed', 'cgss' ), $this->dashicon('clock'), $this->speed_html );
217
		}
218
219
220
		public function box($title, $icon, $desc) {
221
222
			echo 
223
			'<div class="postbox">
224
				<div class="inside">
225
					<div class="main">' .
226
						'<h4>' . $icon . ' ' . $title . '</h4>' .
227
						$desc .
228
					'</div>
229
				</div>
230
			</div>';
231
		}
232
233
234
		public function dashicon($icon) {
235
236
			return '<span class="dashicons dashicons-'.$icon.'"></span>';
237
		}
238
	}
239
} ?>
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...