Passed
Push — master ( 75834f...73b77e )
by Paul
04:12
created
plugin/Modules/Schema.php 2 patches
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -37,10 +37,10 @@  discard block
 block discarded – undo
37 37
 			if( $review->review_type != 'local' )continue;
38 38
 			$reviews[] = $this->buildReview( $review );
39 39
 		}
40
-		if( !empty( $reviews )) {
40
+		if( !empty($reviews) ) {
41 41
 			array_walk( $reviews, function( &$review ) {
42
-				unset( $review['@context'] );
43
-				unset( $review['itemReviewed'] );
42
+				unset($review['@context']);
43
+				unset($review['itemReviewed']);
44 44
 			});
45 45
 			$schema['review'] = $reviews;
46 46
 		}
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 	 */
54 54
 	public function buildSummary( $args = null )
55 55
 	{
56
-		if( is_array( $args )) {
56
+		if( is_array( $args ) ) {
57 57
 			$this->args = $args;
58 58
 		}
59 59
 		$buildSummary = glsr( Helper::class )->buildMethodName( $this->getSchemaOptionValue( 'type' ), 'buildSummaryFor' );
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 		$schema = method_exists( $this, $buildSummary )
62 62
 			? $this->$buildSummary()
63 63
 			: $this->buildSummaryForCustom();
64
-		if( !empty( $count )) {
64
+		if( !empty($count) ) {
65 65
 			$schema->aggregateRating( $this->getSchemaType( 'AggregateRating' )
66 66
 				->ratingValue( $this->getRatingValue() )
67 67
 				->reviewCount( $count )
@@ -79,11 +79,11 @@  discard block
 block discarded – undo
79 79
 	 */
80 80
 	public function render()
81 81
 	{
82
-		if( is_null( glsr()->schemas ))return;
82
+		if( is_null( glsr()->schemas ) )return;
83 83
 		printf( '<script type="application/ld+json">%s</script>', json_encode(
84 84
 			apply_filters( 'site-reviews/schema/all', glsr()->schemas ),
85 85
 			JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
86
-		));
86
+		) );
87 87
 	}
88 88
 
89 89
 	/**
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 	{
94 94
 		$schemas = glsr()->schemas;
95 95
 		$schemas[] = $schema;
96
-		glsr()->schemas = array_map( 'unserialize', array_unique( array_map( 'serialize', $schemas )));
96
+		glsr()->schemas = array_map( 'unserialize', array_unique( array_map( 'serialize', $schemas ) ) );
97 97
 	}
98 98
 
99 99
 	/**
@@ -103,16 +103,16 @@  discard block
 block discarded – undo
103 103
 	protected function buildReview( $review )
104 104
 	{
105 105
 		$schema = $this->getSchemaType( 'Review' )
106
-			->doIf( !in_array( 'title', $this->args['hide'] ), function( $schema ) use( $review ) {
106
+			->doIf( !in_array( 'title', $this->args['hide'] ), function( $schema ) use($review) {
107 107
 				$schema->name( $review->title );
108 108
 			})
109
-			->doIf( !in_array( 'excerpt', $this->args['hide'] ), function( $schema ) use( $review ) {
109
+			->doIf( !in_array( 'excerpt', $this->args['hide'] ), function( $schema ) use($review) {
110 110
 				$schema->reviewBody( $review->content );
111 111
 			})
112
-			->datePublished(( new DateTime( $review->date ))->format( DateTime::ISO8601 ))
113
-			->author( $this->getSchemaType( 'Person' )->name( $review->author ))
114
-			->itemReviewed( $this->getSchemaType()->name( $this->getSchemaOptionValue( 'name' )));
115
-		if( !empty( $review->rating )) {
112
+			->datePublished( (new DateTime( $review->date ))->format( DateTime::ISO8601 ) )
113
+			->author( $this->getSchemaType( 'Person' )->name( $review->author ) )
114
+			->itemReviewed( $this->getSchemaType()->name( $this->getSchemaOptionValue( 'name' ) ) );
115
+		if( !empty($review->rating) ) {
116 116
 			$schema->reviewRating( $this->getSchemaType( 'Rating' )
117 117
 				->ratingValue( $review->rating )
118 118
 				->bestRating( Rating::MAX_RATING )
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 	{
130 130
 		foreach( $values as $value ) {
131 131
 			$option = $this->getSchemaOptionValue( $value );
132
-			if( empty( $option ))continue;
132
+			if( empty($option) )continue;
133 133
 			$schema->$value( $option );
134 134
 		}
135 135
 		return $schema;
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 	{
143 143
 		return $this->buildSchemaValues( $this->getSchemaType(), [
144 144
 			'description', 'image', 'name', 'url',
145
-		]);
145
+		] );
146 146
 	}
147 147
 
148 148
 	/**
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 	{
153 153
 		return $this->buildSchemaValues( $this->buildSummaryForCustom(), [
154 154
 			'address', 'priceRange', 'telephone',
155
-		]);
155
+		] );
156 156
 	}
157 157
 
158 158
 	/**
@@ -162,10 +162,10 @@  discard block
 block discarded – undo
162 162
 	{
163 163
 		$offers = $this->buildSchemaValues( $this->getSchemaType( 'AggregateOffer' ), [
164 164
 			'highPrice', 'lowPrice', 'priceCurrency',
165
-		]);
165
+		] );
166 166
 		return $this->buildSummaryForCustom()
167 167
 			->offers( $offers )
168
-			->setProperty( '@id', $this->getSchemaOptionValue( 'url' ));
168
+			->setProperty( '@id', $this->getSchemaOptionValue( 'url' ) );
169 169
 	}
170 170
 
171 171
 	/**
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 	 */
190 190
 	protected function getReviews( $force = false )
191 191
 	{
192
-		if( !isset( $this->reviews ) || $force ) {
192
+		if( !isset($this->reviews) || $force ) {
193 193
 			$args = wp_parse_args( ['count' => -1], $this->args );
194 194
 			$this->reviews = glsr( Database::class )->getReviews( $args )->results;
195 195
 		}
@@ -204,14 +204,14 @@  discard block
 block discarded – undo
204 204
 	protected function getSchemaOption( $option, $fallback )
205 205
 	{
206 206
 		$option = strtolower( $option );
207
-		if( $schemaOption = trim( (string)get_post_meta( intval( get_the_ID() ), 'schema_'.$option, true ))) {
207
+		if( $schemaOption = trim( (string)get_post_meta( intval( get_the_ID() ), 'schema_'.$option, true ) ) ) {
208 208
 			return $schemaOption;
209 209
 		}
210 210
 		$setting = glsr( OptionManager::class )->get( 'settings.schema.'.$option );
211
-		if( is_array( $setting )) {
211
+		if( is_array( $setting ) ) {
212 212
 			return $this->getSchemaOptionDefault( $setting, $fallback );
213 213
 		}
214
-		return !empty( $setting )
214
+		return !empty($setting)
215 215
 			? $setting
216 216
 			: $fallback;
217 217
 	}
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 		$setting = wp_parse_args( $setting, [
227 227
 			'custom' => '',
228 228
 			'default' => $fallback,
229
-		]);
229
+		] );
230 230
 		return $setting['default'] != 'custom'
231 231
 			? $setting['default']
232 232
 			: $setting['custom'];
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
 	 */
264 264
 	protected function getSchemaType( $type = null )
265 265
 	{
266
-		if( !is_string( $type )) {
266
+		if( !is_string( $type ) ) {
267 267
 			$type = $this->getSchemaOption( 'type', 'LocalBusiness' );
268 268
 		}
269 269
 		$className = glsr( Helper::class )->buildClassName( $type, 'Modules\Schema' );
@@ -278,11 +278,11 @@  discard block
 block discarded – undo
278 278
 	protected function getThingDescription()
279 279
 	{
280 280
 		$post = get_post();
281
-		if( !( $post instanceof WP_Post )) {
281
+		if( !($post instanceof WP_Post) ) {
282 282
 			return '';
283 283
 		}
284
-		$text = strip_shortcodes( wp_strip_all_tags( $post->post_excerpt ));
285
-		return wp_trim_words( $text, apply_filters( 'excerpt_length', 55 ));
284
+		$text = strip_shortcodes( wp_strip_all_tags( $post->post_excerpt ) );
285
+		return wp_trim_words( $text, apply_filters( 'excerpt_length', 55 ) );
286 286
 	}
287 287
 
288 288
 	/**
Please login to merge, or discard this patch.
Braces   +12 added lines, -4 removed lines patch added patch discarded remove patch
@@ -34,7 +34,9 @@  discard block
 block discarded – undo
34 34
 		foreach( glsr( Database::class )->getReviews( $this->args )->results as $review ) {
35 35
 			// Only include critic reviews that have been directly produced by your site, not reviews from third- party sites or syndicated reviews.
36 36
 			// @see https://developers.google.com/search/docs/data-types/review
37
-			if( $review->review_type != 'local' )continue;
37
+			if( $review->review_type != 'local' ) {
38
+				continue;
39
+			}
38 40
 			$reviews[] = $this->buildReview( $review );
39 41
 		}
40 42
 		if( !empty( $reviews )) {
@@ -79,7 +81,9 @@  discard block
 block discarded – undo
79 81
 	 */
80 82
 	public function render()
81 83
 	{
82
-		if( is_null( glsr()->schemas ))return;
84
+		if( is_null( glsr()->schemas )) {
85
+			return;
86
+		}
83 87
 		printf( '<script type="application/ld+json">%s</script>', json_encode(
84 88
 			apply_filters( 'site-reviews/schema/all', glsr()->schemas ),
85 89
 			JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
@@ -129,7 +133,9 @@  discard block
 block discarded – undo
129 133
 	{
130 134
 		foreach( $values as $value ) {
131 135
 			$option = $this->getSchemaOptionValue( $value );
132
-			if( empty( $option ))continue;
136
+			if( empty( $option )) {
137
+				continue;
138
+			}
133 139
 			$schema->$value( $option );
134 140
 		}
135 141
 		return $schema;
@@ -243,7 +249,9 @@  discard block
 block discarded – undo
243 249
 		if( $value != $fallback ) {
244 250
 			return $value;
245 251
 		}
246
-		if( !is_single() && !is_page() )return;
252
+		if( !is_single() && !is_page() ) {
253
+			return;
254
+		}
247 255
 		// @todo make this dynamic
248 256
 		switch( $option ) {
249 257
 			case 'description':
Please login to merge, or discard this patch.