Completed
Branch BETA-4.9-messages-queue-fixed (941081)
by
unknown
17:38 queued 10s
created

EE_Recommended_Versions   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 212
Duplicated Lines 17.45 %

Coupling/Cohesion

Components 1
Dependencies 4
Metric Value
wmc 17
lcom 1
cbo 4
dl 37
loc 212
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A _check_wp_version() 0 4 2
A _minimum_wp_version_required() 0 3 1
A _minimum_wp_version_recommended() 0 3 1
A _check_php_version() 0 3 2
A _minimum_php_version_required() 0 3 1
A _minimum_php_version_recommended() 0 3 1
B handle_request() 12 31 5
A minimum_wp_version_error() 0 18 1
A minimum_php_version_error() 0 17 1
A _display_minimum_recommended_wp_version_notice() 13 13 1
A _display_minimum_recommended_php_version_notice() 12 12 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); }
2
/**
3
 * Class EE_Recommended_Versions
4
 *
5
 * checks required and recommended versions for both WP and PHP
6
 * terminates the request if minimum required versions are not met
7
 *
8
 * @package 	Event Espresso
9
 * @subpackage 	core
10
 * @author 		Brent Christensen
11
 * @since 		4.8.20
12
 *
13
 */
14
15
class EE_Recommended_Versions extends EE_Middleware {
16
17
18
	/**
19
	 * converts a Request to a Response
20
	 *
21
	 * @param 	EE_Request 	$request
22
	 * @param 	EE_Response $response
23
	 * @return 	EE_Response
24
	 */
25
	public function handle_request( EE_Request $request, EE_Response $response ) {
26
		$this->_request = $request;
27
		$this->_response = $response;
28
		//$this->_response->add_output( "\n\t IN >>  " . __CLASS__ );
29
		//$this->_response->set_notice( 1, 'hey look at this' );
30
		// check required WP version
31 View Code Duplication
		if ( ! $this->_minimum_wp_version_required() ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32
			$this->_request->un_set( 'activate', true );
33
			add_action( 'admin_notices', array( $this, 'minimum_wp_version_error' ), 1 );
34
			//$this->_response->add_output( "\n<br />" . 'minimum_wp_version_error' );
35
			$this->_response->terminate_request();
36
		}
37
		// check required PHP version
38 View Code Duplication
		if ( ! $this->_minimum_php_version_required() ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
			$this->_request->un_set( 'activate', true );
40
			add_action( 'admin_notices', array( $this, 'minimum_php_version_error' ), 1 );
41
			//$this->_response->add_output( "\n<br />" . 'minimum_php_version_error' );
42
			$this->_response->terminate_request();
43
		}
44
		// check recommended WP version
45
		if ( ! $this->_minimum_wp_version_recommended() ) {
46
			$this->_display_minimum_recommended_wp_version_notice();
47
		}
48
		// check recommended PHP version
49
		if ( ! $this->_minimum_php_version_recommended() ) {
50
			$this->_display_minimum_recommended_php_version_notice();
51
		}
52
		$this->_response = $this->process_request_stack( $this->_request, $this->_response );
53
		//$this->_response->add_output( "\n\t OUT << " . __CLASS__ );
54
		return $this->_response;
55
	}
56
57
58
59
	/**
60
	 *    _check_wp_version
61
	 *
62
	 * @access private
63
	 * @param string $min_version
64
	 * @return boolean
65
	 */
66
	private function _check_wp_version( $min_version = EE_MIN_WP_VER_REQUIRED ) {
67
		global $wp_version;
68
		return version_compare( $wp_version, $min_version, '>=' ) ? true : false;
69
	}
70
71
72
73
	/**
74
	 *    _minimum_wp_version_required
75
	 *
76
	 * @access private
77
	 * @return boolean
78
	 */
79
	private function _minimum_wp_version_required() {
80
		return $this->_check_wp_version( EE_MIN_WP_VER_REQUIRED );
81
	}
82
83
84
85
	/**
86
	 *    _minimum_wp_version_recommended
87
	 *
88
	 * @access private
89
	 * @return boolean
90
	 */
91
	private function _minimum_wp_version_recommended() {
92
		return $this->_check_wp_version( EE_MIN_WP_VER_RECOMMENDED );
93
	}
94
95
96
97
	/**
98
	 *    _check_php_version
99
	 *
100
	 * @access private
101
	 * @param string $min_version
102
	 * @return boolean
103
	 */
104
	private function _check_php_version( $min_version = EE_MIN_PHP_VER_RECOMMENDED ) {
105
		return version_compare( PHP_VERSION, $min_version, '>=' ) ? true : false;
106
	}
107
108
109
110
	/**
111
	 *    _minimum_php_version_required
112
	 *
113
	 * @access private
114
	 * @return boolean
115
	 */
116
	private function _minimum_php_version_required() {
117
		return $this->_check_php_version( EE_MIN_PHP_VER_REQUIRED );
118
	}
119
120
121
122
	/**
123
	 *    _minimum_php_version_recommended
124
	 *
125
	 * @access private
126
	 * @return boolean
127
	 */
128
	private function _minimum_php_version_recommended() {
129
		return $this->_check_php_version( EE_MIN_PHP_VER_RECOMMENDED );
130
	}
131
132
133
134
	/**
135
	 *    minimum_wp_version_error
136
	 *
137
	 * @return void
138
	 */
139
	public function minimum_wp_version_error() {
140
		global $wp_version;
141
		?>
142
		<div class="error">
143
			<p>
144
				<?php
145
				printf(
146
					__( 'We\'re sorry, but Event Espresso requires WordPress version %1$s or greater in order to operate. You are currently running version %2$s.%3$sFor information on how to update your version of WordPress, please go to %4$s.', 'event_espresso' ),
147
					EE_MIN_WP_VER_REQUIRED,
148
					$wp_version,
149
					'<br/>',
150
					'<a href="http://codex.wordpress.org/Updating_WordPress">http://codex.wordpress.org/Updating_WordPress</a>'
151
				);
152
				?>
153
			</p>
154
		</div>
155
		<?php
156
	}
157
158
159
160
	/**
161
	 *    minimum_php_version_error
162
	 *
163
	 * @return void
164
	 */
165
	public function minimum_php_version_error() {
166
		?>
167
		<div class="error">
168
			<p>
169
				<?php
170
				printf(
171
					__( 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', 'event_espresso' ),
172
					EE_MIN_PHP_VER_REQUIRED,
173
					PHP_VERSION,
174
					'<br/>',
175
					'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
176
				);
177
				?>
178
			</p>
179
		</div>
180
		<?php
181
	}
182
183
184
185
	/**
186
	 *    _display_minimum_recommended_wp_version_notice
187
	 *
188
	 * @access private
189
	 * @return void
190
	 */
191 View Code Duplication
	private function _display_minimum_recommended_wp_version_notice() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
192
		global $wp_version;
193
		EE_Error::add_persistent_admin_notice(
194
			'wp_version_' . str_replace( '.', '-', EE_MIN_WP_VER_RECOMMENDED ) . '_recommended',
195
			sprintf(
196
				__( 'Event Espresso recommends WordPress version %1$s or greater in order for everything to operate properly. You are currently running version %2$s.%3$sFor information on how to update your version of WordPress, please go to %4$s.', 'event_espresso' ),
197
				EE_MIN_WP_VER_RECOMMENDED,
198
				$wp_version,
199
				'<br/>',
200
				'<a href="http://codex.wordpress.org/Updating_WordPress">http://codex.wordpress.org/Updating_WordPress</a>'
201
			)
202
		);
203
	}
204
205
206
207
	/**
208
	 *    _display_minimum_recommended_php_version_notice
209
	 *
210
	 * @access private
211
	 * @return void
212
	 */
213 View Code Duplication
	private function _display_minimum_recommended_php_version_notice() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
214
		EE_Error::add_persistent_admin_notice(
215
			'php_version_' . str_replace( '.', '-', EE_MIN_PHP_VER_RECOMMENDED ) . '_recommended',
216
			sprintf(
217
				__( 'Event Espresso recommends PHP version %1$s or greater for optimal performance. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', 'event_espresso' ),
218
				EE_MIN_PHP_VER_RECOMMENDED,
219
				PHP_VERSION,
220
				'<br/>',
221
				'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
222
			)
223
		);
224
	}
225
226
}
227
228
229
230
// End of file EE_Recommended_Versions.core.php
231
// Location: /EE_Recommended_Versions.core.php