Passed
Push — master ( af979f...1dfed5 )
by Paul
08:16 queued 04:12
created
plugin/Modules/Validator/ValidateReview.php 1 patch
Spacing   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -58,12 +58,12 @@  discard block
 block discarded – undo
58 58
     /**
59 59
      * @return static
60 60
      */
61
-    public function validate(array $request)
61
+    public function validate( array $request )
62 62
     {
63 63
         $request['ip_address'] = Helper::getIpAddress(); // required for Akismet and Blacklist validation
64 64
         $this->form_id = $request['form_id'];
65
-        $this->options = glsr(OptionManager::class)->all();
66
-        $this->request = $this->validateRequest($request);
65
+        $this->options = glsr( OptionManager::class )->all();
66
+        $this->request = $this->validateRequest( $request );
67 67
         $this->validateCustom();
68 68
         $this->validatePermission();
69 69
         $this->validateHoneyPot();
@@ -71,8 +71,8 @@  discard block
 block discarded – undo
71 71
         $this->validateBlacklist();
72 72
         $this->validateAkismet();
73 73
         $this->validateRecaptcha();
74
-        if (!empty($this->error)) {
75
-            $this->setSessionValues('message', $this->error);
74
+        if( !empty($this->error) ) {
75
+            $this->setSessionValues( 'message', $this->error );
76 76
         }
77 77
         return $this;
78 78
     }
@@ -82,9 +82,9 @@  discard block
 block discarded – undo
82 82
      * @param mixed $fallback
83 83
      * @return mixed
84 84
      */
85
-    protected function getOption($path, $fallback = '')
85
+    protected function getOption( $path, $fallback = '' )
86 86
     {
87
-        return Arr::get($this->options, $path, $fallback);
87
+        return Arr::get( $this->options, $path, $fallback );
88 88
     }
89 89
 
90 90
     /**
@@ -92,11 +92,11 @@  discard block
 block discarded – undo
92 92
      */
93 93
     protected function getRecaptchaStatus()
94 94
     {
95
-        if (!glsr(OptionManager::class)->isRecaptchaEnabled()) {
95
+        if( !glsr( OptionManager::class )->isRecaptchaEnabled() ) {
96 96
             return static::RECAPTCHA_DISABLED;
97 97
         }
98
-        if (empty($this->request['_recaptcha-token'])) {
99
-            return $this->request['_counter'] < intval(apply_filters('site-reviews/recaptcha/timeout', 5))
98
+        if( empty($this->request['_recaptcha-token']) ) {
99
+            return $this->request['_counter'] < intval( apply_filters( 'site-reviews/recaptcha/timeout', 5 ) )
100 100
                 ? static::RECAPTCHA_EMPTY
101 101
                 : static::RECAPTCHA_FAILED;
102 102
         }
@@ -108,23 +108,23 @@  discard block
 block discarded – undo
108 108
      */
109 109
     protected function getRecaptchaTokenStatus()
110 110
     {
111
-        $endpoint = add_query_arg([
111
+        $endpoint = add_query_arg( [
112 112
             'remoteip' => Helper::getIpAddress(),
113 113
             'response' => $this->request['_recaptcha-token'],
114
-            'secret' => $this->getOption('settings.submissions.recaptcha.secret'),
115
-        ], static::RECAPTCHA_ENDPOINT);
116
-        if (is_wp_error($response = wp_remote_get($endpoint))) {
117
-            glsr_log()->error($response->get_error_message());
114
+            'secret' => $this->getOption( 'settings.submissions.recaptcha.secret' ),
115
+        ], static::RECAPTCHA_ENDPOINT );
116
+        if( is_wp_error( $response = wp_remote_get( $endpoint ) ) ) {
117
+            glsr_log()->error( $response->get_error_message() );
118 118
             return static::RECAPTCHA_FAILED;
119 119
         }
120
-        $response = json_decode(wp_remote_retrieve_body($response));
121
-        if (!empty($response->success)) {
122
-            return boolval($response->success)
120
+        $response = json_decode( wp_remote_retrieve_body( $response ) );
121
+        if( !empty($response->success) ) {
122
+            return boolval( $response->success )
123 123
                 ? static::RECAPTCHA_VALID
124 124
                 : static::RECAPTCHA_INVALID;
125 125
         }
126
-        foreach ($response->{'error-codes'} as $error) {
127
-            glsr_log()->error('reCAPTCHA error: '.$error);
126
+        foreach( $response->{'error-codes'} as $error ) {
127
+            glsr_log()->error( 'reCAPTCHA error: '.$error );
128 128
         }
129 129
         return static::RECAPTCHA_INVALID;
130 130
     }
@@ -132,35 +132,35 @@  discard block
 block discarded – undo
132 132
     /**
133 133
      * @return array
134 134
      */
135
-    protected function getValidationRules(array $request)
135
+    protected function getValidationRules( array $request )
136 136
     {
137 137
         $rules = array_intersect_key(
138
-            apply_filters('site-reviews/validation/rules', static::VALIDATION_RULES, $request),
139
-            array_flip($this->getOption('settings.submissions.required', []))
138
+            apply_filters( 'site-reviews/validation/rules', static::VALIDATION_RULES, $request ),
139
+            array_flip( $this->getOption( 'settings.submissions.required', [] ) )
140 140
         );
141
-        $excluded = explode(',', Arr::get($request, 'excluded'));
142
-        return array_diff_key($rules, array_flip($excluded));
141
+        $excluded = explode( ',', Arr::get( $request, 'excluded' ) );
142
+        return array_diff_key( $rules, array_flip( $excluded ) );
143 143
     }
144 144
 
145 145
     /**
146 146
      * @return bool
147 147
      */
148
-    protected function isRequestValid(array $request)
148
+    protected function isRequestValid( array $request )
149 149
     {
150
-        $rules = $this->getValidationRules($request);
151
-        $errors = glsr(Validator::class)->validate($request, $rules);
152
-        if (empty($errors)) {
150
+        $rules = $this->getValidationRules( $request );
151
+        $errors = glsr( Validator::class )->validate( $request, $rules );
152
+        if( empty($errors) ) {
153 153
             return true;
154 154
         }
155
-        $this->error = __('Please fix the submission errors.', 'site-reviews');
156
-        $this->setSessionValues('errors', $errors);
157
-        $this->setSessionValues('values', $request);
155
+        $this->error = __( 'Please fix the submission errors.', 'site-reviews' );
156
+        $this->setSessionValues( 'errors', $errors );
157
+        $this->setSessionValues( 'values', $request );
158 158
         return false;
159 159
     }
160 160
 
161
-    protected function setError($message, $loggedMessage = '')
161
+    protected function setError( $message, $loggedMessage = '' )
162 162
     {
163
-        $this->setSessionValues('errors', [], $loggedMessage);
163
+        $this->setSessionValues( 'errors', [], $loggedMessage );
164 164
         $this->error = $message;
165 165
     }
166 166
 
@@ -170,11 +170,11 @@  discard block
 block discarded – undo
170 170
      * @param string $loggedMessage
171 171
      * @return void
172 172
      */
173
-    protected function setSessionValues($type, $value, $loggedMessage = '')
173
+    protected function setSessionValues( $type, $value, $loggedMessage = '' )
174 174
     {
175
-        glsr()->sessionSet($this->form_id.$type, $value);
176
-        if (!empty($loggedMessage)) {
177
-            glsr_log()->warning($loggedMessage)->debug($this->request);
175
+        glsr()->sessionSet( $this->form_id.$type, $value );
176
+        if( !empty($loggedMessage) ) {
177
+            glsr_log()->warning( $loggedMessage )->debug( $this->request );
178 178
         }
179 179
     }
180 180
 
@@ -183,11 +183,11 @@  discard block
 block discarded – undo
183 183
      */
184 184
     protected function validateAkismet()
185 185
     {
186
-        if (!empty($this->error)) {
186
+        if( !empty($this->error) ) {
187 187
             return;
188 188
         }
189
-        if (glsr(Akismet::class)->isSpam($this->request)) {
190
-            $this->setError(__('This review has been flagged as possible spam and cannot be submitted.', 'site-reviews'),
189
+        if( glsr( Akismet::class )->isSpam( $this->request ) ) {
190
+            $this->setError( __( 'This review has been flagged as possible spam and cannot be submitted.', 'site-reviews' ),
191 191
                 'Akismet caught a spam submission (consider adding the IP address to the blacklist):'
192 192
             );
193 193
         }
@@ -198,18 +198,18 @@  discard block
 block discarded – undo
198 198
      */
199 199
     protected function validateBlacklist()
200 200
     {
201
-        if (!empty($this->error)) {
201
+        if( !empty($this->error) ) {
202 202
             return;
203 203
         }
204
-        if (!glsr(Blacklist::class)->isBlacklisted($this->request)) {
204
+        if( !glsr( Blacklist::class )->isBlacklisted( $this->request ) ) {
205 205
             return;
206 206
         }
207
-        $blacklistAction = $this->getOption('settings.submissions.blacklist.action');
208
-        if ('reject' != $blacklistAction) {
207
+        $blacklistAction = $this->getOption( 'settings.submissions.blacklist.action' );
208
+        if( 'reject' != $blacklistAction ) {
209 209
             $this->request['blacklisted'] = true;
210 210
             return;
211 211
         }
212
-        $this->setError(__('Your review cannot be submitted at this time.', 'site-reviews'),
212
+        $this->setError( __( 'Your review cannot be submitted at this time.', 'site-reviews' ),
213 213
             'Blacklisted submission detected:'
214 214
         );
215 215
     }
@@ -219,18 +219,18 @@  discard block
 block discarded – undo
219 219
      */
220 220
     protected function validateCustom()
221 221
     {
222
-        if (!empty($this->error)) {
222
+        if( !empty($this->error) ) {
223 223
             return;
224 224
         }
225
-        $validated = apply_filters('site-reviews/validate/custom', true, $this->request);
226
-        if (true === $validated) {
225
+        $validated = apply_filters( 'site-reviews/validate/custom', true, $this->request );
226
+        if( true === $validated ) {
227 227
             return;
228 228
         }
229
-        $errorMessage = is_string($validated)
229
+        $errorMessage = is_string( $validated )
230 230
             ? $validated
231
-            : __('The review submission failed. Please notify the site administrator.', 'site-reviews');
232
-        $this->setError($errorMessage);
233
-        $this->setSessionValues('values', $this->request);
231
+            : __( 'The review submission failed. Please notify the site administrator.', 'site-reviews' );
232
+        $this->setError( $errorMessage );
233
+        $this->setSessionValues( 'values', $this->request );
234 234
     }
235 235
 
236 236
     /**
@@ -238,11 +238,11 @@  discard block
 block discarded – undo
238 238
      */
239 239
     protected function validateHoneyPot()
240 240
     {
241
-        if (!empty($this->error)) {
241
+        if( !empty($this->error) ) {
242 242
             return;
243 243
         }
244
-        if (!empty($this->request['gotcha'])) {
245
-            $this->setError(__('The review submission failed. Please notify the site administrator.', 'site-reviews'),
244
+        if( !empty($this->request['gotcha']) ) {
245
+            $this->setError( __( 'The review submission failed. Please notify the site administrator.', 'site-reviews' ),
246 246
                 'The Honeypot caught a bad submission:'
247 247
             );
248 248
         }
@@ -253,11 +253,11 @@  discard block
 block discarded – undo
253 253
      */
254 254
     protected function validatePermission()
255 255
     {
256
-        if (!empty($this->error)) {
256
+        if( !empty($this->error) ) {
257 257
             return;
258 258
         }
259
-        if (!is_user_logged_in() && glsr(OptionManager::class)->getBool('settings.general.require.login')) {
260
-            $this->setError(__('You must be logged in to submit a review.', 'site-reviews'));
259
+        if( !is_user_logged_in() && glsr( OptionManager::class )->getBool( 'settings.general.require.login' ) ) {
260
+            $this->setError( __( 'You must be logged in to submit a review.', 'site-reviews' ) );
261 261
         }
262 262
     }
263 263
 
@@ -266,11 +266,11 @@  discard block
 block discarded – undo
266 266
      */
267 267
     protected function validateReviewLimits()
268 268
     {
269
-        if (!empty($this->error)) {
269
+        if( !empty($this->error) ) {
270 270
             return;
271 271
         }
272
-        if (glsr(ReviewLimits::class)->hasReachedLimit($this->request)) {
273
-            $this->setError(__('You have already submitted a review.', 'site-reviews'));
272
+        if( glsr( ReviewLimits::class )->hasReachedLimit( $this->request ) ) {
273
+            $this->setError( __( 'You have already submitted a review.', 'site-reviews' ) );
274 274
         }
275 275
     }
276 276
 
@@ -279,33 +279,33 @@  discard block
 block discarded – undo
279 279
      */
280 280
     protected function validateRecaptcha()
281 281
     {
282
-        if (!empty($this->error)) {
282
+        if( !empty($this->error) ) {
283 283
             return;
284 284
         }
285 285
         $status = $this->getRecaptchaStatus();
286
-        if (in_array($status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID])) {
286
+        if( in_array( $status, [static::RECAPTCHA_DISABLED, static::RECAPTCHA_VALID] ) ) {
287 287
             return;
288 288
         }
289
-        if (static::RECAPTCHA_EMPTY === $status) {
290
-            $this->setSessionValues('recaptcha', 'unset');
289
+        if( static::RECAPTCHA_EMPTY === $status ) {
290
+            $this->setSessionValues( 'recaptcha', 'unset' );
291 291
             $this->recaptchaIsUnset = true;
292 292
             return;
293 293
         }
294
-        $this->setSessionValues('recaptcha', 'reset');
294
+        $this->setSessionValues( 'recaptcha', 'reset' );
295 295
         $errors = [
296
-            static::RECAPTCHA_FAILED => __('The reCAPTCHA failed to load, please refresh the page and try again.', 'site-reviews'),
297
-            static::RECAPTCHA_INVALID => __('The reCAPTCHA verification failed, please try again.', 'site-reviews'),
296
+            static::RECAPTCHA_FAILED => __( 'The reCAPTCHA failed to load, please refresh the page and try again.', 'site-reviews' ),
297
+            static::RECAPTCHA_INVALID => __( 'The reCAPTCHA verification failed, please try again.', 'site-reviews' ),
298 298
         ];
299
-        $this->setError($errors[$status]);
299
+        $this->setError( $errors[$status] );
300 300
     }
301 301
 
302 302
     /**
303 303
      * @return array
304 304
      */
305
-    protected function validateRequest(array $request)
305
+    protected function validateRequest( array $request )
306 306
     {
307
-        return $this->isRequestValid($request)
308
-            ? array_merge(glsr(ValidateReviewDefaults::class)->defaults(), $request)
307
+        return $this->isRequestValid( $request )
308
+            ? array_merge( glsr( ValidateReviewDefaults::class )->defaults(), $request )
309 309
             : $request;
310 310
     }
311 311
 }
Please login to merge, or discard this patch.
plugin/Modules/Schema.php 1 patch
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -30,18 +30,18 @@  discard block
 block discarded – undo
30 30
     /**
31 31
      * @return array
32 32
      */
33
-    public function build(array $args = [])
33
+    public function build( array $args = [] )
34 34
     {
35 35
         $this->args = $args;
36
-        $schema = $this->buildSummary($args);
37
-        if (!empty($schema)) {
36
+        $schema = $this->buildSummary( $args );
37
+        if( !empty($schema) ) {
38 38
             $reviews = $this->buildReviews();
39
-            foreach ($reviews as &$review) {
39
+            foreach( $reviews as &$review ) {
40 40
                 unset($review['@context']);
41 41
                 unset($review['itemReviewed']);
42 42
             });
43 43
         }
44
-        if (!empty($reviews)) {
44
+        if( !empty($reviews) ) {
45 45
             $schema['review'] = $reviews;
46 46
         }
47 47
         return $schema;
@@ -51,25 +51,25 @@  discard block
 block discarded – undo
51 51
      * @param array|null $args
52 52
      * @return array
53 53
      */
54
-    public function buildSummary($args = null)
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
-        $buildSummary = Helper::buildMethodName($this->getSchemaOptionValue('type'), 'buildSummaryFor');
60
-        if ($count = array_sum($this->getRatingCounts())) {
61
-            $schema = method_exists($this, $buildSummary)
59
+        $buildSummary = Helper::buildMethodName( $this->getSchemaOptionValue( 'type' ), 'buildSummaryFor' );
60
+        if( $count = array_sum( $this->getRatingCounts() ) ) {
61
+            $schema = method_exists( $this, $buildSummary )
62 62
                 ? $this->$buildSummary()
63 63
                 : $this->buildSummaryForCustom();
64 64
             $schema->aggregateRating(
65
-                $this->getSchemaType('AggregateRating')
66
-                    ->ratingValue($this->getRatingValue())
67
-                    ->reviewCount($count)
68
-                    ->bestRating(glsr()->constant('MAX_RATING', Rating::class))
69
-                    ->worstRating(glsr()->constant('MIN_RATING', Rating::class))
65
+                $this->getSchemaType( 'AggregateRating' )
66
+                    ->ratingValue( $this->getRatingValue() )
67
+                    ->reviewCount( $count )
68
+                    ->bestRating( glsr()->constant( 'MAX_RATING', Rating::class ) )
69
+                    ->worstRating( glsr()->constant( 'MIN_RATING', Rating::class ) )
70 70
             );
71 71
             $schema = $schema->toArray();
72
-            return apply_filters('site-reviews/schema/'.$schema['@type'], $schema, $args);
72
+            return apply_filters( 'site-reviews/schema/'.$schema['@type'], $schema, $args );
73 73
         }
74 74
         return [];
75 75
     }
@@ -79,53 +79,53 @@  discard block
 block discarded – undo
79 79
      */
80 80
     public function render()
81 81
     {
82
-        if (empty(glsr()->schemas)) {
82
+        if( empty(glsr()->schemas) ) {
83 83
             return;
84 84
         }
85
-        printf('<script type="application/ld+json">%s</script>', json_encode(
86
-            apply_filters('site-reviews/schema/all', glsr()->schemas),
85
+        printf( '<script type="application/ld+json">%s</script>', json_encode(
86
+            apply_filters( 'site-reviews/schema/all', glsr()->schemas ),
87 87
             JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
88
-        ));
88
+        ) );
89 89
     }
90 90
 
91 91
     /**
92 92
      * @return void
93 93
      */
94
-    public function store(array $schema)
94
+    public function store( array $schema )
95 95
     {
96
-        if (empty($schema)) {
96
+        if( empty($schema) ) {
97 97
             return;
98 98
         }
99 99
         $schemas = glsr()->schemas;
100 100
         $schemas[] = $schema;
101
-        glsr()->schemas = array_map('unserialize', array_unique(array_map('serialize', $schemas)));
101
+        glsr()->schemas = array_map( 'unserialize', array_unique( array_map( 'serialize', $schemas ) ) );
102 102
     }
103 103
 
104 104
     /**
105 105
      * @param Review $review
106 106
      * @return array
107 107
      */
108
-    protected function buildReview($review)
108
+    protected function buildReview( $review )
109 109
     {
110
-        $schema = $this->getSchemaType('Review')
111
-            ->doIf(!in_array('title', $this->args['hide']), function ($schema) use ($review) {
112
-                $schema->name($review->title);
110
+        $schema = $this->getSchemaType( 'Review' )
111
+            ->doIf( !in_array( 'title', $this->args['hide'] ), function( $schema ) use ($review) {
112
+                $schema->name( $review->title );
113 113
             })
114
-            ->doIf(!in_array('excerpt', $this->args['hide']), function ($schema) use ($review) {
115
-                $schema->reviewBody($review->content);
114
+            ->doIf( !in_array( 'excerpt', $this->args['hide'] ), function( $schema ) use ($review) {
115
+                $schema->reviewBody( $review->content );
116 116
             })
117
-            ->datePublished((new DateTime($review->date)))
118
-            ->author($this->getSchemaType('Person')->name($review->author))
119
-            ->itemReviewed($this->getSchemaType()->name($this->getSchemaOptionValue('name')));
120
-        if (!empty($review->rating)) {
117
+            ->datePublished( (new DateTime( $review->date )) )
118
+            ->author( $this->getSchemaType( 'Person' )->name( $review->author ) )
119
+            ->itemReviewed( $this->getSchemaType()->name( $this->getSchemaOptionValue( 'name' ) ) );
120
+        if( !empty($review->rating) ) {
121 121
             $schema->reviewRating(
122
-                $this->getSchemaType('Rating')
123
-                    ->ratingValue($review->rating)
124
-                    ->bestRating(glsr()->constant('MAX_RATING', Rating::class))
125
-                    ->worstRating(glsr()->constant('MIN_RATING', Rating::class))
122
+                $this->getSchemaType( 'Rating' )
123
+                    ->ratingValue( $review->rating )
124
+                    ->bestRating( glsr()->constant( 'MAX_RATING', Rating::class ) )
125
+                    ->worstRating( glsr()->constant( 'MIN_RATING', Rating::class ) )
126 126
             );
127 127
         }
128
-        return apply_filters('site-reviews/schema/review', $schema->toArray(), $review, $this->args);
128
+        return apply_filters( 'site-reviews/schema/review', $schema->toArray(), $review, $this->args );
129 129
     }
130 130
 
131 131
     /**
@@ -134,11 +134,11 @@  discard block
 block discarded – undo
134 134
     protected function buildReviews()
135 135
     {
136 136
         $reviews = [];
137
-        foreach (glsr(ReviewManager::class)->get($this->args) as $review) {
137
+        foreach( glsr( ReviewManager::class )->get( $this->args ) as $review ) {
138 138
             // Only include critic reviews that have been directly produced by your site, not reviews from third-party sites or syndicated reviews.
139 139
             // @see https://developers.google.com/search/docs/data-types/review
140
-            if ('local' === $review->review_type) {
141
-                $reviews[] = $this->buildReview($review);
140
+            if( 'local' === $review->review_type ) {
141
+                $reviews[] = $this->buildReview( $review );
142 142
             }
143 143
         }
144 144
         return $reviews;
@@ -148,14 +148,14 @@  discard block
 block discarded – undo
148 148
      * @param mixed $schema
149 149
      * @return mixed
150 150
      */
151
-    protected function buildSchemaValues($schema, array $values = [])
151
+    protected function buildSchemaValues( $schema, array $values = [] )
152 152
     {
153
-        foreach ($values as $value) {
154
-            $option = $this->getSchemaOptionValue($value);
155
-            if (empty($option)) {
153
+        foreach( $values as $value ) {
154
+            $option = $this->getSchemaOptionValue( $value );
155
+            if( empty($option) ) {
156 156
                 continue;
157 157
             }
158
-            $schema->$value($option);
158
+            $schema->$value( $option );
159 159
         }
160 160
         return $schema;
161 161
     }
@@ -165,9 +165,9 @@  discard block
 block discarded – undo
165 165
      */
166 166
     protected function buildSummaryForCustom()
167 167
     {
168
-        return $this->buildSchemaValues($this->getSchemaType(), [
168
+        return $this->buildSchemaValues( $this->getSchemaType(), [
169 169
             'description', 'image', 'name', 'url',
170
-        ]);
170
+        ] );
171 171
     }
172 172
 
173 173
     /**
@@ -175,9 +175,9 @@  discard block
 block discarded – undo
175 175
      */
176 176
     protected function buildSummaryForLocalBusiness()
177 177
     {
178
-        return $this->buildSchemaValues($this->buildSummaryForCustom(), [
178
+        return $this->buildSchemaValues( $this->buildSummaryForCustom(), [
179 179
             'address', 'priceRange', 'telephone',
180
-        ]);
180
+        ] );
181 181
     }
182 182
 
183 183
     /**
@@ -185,15 +185,15 @@  discard block
 block discarded – undo
185 185
      */
186 186
     protected function buildSummaryForProduct()
187 187
     {
188
-        $offerType = $this->getSchemaOption('offerType', 'AggregateOffer');
189
-        $offers = $this->buildSchemaValues($this->getSchemaType($offerType), [
188
+        $offerType = $this->getSchemaOption( 'offerType', 'AggregateOffer' );
189
+        $offers = $this->buildSchemaValues( $this->getSchemaType( $offerType ), [
190 190
             'highPrice', 'lowPrice', 'price', 'priceCurrency',
191
-        ]);
191
+        ] );
192 192
         return $this->buildSummaryForCustom()
193
-            ->doIf(!empty($offers->getProperties()), function ($schema) use ($offers) {
194
-                $schema->offers($offers);
193
+            ->doIf( !empty($offers->getProperties()), function( $schema ) use ($offers) {
194
+                $schema->offers( $offers );
195 195
             })
196
-            ->setProperty('@id', $this->getSchemaOptionValue('url').'#product');
196
+            ->setProperty( '@id', $this->getSchemaOptionValue( 'url' ).'#product' );
197 197
     }
198 198
 
199 199
     /**
@@ -201,8 +201,8 @@  discard block
 block discarded – undo
201 201
      */
202 202
     protected function getRatingCounts()
203 203
     {
204
-        if (!isset($this->ratingCounts)) {
205
-            $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($this->args);
204
+        if( !isset($this->ratingCounts) ) {
205
+            $this->ratingCounts = glsr( ReviewManager::class )->getRatingCounts( $this->args );
206 206
         }
207 207
         return $this->ratingCounts;
208 208
     }
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
      */
213 213
     protected function getRatingValue()
214 214
     {
215
-        return glsr(Rating::class)->getAverage($this->getRatingCounts());
215
+        return glsr( Rating::class )->getAverage( $this->getRatingCounts() );
216 216
     }
217 217
 
218 218
     /**
@@ -220,15 +220,15 @@  discard block
 block discarded – undo
220 220
      * @param string $fallback
221 221
      * @return string
222 222
      */
223
-    protected function getSchemaOption($option, $fallback)
223
+    protected function getSchemaOption( $option, $fallback )
224 224
     {
225
-        $option = strtolower($option);
226
-        if ($schemaOption = trim((string) get_post_meta(intval(get_the_ID()), 'schema_'.$option, true))) {
225
+        $option = strtolower( $option );
226
+        if( $schemaOption = trim( (string)get_post_meta( intval( get_the_ID() ), 'schema_'.$option, true ) ) ) {
227 227
             return $schemaOption;
228 228
         }
229
-        $setting = glsr(OptionManager::class)->get('settings.schema.'.$option);
230
-        if (is_array($setting)) {
231
-            return $this->getSchemaOptionDefault($setting, $fallback);
229
+        $setting = glsr( OptionManager::class )->get( 'settings.schema.'.$option );
230
+        if( is_array( $setting ) ) {
231
+            return $this->getSchemaOptionDefault( $setting, $fallback );
232 232
         }
233 233
         return !empty($setting)
234 234
             ? $setting
@@ -239,12 +239,12 @@  discard block
 block discarded – undo
239 239
      * @param string $fallback
240 240
      * @return string
241 241
      */
242
-    protected function getSchemaOptionDefault(array $setting, $fallback)
242
+    protected function getSchemaOptionDefault( array $setting, $fallback )
243 243
     {
244
-        $setting = wp_parse_args($setting, [
244
+        $setting = wp_parse_args( $setting, [
245 245
             'custom' => '',
246 246
             'default' => $fallback,
247
-        ]);
247
+        ] );
248 248
         return 'custom' != $setting['default']
249 249
             ? $setting['default']
250 250
             : $setting['custom'];
@@ -255,21 +255,21 @@  discard block
 block discarded – undo
255 255
      * @param string $fallback
256 256
      * @return void|string
257 257
      */
258
-    protected function getSchemaOptionValue($option, $fallback = 'post')
258
+    protected function getSchemaOptionValue( $option, $fallback = 'post' )
259 259
     {
260
-        if (array_key_exists($option, $this->keyValues)) {
260
+        if( array_key_exists( $option, $this->keyValues ) ) {
261 261
             return $this->keyValues[$option];
262 262
         }
263
-        $value = $this->getSchemaOption($option, $fallback);
264
-        if ($value != $fallback) {
265
-            return $this->setAndGetKeyValue($option, $value);
263
+        $value = $this->getSchemaOption( $option, $fallback );
264
+        if( $value != $fallback ) {
265
+            return $this->setAndGetKeyValue( $option, $value );
266 266
         }
267
-        if (!is_single() && !is_page()) {
267
+        if( !is_single() && !is_page() ) {
268 268
             return;
269 269
         }
270
-        $method = Helper::buildMethodName($option, 'getThing');
271
-        if (method_exists($this, $method)) {
272
-            return $this->setAndGetKeyValue($option, $this->$method());
270
+        $method = Helper::buildMethodName( $option, 'getThing' );
271
+        if( method_exists( $this, $method ) ) {
272
+            return $this->setAndGetKeyValue( $option, $this->$method() );
273 273
         }
274 274
     }
275 275
 
@@ -277,15 +277,15 @@  discard block
 block discarded – undo
277 277
      * @param string|null $type
278 278
      * @return mixed
279 279
      */
280
-    protected function getSchemaType($type = null)
280
+    protected function getSchemaType( $type = null )
281 281
     {
282
-        if (!is_string($type)) {
283
-            $type = $this->getSchemaOption('type', 'LocalBusiness');
282
+        if( !is_string( $type ) ) {
283
+            $type = $this->getSchemaOption( 'type', 'LocalBusiness' );
284 284
         }
285
-        $className = Helper::buildClassName($type, 'Modules\Schema');
286
-        return class_exists($className)
285
+        $className = Helper::buildClassName( $type, 'Modules\Schema' );
286
+        return class_exists( $className )
287 287
             ? new $className()
288
-            : new UnknownType($type);
288
+            : new UnknownType( $type );
289 289
     }
290 290
 
291 291
     /**
@@ -294,19 +294,19 @@  discard block
 block discarded – undo
294 294
     protected function getThingDescription()
295 295
     {
296 296
         $post = get_post();
297
-        $text = Arr::get($post, 'post_excerpt');
298
-        if (empty($text)) {
299
-            $text = Arr::get($post, 'post_content');
297
+        $text = Arr::get( $post, 'post_excerpt' );
298
+        if( empty($text) ) {
299
+            $text = Arr::get( $post, 'post_content' );
300 300
         }
301
-        if (function_exists('excerpt_remove_blocks')) {
302
-            $text = excerpt_remove_blocks($text);
301
+        if( function_exists( 'excerpt_remove_blocks' ) ) {
302
+            $text = excerpt_remove_blocks( $text );
303 303
         }
304
-        $text = strip_shortcodes($text);
305
-        $text = wpautop($text);
306
-        $text = wptexturize($text);
307
-        $text = wp_strip_all_tags($text);
308
-        $text = str_replace(']]>', ']]&gt;', $text);
309
-        return wp_trim_words($text, apply_filters('excerpt_length', 55));
304
+        $text = strip_shortcodes( $text );
305
+        $text = wpautop( $text );
306
+        $text = wptexturize( $text );
307
+        $text = wp_strip_all_tags( $text );
308
+        $text = str_replace( ']]>', ']]&gt;', $text );
309
+        return wp_trim_words( $text, apply_filters( 'excerpt_length', 55 ) );
310 310
     }
311 311
 
312 312
     /**
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
      */
315 315
     protected function getThingImage()
316 316
     {
317
-        return (string) get_the_post_thumbnail_url(null, 'large');
317
+        return (string)get_the_post_thumbnail_url( null, 'large' );
318 318
     }
319 319
 
320 320
     /**
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
      */
331 331
     protected function getThingUrl()
332 332
     {
333
-        return (string) get_the_permalink();
333
+        return (string)get_the_permalink();
334 334
     }
335 335
 
336 336
     /**
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
      * @param string $value
339 339
      * @return string
340 340
      */
341
-    protected function setAndGetKeyValue($option, $value)
341
+    protected function setAndGetKeyValue( $option, $value )
342 342
     {
343 343
         $this->keyValues[$option] = $value;
344 344
         return $value;
Please login to merge, or discard this patch.