Completed
Push — develop ( 30f360...679d73 )
by David
10:48 queued 07:50
created
src/includes/batch-analysis/class-wordlift-batch-analysis-sql-helper.php 2 patches
Indentation   +203 added lines, -203 removed lines patch added patch discarded remove patch
@@ -11,24 +11,24 @@  discard block
 block discarded – undo
11 11
 
12 12
 class Wordlift_Batch_Analysis_Sql_Helper {
13 13
 
14
-	/**
15
-	 * Get the base SQL statement to submit a post for Batch Analysis.
16
-	 *
17
-	 * Functions may use this base SQL and add their own filters. This function
18
-	 * should be `private` and only used by the {@link Wordlift_Batch_Analysis_Service}
19
-	 * `submit` function. But since we want to maintain compatibility with PHP 5.3
20
-	 * and we couldn't use traits to hide the function from the Wordlift_Batch_Analysis_Service
21
-	 * we used a Helper function.
22
-	 *
23
-	 * @since 3.14.2
24
-	 *
25
-	 * @param array $args An array of parameters, see {@link submit}.
26
-	 *
27
-	 * @return string The base SQL.
28
-	 */
29
-	public static function get_sql( $args ) {
30
-
31
-		/*
14
+    /**
15
+     * Get the base SQL statement to submit a post for Batch Analysis.
16
+     *
17
+     * Functions may use this base SQL and add their own filters. This function
18
+     * should be `private` and only used by the {@link Wordlift_Batch_Analysis_Service}
19
+     * `submit` function. But since we want to maintain compatibility with PHP 5.3
20
+     * and we couldn't use traits to hide the function from the Wordlift_Batch_Analysis_Service
21
+     * we used a Helper function.
22
+     *
23
+     * @since 3.14.2
24
+     *
25
+     * @param array $args An array of parameters, see {@link submit}.
26
+     *
27
+     * @return string The base SQL.
28
+     */
29
+    public static function get_sql( $args ) {
30
+
31
+        /*
32 32
 		Prepare the statement:
33 33
 			1. Insert into `postmeta` the meta keys and values:
34 34
 				a) state meta, with value of SUBMIT (0),
@@ -44,20 +44,20 @@  discard block
 block discarded – undo
44 44
 			9. Filter by `post_id` where `exclude` is the posts id to exclude.
45 45
 		*/
46 46
 
47
-		// @codingStandardsIgnoreStart, Ignore phpcs sanitation errors.
48
-		return self::get_base_query( $args )
49
-			   . " WHERE p.post_type IN ('" . join( "', '", array_map( 'esc_sql', (array) $args['post_type'] ) ) . "')"
50
-			   . "  AND p.post_status = 'publish'"
51
-			   . Wordlift_Batch_Analysis_Sql_Helper::and_include_annotated( $args['include_annotated'] )
52
-			   . Wordlift_Batch_Analysis_Sql_Helper::and_post_date_from( $args['from'] )
53
-			   . Wordlift_Batch_Analysis_Sql_Helper::and_post_date_to( $args['to'] )
54
-			   . Wordlift_Batch_Analysis_Sql_Helper::and_exclude_posts( $args['exclude'] );
55
-		// @codingStandardsIgnoreEnd
56
-	}
47
+        // @codingStandardsIgnoreStart, Ignore phpcs sanitation errors.
48
+        return self::get_base_query( $args )
49
+                . " WHERE p.post_type IN ('" . join( "', '", array_map( 'esc_sql', (array) $args['post_type'] ) ) . "')"
50
+                . "  AND p.post_status = 'publish'"
51
+                . Wordlift_Batch_Analysis_Sql_Helper::and_include_annotated( $args['include_annotated'] )
52
+                . Wordlift_Batch_Analysis_Sql_Helper::and_post_date_from( $args['from'] )
53
+                . Wordlift_Batch_Analysis_Sql_Helper::and_post_date_to( $args['to'] )
54
+                . Wordlift_Batch_Analysis_Sql_Helper::and_exclude_posts( $args['exclude'] );
55
+        // @codingStandardsIgnoreEnd
56
+    }
57 57
 
58
-	public static function get_sql_for_ids( $args ) {
58
+    public static function get_sql_for_ids( $args ) {
59 59
 
60
-		/*
60
+        /*
61 61
 		Prepare the statement:
62 62
 			1. Insert into `postmeta` the meta keys and values:
63 63
 				a) state meta, with value of SUBMIT (0),
@@ -73,178 +73,178 @@  discard block
 block discarded – undo
73 73
 			9. Filter by `post_id` where `exclude` is the posts id to exclude.
74 74
 		*/
75 75
 
76
-		// @codingStandardsIgnoreStart, Ignore phpcs sanitation errors.
77
-
78
-		return self::get_base_query( $args )
79
-			   . ' WHERE p.id IN (' . implode( ', ', wp_parse_id_list( $args['ids'] ) ) . ')';
80
-		// @codingStandardsIgnoreEnd
81
-	}
82
-
83
-	private static function get_base_query( $args ) {
84
-		global $wpdb;
85
-
86
-		// Get the link options.
87
-		$link_options = serialize( array(
88
-			'links'           => $args['links'],
89
-			'min_occurrences' => $args['min_occurrences'],
90
-		) );
91
-
92
-		return $wpdb->prepare(
93
-			"INSERT INTO $wpdb->postmeta ( post_id, meta_key, meta_value )"
94
-			// Populate 3 metas for the batch analysis request using a SQL
95
-			// statement: each meta contains a state for the batch analysis
96
-			// request.
97
-			. ' SELECT p.ID, metas.* FROM ('
98
-			. '  SELECT %s, 0 FROM dual'                // STATE_META_KEY.
99
-			. '   UNION'
100
-			. '	 SELECT %s, UTC_TIMESTAMP() FROM dual'  // SUBMIT_TIMESTAMP_META_KEY.
101
-			. '	  UNION'
102
-			. '	 SELECT %s, %s FROM dual'               // LINK_META_KEY.
103
-			. '	) metas'
104
-			. ", $wpdb->posts p",
105
-			Wordlift_Batch_Analysis_Service::STATE_META_KEY,
106
-			Wordlift_Batch_Analysis_Service::SUBMIT_TIMESTAMP_META_KEY,
107
-			Wordlift_Batch_Analysis_Service::BATCH_ANALYSIS_OPTIONS_META_KEY,
108
-			$link_options
109
-		);
110
-	}
111
-
112
-	/**
113
-	 * Add a clause to analyze all auto selected posts, i.e. non annotated posts.
114
-	 *
115
-	 * @param bool $include Whether to include annotated posts in selection.
116
-	 *
117
-	 * @since  3.17.0
118
-	 *
119
-	 * @return string The `post_content` clause.
120
-	 */
121
-	private static function and_include_annotated( $include ) {
122
-
123
-		// Bail out with an empty string if we include all the posts.
124
-		if ( true === $include ) {
125
-			return '';
126
-		}
127
-
128
-		// Filter out already annotated posts.
129
-		return " AND p.post_content NOT REGEXP '<[a-z]+ id=\"urn:[^\"]+\" class=\"[^\"]+\" itemid=\"[^\"]+\">'";
130
-	}
131
-
132
-	/**
133
-	 * Add the start date clause.
134
-	 *
135
-	 * @param  DateTime|null $value The date where the analysis should start.
136
-	 *
137
-	 * @since  3.17.0
138
-	 *
139
-	 * @return string The start `post_date_gmt` clause
140
-	 */
141
-	private static function and_post_date_from( $value ) {
142
-
143
-		// Bail out if the `from` isn't specified.
144
-		if ( null === $value ) {
145
-			return '';
146
-		}
147
-
148
-		// Try to convert the value to a date, GMT timezone.
149
-		$date = self::get_mysql_date_string( $value );
150
-
151
-		// Return the clause.
152
-		return " AND p.post_date_gmt >= '$date'";
153
-	}
154
-
155
-	/**
156
-	 * Add the `to` date clause.
157
-	 *
158
-	 * @param  DateTime|null $value The `to` date clause.
159
-	 *
160
-	 * @since  3.17.0
161
-	 *
162
-	 * @return string The end `post_date_gmt` clause
163
-	 */
164
-	private static function and_post_date_to( $value ) {
165
-
166
-		// Bail out if the `from` isn't specified.
167
-		if ( null === $value ) {
168
-			return '';
169
-		}
170
-
171
-		// Try to convert the value to a date, GMT timezone.
172
-		$date = self::get_mysql_date_string( $value );
173
-
174
-		// Return the clause.
175
-		return " AND p.post_date_gmt <= '$date'";
176
-	}
177
-
178
-	/**
179
-	 * Include specific posts by their id in the analysis.
180
-	 *
181
-	 * @param array $include Array of post ids to include.
182
-	 *
183
-	 * @since  3.17.0
184
-	 *
185
-	 * @return string The posts IN clause.
186
-	 */
187
-	private static function and_include_posts( $include ) {
188
-
189
-		// Bail if the param is not set.
190
-		if ( empty( $include ) ) {
191
-			return '';
192
-		}
193
-
194
-		return ' AND p.ID IN ( ' . implode( ',', wp_parse_id_list( $include ) ) . ' )';
195
-	}
196
-
197
-	/**
198
-	 * Exclude specific posts by ids.
199
-	 *
200
-	 * @param array $exclude Array of post ids to exclude.
201
-	 *
202
-	 * @since  3.17.0
203
-	 *
204
-	 * @return string The posts NOT IN clause.
205
-	 */
206
-	private static function and_exclude_posts( $exclude ) {
207
-
208
-		// Bail if the param is not set.
209
-		if ( empty( $exclude ) ) {
210
-			return '';
211
-		}
212
-
213
-		return ' AND p.ID NOT IN ( ' . implode( ',', wp_parse_id_list( $exclude ) ) . ' )';
214
-	}
215
-
216
-
217
-	/**
218
-	 * Convert a `Y-m-d'T'H:i:sT` string representation of a date to a MySQL
219
-	 * date string, taking into consideration the time zone.
220
-	 *
221
-	 * If the date string cannot be converted, the processing is stopped.
222
-	 *
223
-	 * @since 3.17.0
224
-	 *
225
-	 * @param string $value A date represented as `Y-m-d'T'H:i:sT`.
226
-	 *
227
-	 * @return string A MySQL string representation of the date.
228
-	 */
229
-	private static function get_mysql_date_string( $value ) {
230
-
231
-		// Try to convert the value to a date, GMT timezone.
232
-		$date = date_create_from_format( 'Y-m-d\TH:i:sT', $value );
233
-
234
-		if ( false === $date ) {
235
-			wp_die( "Invalid date format, use `Y-m-d'T'H:i:sT`." );
236
-		}
237
-
238
-		// Convert the DateTime timezone to `GMT`.
239
-		$date->setTimezone( timezone_open( 'GMT' ) );
240
-
241
-		// Stop if the conversion failed.
242
-		if ( false === $date ) {
243
-			wp_die( "Invalid date format, date must be in Y-m-d'T'H:i:sT format." );
244
-		}
245
-
246
-		// Return the clause.
247
-		return $date->format( 'Y-m-d H:i:s' );
248
-	}
76
+        // @codingStandardsIgnoreStart, Ignore phpcs sanitation errors.
77
+
78
+        return self::get_base_query( $args )
79
+                . ' WHERE p.id IN (' . implode( ', ', wp_parse_id_list( $args['ids'] ) ) . ')';
80
+        // @codingStandardsIgnoreEnd
81
+    }
82
+
83
+    private static function get_base_query( $args ) {
84
+        global $wpdb;
85
+
86
+        // Get the link options.
87
+        $link_options = serialize( array(
88
+            'links'           => $args['links'],
89
+            'min_occurrences' => $args['min_occurrences'],
90
+        ) );
91
+
92
+        return $wpdb->prepare(
93
+            "INSERT INTO $wpdb->postmeta ( post_id, meta_key, meta_value )"
94
+            // Populate 3 metas for the batch analysis request using a SQL
95
+            // statement: each meta contains a state for the batch analysis
96
+            // request.
97
+            . ' SELECT p.ID, metas.* FROM ('
98
+            . '  SELECT %s, 0 FROM dual'                // STATE_META_KEY.
99
+            . '   UNION'
100
+            . '	 SELECT %s, UTC_TIMESTAMP() FROM dual'  // SUBMIT_TIMESTAMP_META_KEY.
101
+            . '	  UNION'
102
+            . '	 SELECT %s, %s FROM dual'               // LINK_META_KEY.
103
+            . '	) metas'
104
+            . ", $wpdb->posts p",
105
+            Wordlift_Batch_Analysis_Service::STATE_META_KEY,
106
+            Wordlift_Batch_Analysis_Service::SUBMIT_TIMESTAMP_META_KEY,
107
+            Wordlift_Batch_Analysis_Service::BATCH_ANALYSIS_OPTIONS_META_KEY,
108
+            $link_options
109
+        );
110
+    }
111
+
112
+    /**
113
+     * Add a clause to analyze all auto selected posts, i.e. non annotated posts.
114
+     *
115
+     * @param bool $include Whether to include annotated posts in selection.
116
+     *
117
+     * @since  3.17.0
118
+     *
119
+     * @return string The `post_content` clause.
120
+     */
121
+    private static function and_include_annotated( $include ) {
122
+
123
+        // Bail out with an empty string if we include all the posts.
124
+        if ( true === $include ) {
125
+            return '';
126
+        }
127
+
128
+        // Filter out already annotated posts.
129
+        return " AND p.post_content NOT REGEXP '<[a-z]+ id=\"urn:[^\"]+\" class=\"[^\"]+\" itemid=\"[^\"]+\">'";
130
+    }
131
+
132
+    /**
133
+     * Add the start date clause.
134
+     *
135
+     * @param  DateTime|null $value The date where the analysis should start.
136
+     *
137
+     * @since  3.17.0
138
+     *
139
+     * @return string The start `post_date_gmt` clause
140
+     */
141
+    private static function and_post_date_from( $value ) {
142
+
143
+        // Bail out if the `from` isn't specified.
144
+        if ( null === $value ) {
145
+            return '';
146
+        }
147
+
148
+        // Try to convert the value to a date, GMT timezone.
149
+        $date = self::get_mysql_date_string( $value );
150
+
151
+        // Return the clause.
152
+        return " AND p.post_date_gmt >= '$date'";
153
+    }
154
+
155
+    /**
156
+     * Add the `to` date clause.
157
+     *
158
+     * @param  DateTime|null $value The `to` date clause.
159
+     *
160
+     * @since  3.17.0
161
+     *
162
+     * @return string The end `post_date_gmt` clause
163
+     */
164
+    private static function and_post_date_to( $value ) {
165
+
166
+        // Bail out if the `from` isn't specified.
167
+        if ( null === $value ) {
168
+            return '';
169
+        }
170
+
171
+        // Try to convert the value to a date, GMT timezone.
172
+        $date = self::get_mysql_date_string( $value );
173
+
174
+        // Return the clause.
175
+        return " AND p.post_date_gmt <= '$date'";
176
+    }
177
+
178
+    /**
179
+     * Include specific posts by their id in the analysis.
180
+     *
181
+     * @param array $include Array of post ids to include.
182
+     *
183
+     * @since  3.17.0
184
+     *
185
+     * @return string The posts IN clause.
186
+     */
187
+    private static function and_include_posts( $include ) {
188
+
189
+        // Bail if the param is not set.
190
+        if ( empty( $include ) ) {
191
+            return '';
192
+        }
193
+
194
+        return ' AND p.ID IN ( ' . implode( ',', wp_parse_id_list( $include ) ) . ' )';
195
+    }
196
+
197
+    /**
198
+     * Exclude specific posts by ids.
199
+     *
200
+     * @param array $exclude Array of post ids to exclude.
201
+     *
202
+     * @since  3.17.0
203
+     *
204
+     * @return string The posts NOT IN clause.
205
+     */
206
+    private static function and_exclude_posts( $exclude ) {
207
+
208
+        // Bail if the param is not set.
209
+        if ( empty( $exclude ) ) {
210
+            return '';
211
+        }
212
+
213
+        return ' AND p.ID NOT IN ( ' . implode( ',', wp_parse_id_list( $exclude ) ) . ' )';
214
+    }
215
+
216
+
217
+    /**
218
+     * Convert a `Y-m-d'T'H:i:sT` string representation of a date to a MySQL
219
+     * date string, taking into consideration the time zone.
220
+     *
221
+     * If the date string cannot be converted, the processing is stopped.
222
+     *
223
+     * @since 3.17.0
224
+     *
225
+     * @param string $value A date represented as `Y-m-d'T'H:i:sT`.
226
+     *
227
+     * @return string A MySQL string representation of the date.
228
+     */
229
+    private static function get_mysql_date_string( $value ) {
230
+
231
+        // Try to convert the value to a date, GMT timezone.
232
+        $date = date_create_from_format( 'Y-m-d\TH:i:sT', $value );
233
+
234
+        if ( false === $date ) {
235
+            wp_die( "Invalid date format, use `Y-m-d'T'H:i:sT`." );
236
+        }
237
+
238
+        // Convert the DateTime timezone to `GMT`.
239
+        $date->setTimezone( timezone_open( 'GMT' ) );
240
+
241
+        // Stop if the conversion failed.
242
+        if ( false === $date ) {
243
+            wp_die( "Invalid date format, date must be in Y-m-d'T'H:i:sT format." );
244
+        }
245
+
246
+        // Return the clause.
247
+        return $date->format( 'Y-m-d H:i:s' );
248
+    }
249 249
 
250 250
 }
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 	 *
27 27
 	 * @return string The base SQL.
