Issues (1057)

classes/class-to-reviews.php (132 issues)

1
<?php
0 ignored issues
show
Class file names should be based on the class name with "class-" prepended. Expected class-lsx-to-reviews.php, but found class-to-reviews.php.
Loading history...
2
/**
3
 * LSX_TO_Reviews
4
 *
5
 * @package   LSX_TO_Reviews
6
 * @author    LightSpeed
7
 * @license   GPL-3.0+
8
 * @link      
9
 * @copyright 2016 LightSpeedDevelopment
10
 */
0 ignored issues
show
There must be exactly one blank line after the file comment
Loading history...
11
if (!class_exists( 'LSX_TO_Reviews' ) ) {
0 ignored issues
show
No space after opening parenthesis is prohibited
Loading history...
Expected 1 space before "!"; 0 found
Loading history...
Expected 1 space after "!"; 0 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
12
	/**
13
	 * Main plugin class.
14
	 *
15
	 * @package LSX_TO_Reviews
16
	 * @author  LightSpeed
17
	 */
18
	class LSX_TO_Reviews {
19
		
20
		/**
21
		 * The plugins id
22
		 */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @var tag in member variable comment
Loading history...
23
		public $plugin_slug = 'to-reviews';
24
25
		/**
26
		 * The post types the plugin registers
27
		 */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @var tag in member variable comment
Loading history...
28
		public $post_types = false;	
0 ignored issues
show
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
29
30
		/**
31
		 * The singular post types the plugin registers
32
		 */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @var tag in member variable comment
Loading history...
33
		public $post_types_singular = false;	
0 ignored issues
show
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
34
35
		/**
36
		 * An array of the post types slugs plugin registers
37
		 */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @var tag in member variable comment
Loading history...
38
		public $post_type_slugs = false;			
0 ignored issues
show
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
39
40
		/**
41
		 * The taxonomies the plugin registers
42
		 */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @var tag in member variable comment
Loading history...
43
		public $taxonomies = false;			
0 ignored issues
show
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
44
45
		/**
46
		 * The taxonomies the plugin registers (plural)
47
		 */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @var tag in member variable comment
Loading history...
48
		public $taxonomies_plural = false;			
0 ignored issues
show
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
49
50
		/**
51
		 * Constructor
52
		 */
53
		public function __construct() {
0 ignored issues
show
Expected 2 blank lines before function; 1 found
Loading history...
54
			//Set the variables
0 ignored issues
show
No space found before comment text; expected "// Set the variables" but found "//Set the variables"
Loading history...
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
55
			$this->set_vars();
56
			$this->lsx_to_search_integration();
57
58
			// Make TO last plugin to load.
59
			add_action( 'activated_plugin', array( $this, 'activated_plugin' ) );
60
61
			add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
62
63
			if ( false !== $this->post_types ) {
64
				add_filter( 'lsx_to_framework_post_types', array( $this, 'post_types_filter' ) );
65
				add_filter( 'lsx_to_post_types', array( $this, 'post_types_filter' ) );
66
				add_filter( 'lsx_to_post_types_singular', array( $this, 'post_types_singular_filter' ) );
67
				add_filter( 'lsx_to_settings_path', array( $this, 'plugin_path' ), 10, 2 );
68
			}
69
			if ( false !== $this->taxonomies ) {
70
				add_filter( 'lsx_to_framework_taxonomies', array( $this, 'taxonomies_filter' ) );
71
				add_filter( 'lsx_to_framework_taxonomies_plural', array( $this, 'taxonomies_plural_filter' ) );
72
			}
73
74
			require_once LSX_TO_REVIEWS_PATH . '/classes/class-to-reviews-admin.php';
75
			require_once LSX_TO_REVIEWS_PATH . '/classes/class-to-reviews-frontend.php';
76
			require_once LSX_TO_REVIEWS_PATH . '/includes/template-tags.php';
77
78
			// flush_rewrite_rules.
79
			register_activation_hook( LSX_TO_REVIEWS_CORE, array( $this, 'register_activation_hook' ) );
80
			add_action( 'admin_init', array( $this, 'register_activation_hook_check' ) );
81
82
			add_filter( 'wpseo_schema_graph_pieces', array( $this, 'add_graph_pieces' ), 11, 2 );
83
		}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
84
85
		/**
86
		 * Include the post type for the search integration
87
		 */
88
		public function lsx_to_search_integration(){
0 ignored issues
show
Expected 1 space before opening brace; found 0
Loading history...
89
			add_filter( 'lsx_to_search_post_types', array( $this, 'post_types_filter' ) );
90
			add_filter( 'lsx_to_search_taxonomies', array( $this, 'taxonomies_filter' ) );
91
		}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
92
	
93
		/**
94
		 * Load the plugin text domain for translation.
95
		 */
96
		public function load_plugin_textdomain() {
97
			load_plugin_textdomain( 'to-reviews', FALSE, basename( LSX_TO_REVIEWS_PATH ) . '/languages');
0 ignored issues
show
The parameter "FALSE" at position #2 of load_plugin_textdomain() has been deprecated since WordPress version 2.7.0. Use "" instead.
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
TRUE, FALSE and NULL must be lowercase; expected false, but found FALSE.
Loading history...
98
		}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
99
100
		/**
101
		 * Sets the plugins variables
102
		 */
103
		public function set_vars() {
104
			$this->post_types = array(
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 10 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
105
				'review'	=>	__('Reviews','to-reviews')
0 ignored issues
show
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
Array double arrow not aligned correctly; expected 1 space(s) between "'review'" and double arrow, but found 4.
Loading history...
Expected 1 space after "=>"; 2 found
Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
Each array item in a multi-line array declaration must end in a comma
Loading history...
106
			);
107
			$this->post_types_singular = array(
108
				'review'	=>	__('Review','to-reviews')
0 ignored issues
show
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
Array double arrow not aligned correctly; expected 1 space(s) between "'review'" and double arrow, but found 4.
Loading history...
Expected 1 space after "=>"; 2 found
Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
Each array item in a multi-line array declaration must end in a comma
Loading history...
109
			);
110
			$this->post_type_slugs = array_keys($this->post_types);			
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
111
		}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
112
113
		/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$path" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$post_type" missing
Loading history...
114
		 * Adds our post types to an array via a filter
115
		 */
116
		public function plugin_path($path,$post_type){
0 ignored issues
show
No space after opening parenthesis is prohibited
Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 space between comma and argument "$post_type"; 0 found
Loading history...
No space before closing parenthesis is prohibited
Loading history...
Expected 1 space before opening brace; found 0
Loading history...
Space between opening control structure and closing parenthesis is required
Loading history...
117
			if(false !== $this->post_types && array_key_exists($post_type,$this->post_types)){
0 ignored issues
show
Space after opening control structure is required
Loading history...
No space before opening parenthesis is prohibited
Loading history...
No space after opening parenthesis is prohibited
Loading history...
Expected 1 space(s) after IF keyword; 0 found
Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
No space before closing parenthesis is prohibited
Loading history...
Space between opening control structure and closing parenthesis is required
Loading history...
$this->post_types of type true is incompatible with the type ArrayObject|array expected by parameter $array of array_key_exists(). ( Ignorable by Annotation )

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

117
			if(false !== $this->post_types && array_key_exists($post_type,/** @scrutinizer ignore-type */ $this->post_types)){
Loading history...
118
				$path = LSX_TO_REVIEWS_PATH;
119
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
120
			return $path;
121
		}	
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
122
123
		/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$post_types" missing
Loading history...
124
		 * Adds our post types to an array via a filter
125
		 */
126
		public function post_types_slugs_filter($post_types){
0 ignored issues
show
No space after opening parenthesis is prohibited
Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
No space before closing parenthesis is prohibited
Loading history...
Expected 1 space before opening brace; found 0
Loading history...
Space between opening control structure and closing parenthesis is required
Loading history...
127
			if(is_array($post_types)){
0 ignored issues
show
Space after opening control structure is required
Loading history...
No space before opening parenthesis is prohibited
Loading history...
No space after opening parenthesis is prohibited
Loading history...
Expected 1 space(s) after IF keyword; 0 found
Loading history...
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
No space before closing parenthesis is prohibited
Loading history...
Space between opening control structure and closing parenthesis is required
Loading history...
128
				$post_types = array_merge($post_types,$this->post_type_slugs);
0 ignored issues
show
Expected 1 spaces after opening parenthesis; 0 found
Loading history...
Expected 1 spaces before closing parenthesis; 0 found
Loading history...
$this->post_type_slugs of type boolean is incompatible with the type array expected by parameter $arrays of array_merge(). ( Ignorable by Annotation )

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

128
				$post_types = array_merge($post_types,/** @scrutinizer ignore-type */ $this->post_type_slugs);
Loading history...
129
			}else{
0 ignored issues
show
Space after opening control structure is required
Loading history...
No space before opening parenthesis is prohibited
Loading history...
Expected 1 space(s) after ELSE keyword; 0 found
Loading history...
130
				$post_types = $this->post_type_slugs;
131
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
132
			return $post_types;
133
		}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
134
135
		/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$post_types" missing
Loading history...
136
		 * Adds our post types to an array via a filter
137
		 */
138
		public function post_types_filter( $post_types ) {
139
			if ( is_array( $post_types ) && is_array( $this->post_types ) ) {
140
				$post_types = array_merge( $post_types, $this->post_types );
141
			} elseif ( is_array( $this->post_types ) ) {
142
				$post_types = $this->post_types;
143
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
144
			return $post_types;
145
		}	
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
146
147
		/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$post_types_singular" missing
Loading history...
148
		 * Adds our post types to an array via a filter
149
		 */
150
		public function post_types_singular_filter( $post_types_singular ) {
151
			if ( is_array( $post_types_singular ) && is_array( $this->post_types_singular ) ) {
152
				$post_types_singular = array_merge( $post_types_singular, $this->post_types_singular );
153
			} elseif ( is_array( $this->post_types_singular ) ) {
154
				$post_types_singular = $this->post_types_singular;
155
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
156
			return $post_types_singular;
157
		}	
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
Spaces must be used for mid-line alignment; tabs are not allowed
Loading history...
158
159
		/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$taxonomies" missing
Loading history...
160
		 * Adds our taxonomies to an array via a filter
161
		 */
162
		public function taxonomies_filter( $taxonomies ) {
163
			if ( is_array( $taxonomies ) && is_array( $this->taxonomies ) ) {
164
				$taxonomies = array_merge( $taxonomies, $this->taxonomies );
165
			} elseif ( is_array( $this->taxonomies ) ) {
166
				$taxonomies = $this->taxonomies;
167
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
168
			return $taxonomies;
169
		}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
170
171
		/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$taxonomies_plural" missing
Loading history...
172
		 * Adds our taxonomies_plural to an array via a filter
173
		 */
174
		public function taxonomies_plural_filter( $taxonomies_plural ) {
175
			if ( is_array( $taxonomies_plural ) && is_array( $this->taxonomies_plural ) ) {
176
				$taxonomies_plural = array_merge( $taxonomies_plural, $this->taxonomies_plural );
177
			} elseif ( is_array( $this->taxonomies_plural ) ) {
178
				$taxonomies_plural = $this->taxonomies_plural;
179
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
180
			return $taxonomies_plural;
181
		}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
182
183
		/**
184
		 * Make TO last plugin to load.
185
		 */
186
		public function activated_plugin() {
187
			if ( $plugins = get_option( 'active_plugins' ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Variable assignment found within a condition. Did you mean to do a comparison?
Loading history...
Assignments must be the first block of code on a line
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
188
				$search = preg_grep( '/.*\/tour-operator\.php/', $plugins );
189
				$key = array_search( $search, $plugins );
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
Not using strict comparison for array_search; supply true for third argument.
Loading history...
190
191
				if ( is_array( $search ) && count( $search ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
192
					foreach ( $search as $key => $path ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
193
						array_splice( $plugins, $key, 1 );
194
						array_push( $plugins, $path );
195
						update_option( 'active_plugins', $plugins );
196
					}
197
				}
198
			}
199
		}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
200
201
		/**
202
		 * On plugin activation
203
		 */
204
		public function register_activation_hook() {
205
			if ( ! is_network_admin() && ! isset( $_GET['activate-multi'] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Processing form data without nonce verification.
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
206
				set_transient( '_tour_operators_reviews_flush_rewrite_rules', 1, 30 );
207
			}
208
		}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
209
210
		/**
211
		 * On plugin activation (check)
212
		 */
213
		public function register_activation_hook_check() {
214
			if ( ! get_transient( '_tour_operators_reviews_flush_rewrite_rules' ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
215
				return;
216
			}
217
218
			delete_transient( '_tour_operators_reviews_flush_rewrite_rules' );
219
			flush_rewrite_rules();
220
		}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 0 found
Loading history...
221
		/**
222
		 * Adds Schema pieces to our output.
223
		 *
224
		 * @param array                 $pieces  Graph pieces to output.
225
		 * @param \WPSEO_Schema_Context $context Object with context variables.
226
		 *
227
		 * @return array $pieces Graph pieces to output.
228
		 */
229
		public function add_graph_pieces( $pieces, $context ) {
230
			if ( class_exists( 'LSX_TO_Schema_Graph_Piece' ) ) {
231
				require_once LSX_TO_REVIEWS_PATH . '/classes/class-to-review-schema.php';
232
				$pieces[] = new LSX_TO_Schema_Review( $context );
233
			}
234
			return $pieces;
235
		}
236
	}
237
	new LSX_TO_Reviews();
238
}
239