Issues (617)

classes/class-lsx-to-vehicles.php (115 issues)

1
<?php
2
/**
3
 * LSX_TO_Vehicles
4
 *
5
 * @package   LSX_TO_Vehicles
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_Vehicles' ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
12
	/**
13
	 * Main plugin class.
14
	 *
15
	 * @package LSX_TO_Vehicles
16
	 * @author  LightSpeed
17
	 */
18
	class LSX_TO_Vehicles {
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-vehicles';
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;
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;
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;
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;
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;
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
0 ignored issues
show
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
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 ) {
0 ignored issues
show
The condition false !== $this->post_types is always true.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
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
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
69
			if ( false !== $this->taxonomies ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
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_VEHICLES_PATH . '/classes/class-lsx-to-vehicles-admin.php' );
0 ignored issues
show
"require_once" is a statement not a function; no parentheses are required
Loading history...
75
			require_once( LSX_TO_VEHICLES_PATH . '/classes/class-lsx-to-vehicles-frontend.php' );
0 ignored issues
show
"require_once" is a statement not a function; no parentheses are required
Loading history...
76
			require_once( LSX_TO_VEHICLES_PATH . '/includes/template-tags.php' );
0 ignored issues
show
"require_once" is a statement not a function; no parentheses are required
Loading history...
77
78
			// flush_rewrite_rules()
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
79
			register_activation_hook( LSX_TO_VEHICLES_CORE, array( $this, 'register_activation_hook' ) );
80
			add_action( 'admin_init', array( $this, 'register_activation_hook_check' ) );
81
		}
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...
82
83
		/**
84
		 * Include the post type for the search integration
85
		 */
86
		public function lsx_to_search_integration() {
87
			add_filter( 'lsx_to_search_post_types', array( $this, 'post_types_filter' ) );
88
			add_filter( 'lsx_to_search_taxonomies', array( $this, 'taxonomies_filter' ) );
89
		}
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...
90
91
		/**
92
		 * Load the plugin text domain for translation.
93
		 */
94
		public function load_plugin_textdomain() {
95
			load_plugin_textdomain( 'to-vehicles', false, basename( LSX_TO_VEHICLES_PATH ) . '/languages' );
96
		}
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...
97
98
		/**
99
		 * Sets the plugins variables
100
		 */
101
		public function set_vars() {
102
			$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...
103
				'vehicle' => __( 'Vehicles', 'to-vehicles' ),
104
			);
105
			$this->post_types_singular = array(
106
				'vehicle' => __( 'Vehicle', 'to-vehicles' ),
107
			);
108
			$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...
109
		}
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...
110
111
		/**
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...
112
		 * Adds our post types to an array via a filter
113
		 */