28 28
 	 */
29
-	public static function get_sql( $args ) {
29
+	public static function get_sql($args) {
30 30
 
31 31
 		/*
32 32
 		Prepare the statement:
@@ -45,17 +45,17 @@  discard block
 block discarded – undo
45 45
 		*/
46 46
 
47 47
 		// @codingStandardsIgnoreStart, Ignore phpcs sanitation errors.
48
-		return self::get_base_query( $args )
49
-			   . " WHERE p.post_type IN ('" . join( "', '", array_map( 'esc_sql', (array) $args['post_type'] ) ) . "')"
48
+		return self::get_base_query($args)
49
+			   . " WHERE p.post_type IN ('".join("', '", array_map('esc_sql', (array) $args['post_type']))."')"
50 50
 			   . "  AND p.post_status = 'publish'"
51
-			   . Wordlift_Batch_Analysis_Sql_Helper::and_include_annotated( $args['include_annotated'] )
52
-			   . Wordlift_Batch_Analysis_Sql_Helper::and_post_date_from( $args['from'] )
53
-			   . Wordlift_Batch_Analysis_Sql_Helper::and_post_date_to( $args['to'] )
54
-			   . Wordlift_Batch_Analysis_Sql_Helper::and_exclude_posts( $args['exclude'] );
51
+			   . Wordlift_Batch_Analysis_Sql_Helper::and_include_annotated($args['include_annotated'])
52
+			   . Wordlift_Batch_Analysis_Sql_Helper::and_post_date_from($args['from'])
53
+			   . Wordlift_Batch_Analysis_Sql_Helper::and_post_date_to($args['to'])
54
+			   . Wordlift_Batch_Analysis_Sql_Helper::and_exclude_posts($args['exclude']);
55 55
 		// @codingStandardsIgnoreEnd
56 56
 	}
57 57
 
58
-	public static function get_sql_for_ids( $args ) {
58
+	public static function get_sql_for_ids($args) {
59 59
 
60 60
 		/*
61 61
 		Prepare the statement:
@@ -75,19 +75,19 @@  discard block
 block discarded – undo
75 75
 
76 76
 		// @codingStandardsIgnoreStart, Ignore phpcs sanitation errors.
77 77
 
78
-		return self::get_base_query( $args )
79
-			   . ' WHERE p.id IN (' . implode( ', ', wp_parse_id_list( $args['ids'] ) ) . ')';
78
+		return self::get_base_query($args)
79
+			   . ' WHERE p.id IN ('.implode(', ', wp_parse_id_list($args['ids'])).')';
80 80
 		// @codingStandardsIgnoreEnd
81 81
 	}
82 82
 
83
-	private static function get_base_query( $args ) {
83
+	private static function get_base_query($args) {
84 84
 		global $wpdb;
85 85
 
86 86
 		// Get the link options.
87
-		$link_options = serialize( array(
87
+		$link_options = serialize(array(
88 88
 			'links'           => $args['links'],
89 89
 			'min_occurrences' => $args['min_occurrences'],
90
-		) );
90
+		));
91 91
 
92 92
 		return $wpdb->prepare(
93 93
 			"INSERT INTO $wpdb->postmeta ( post_id, meta_key, meta_value )"
@@ -118,10 +118,10 @@  discard block
 block discarded – undo
118 118
 	 *
119 119
 	 * @return string The `post_content` clause.
120 120
 	 */
121
-	private static function and_include_annotated( $include ) {
121
+	private static function and_include_annotated($include) {
122 122
 
123 123
 		// Bail out with an empty string if we include all the posts.
124
-		if ( true === $include ) {
124
+		if (true === $include) {
125 125
 			return '';
126 126
 		}
127 127
 
@@ -138,15 +138,15 @@  discard block
 block discarded – undo
138 138
 	 *
139 139
 	 * @return string The start `post_date_gmt` clause
140 140
 	 */
141
-	private static function and_post_date_from( $value ) {
141
+	private static function and_post_date_from($value) {
142 142
 
143 143
 		// Bail out if the `from` isn't specified.
144
-		if ( null === $value ) {
144
+		if (null === $value) {
145 145
 			return '';
146 146
 		}
147 147
 
148 148
 		// Try to convert the value to a date, GMT timezone.
149
-		$date = self::get_mysql_date_string( $value );
149
+		$date = self::get_mysql_date_string($value);
150 150
 
151 151
 		// Return the clause.
152 152
 		return " AND p.post_date_gmt >= '$date'";
@@ -161,15 +161,15 @@  discard block
 block discarded – undo
161 161
 	 *
162 162
 	 * @return string The end `post_date_gmt` clause
163 163
 	 */
164
-	private static function and_post_date_to( $value ) {
164
+	private static function and_post_date_to($value) {
165 165
 
166 166
 		// Bail out if the `from` isn't specified.
167
-		if ( null === $value ) {
167
+		if (null === $value) {
168 168
 			return '';
169 169
 		}
170 170
 
171 171
 		// Try to convert the value to a date, GMT timezone.
172
-		$date = self::get_mysql_date_string( $value );
172
+		$date = self::get_mysql_date_string($value);
173 173
 
174 174
 		// Return the clause.
175 175
 		return " AND p.post_date_gmt <= '$date'";
@@ -184,14 +184,14 @@  discard block
 block discarded – undo
184 184
 	 *
185 185
 	 * @return string The posts IN clause.
186 186
 	 */
187
-	private static function and_include_posts( $include ) {
187
+	private static function and_include_posts($include) {
188 188
 
189 189
 		// Bail if the param is not set.
190
-		if ( empty( $include ) ) {
190
+		if (empty($include)) {
191 191
 			return '';
192 192
 		}
193 193
 
194
-		return ' AND p.ID IN ( ' . implode( ',', wp_parse_id_list( $include ) ) . ' )';
194
+		return ' AND p.ID IN ( '.implode(',', wp_parse_id_list($include)).' )';
195 195
 	}
196 196
 
197 197
 	/**
@@ -203,14 +203,14 @@  discard block
 block discarded – undo
203 203
 	 *
204 204
 	 * @return string The posts NOT IN clause.
205 205
 	 */
206
-	private static function and_exclude_posts( $exclude ) {
206
+	private static function and_exclude_posts($exclude) {
207 207
 
208 208
 		// Bail if the param is not set.
209
-		if ( empty( $exclude ) ) {
209
+		if (empty($exclude)) {
210 210
 			return '';
211 211
 		}
212 212
 
213
-		return ' AND p.ID NOT IN ( ' . implode( ',', wp_parse_id_list( $exclude ) ) . ' )';
213
+		return ' AND p.ID NOT IN ( '.implode(',', wp_parse_id_list($exclude)).' )';
214 214
 	}
215 215
 
216 216
 
@@ -226,25 +226,25 @@  discard block
 block discarded – undo
226 226
 	 *
227 227
 	 * @return string A MySQL string representation of the date.
228 228
 	 */
229
-	private static function get_mysql_date_string( $value ) {
229
+	private static function get_mysql_date_string($value) {
230 230
 
231 231
 		// Try to convert the value to a date, GMT timezone.
232
-		$date = date_create_from_format( 'Y-m-d\TH:i:sT', $value );
232
+		$date = date_create_from_format('Y-m-d\TH:i:sT', $value);
233 233
 
234
-		if ( false === $date ) {
235
-			wp_die( "Invalid date format, use `Y-m-d'T'H:i:sT`." );
234
+		if (false === $date) {
235
+			wp_die("Invalid date format, use `Y-m-d'T'H:i:sT`.");
236 236
 		}
237 237
 
238 238
 		// Convert the DateTime timezone to `GMT`.
239
-		$date->setTimezone( timezone_open( 'GMT' ) );
239
+		$date->setTimezone(timezone_open('GMT'));
240 240
 
241 241
 		// Stop if the conversion failed.
242
-		if ( false === $date ) {
243
-			wp_die( "Invalid date format, date must be in Y-m-d'T'H:i:sT format." );
242
+		if (false === $date) {
243
+			wp_die("Invalid date format, date must be in Y-m-d'T'H:i:sT format.");
244 244
 		}
245 245
 
246 246
 		// Return the clause.
247
-		return $date->format( 'Y-m-d H:i:s' );
247
+		return $date->format('Y-m-d H:i:s');
248 248
 	}
249 249
 
250 250
 }
Please login to merge, or discard this patch.