114
		public function plugin_path( $path, $post_type ) {
115
			if ( false !== $this->post_types && array_key_exists( $post_type, $this->post_types ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
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

115
			if ( false !== $this->post_types && array_key_exists( $post_type, /** @scrutinizer ignore-type */ $this->post_types ) ) {
Loading history...
116
				$path = LSX_TO_VEHICLES_PATH;
117
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
118
			return $path;
119
		}
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...
120
121
		/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$post_types" missing
Loading history...
122
		 * Adds our post types to an array via a filter
123
		 */
124
		public function post_types_slugs_filter( $post_types ) {
125
			if ( is_array( $post_types ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
126
				$post_types = array_merge( $post_types, $this->post_type_slugs );
0 ignored issues
show
$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

126
				$post_types = array_merge( $post_types, /** @scrutinizer ignore-type */ $this->post_type_slugs );
Loading history...
127
			} else {
128
				$post_types = $this->post_type_slugs;
129
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
130
			return $post_types;
131
		}
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...
132
133
		/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$post_types" missing
Loading history...
134
		 * Adds our post types to an array via a filter
135
		 */
136
		public function post_types_filter( $post_types ) {
137
			if ( is_array( $post_types ) && is_array( $this->post_types ) ) {
0 ignored issues
show
The condition is_array($this->post_types) is always false.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
138
				$post_types = array_merge( $post_types, $this->post_types );
139
			} elseif ( is_array( $this->post_types ) ) {
0 ignored issues
show
The condition is_array($this->post_types) is always false.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
140
				$post_types = $this->post_types;
141
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
142
			return $post_types;
143
		}
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...
144
145
		/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$post_types_singular" missing
Loading history...
146
		 * Adds our post types to an array via a filter
147
		 */
148
		public function post_types_singular_filter( $post_types_singular ) {
149
			if ( is_array( $post_types_singular ) && is_array( $this->post_types_singular ) ) {
0 ignored issues
show
The condition is_array($this->post_types_singular) is always false.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
150
				$post_types_singular = array_merge( $post_types_singular, $this->post_types_singular );
151
			} elseif ( is_array( $this->post_types_singular ) ) {
0 ignored issues
show
The condition is_array($this->post_types_singular) is always false.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
152
				$post_types_singular = $this->post_types_singular;
153
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
154
			return $post_types_singular;
155
		}
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...
156
157
		/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$taxonomies" missing
Loading history...
158
		 * Adds our taxonomies to an array via a filter
159
		 */
160
		public function taxonomies_filter( $taxonomies ) {
161
			if ( is_array( $taxonomies ) && is_array( $this->taxonomies ) ) {
0 ignored issues
show
The condition is_array($this->taxonomies) is always false.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
162
				$taxonomies = array_merge( $taxonomies, $this->taxonomies );
163
			} elseif ( is_array( $this->taxonomies ) ) {
0 ignored issues
show
The condition is_array($this->taxonomies) is always false.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
164
				$taxonomies = $this->taxonomies;
165
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
166
			return $taxonomies;
167
		}
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...
168
169
		/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$taxonomies_plural" missing
Loading history...
170
		 * Adds our taxonomies_plural to an array via a filter
171
		 */
172
		public function taxonomies_plural_filter( $taxonomies_plural ) {
173
			if ( is_array( $taxonomies_plural ) && is_array( $this->taxonomies_plural ) ) {
0 ignored issues
show
The condition is_array($this->taxonomies_plural) is always false.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
174
				$taxonomies_plural = array_merge( $taxonomies_plural, $this->taxonomies_plural );
175
			} elseif ( is_array( $this->taxonomies_plural ) ) {
0 ignored issues
show
The condition is_array($this->taxonomies_plural) is always false.
Loading history...
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
176
				$taxonomies_plural = $this->taxonomies_plural;
177
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
178
			return $taxonomies_plural;
179
		}
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...
180
181
		/**
182
		 * Make TO last plugin to load.
183
		 */
184
		public function activated_plugin() {
185
			if ( get_option( 'active_plugins' ) === $plugins ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
186
				$search = preg_grep( '/.*\/tour-operator\.php/', $plugins );
187
				$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...
188
189
				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...
190
					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...
191
						array_splice( $plugins, $key, 1 );
192
						array_push( $plugins, $path );
193
						update_option( 'active_plugins', $plugins );
194
					}
195
				}
196
			}
197
		}
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...
198
199
		/**
200
		 * On plugin activation
201
		 */
202
		public function register_activation_hook() {
203
			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...
204
				set_transient( '_tour_operators_vehicles_flush_rewrite_rules', 1, 30 );
205
			}
206
		}
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...
207
208
		/**
209
		 * On plugin activation (check)
210
		 */
211
		public function register_activation_hook_check() {
212
			if ( ! get_transient( '_tour_operators_vehicles_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...
213
				return;
214
			}
215
216
			delete_transient( '_tour_operators_vehicles_flush_rewrite_rules' );
217
			flush_rewrite_rules();
218
		}
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...
219
220
		/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$post_types" missing
Loading history...
221
		 * Enabled banners for the additional post types
222
		 *
223
		 * @package    theme
224
		 * @subpackage setup
225
		 * @category   banners
226
		 *
227
		 * @param   $post_types array()
0 ignored issues
show
Missing parameter name
Loading history...
228
		 * @return  $post_types array()
0 ignored issues
show
Documentation Bug introduced by
The doc comment $post_types at position 0 could not be parsed: Unknown type name '$post_types' at position 0 in $post_types.
Loading history...
229
		 */
230
		function theme_allowed_post_type_banners( $post_types ) {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for theme_allowed_post_type_banners.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
231
			$post_types[] = 'summary';
232
			$post_types[] = 'gallery';
233
			$post_types[] = 'video';
234
			return $post_types;
235
		}
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...
236
237
	}
238
	new LSX_TO_Vehicles();
239
}
240