Passed
Push — master ( 876108...8633df )
by Paul
06:37
created
plugin/Modules/Html/Builder.php 2 patches
Indentation   +342 added lines, -342 removed lines patch added patch discarded remove patch
@@ -18,346 +18,346 @@
 block discarded – undo
18 18
  */
19 19
 class Builder
20 20
 {
21
-    const INPUT_TYPES = [
22
-        'checkbox', 'date', 'datetime-local', 'email', 'file', 'hidden', 'image', 'month',
23
-        'number', 'password', 'radio', 'range', 'reset', 'search', 'submit', 'tel', 'text', 'time',
24
-        'url', 'week',
25
-    ];
26
-
27
-    const TAGS_FORM = [
28
-        'input', 'select', 'textarea',
29
-    ];
30
-
31
-    const TAGS_SINGLE = [
32
-        'img',
33
-    ];
34
-
35
-    const TAGS_STRUCTURE = [
36
-        'div', 'form', 'nav', 'ol', 'section', 'ul',
37
-    ];
38
-
39
-    const TAGS_TEXT = [
40
-        'a', 'button', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'i', 'label', 'li', 'option', 'p', 'pre',
41
-        'small', 'span',
42
-    ];
43
-
44
-    /**
45
-     * @var array
46
-     */
47
-    public $args = [];
48
-
49
-    /**
50
-     * @var bool
51
-     */
52
-    public $render = false;
53
-
54
-    /**
55
-     * @var string
56
-     */
57
-    public $tag;
58
-
59
-    /**
60
-     * @param string $method
61
-     * @param array $args
62
-     * @return string|void
63
-     */
64
-    public function __call($method, $args)
65
-    {
66
-        $instance = new static();
67
-        $instance->setTagFromMethod($method);
68
-        call_user_func_array([$instance, 'normalize'], $args += ['', '']);
69
-        $tags = array_merge(static::TAGS_FORM, static::TAGS_SINGLE, static::TAGS_STRUCTURE, static::TAGS_TEXT);
70
-        do_action_ref_array('site-reviews/builder', [$instance]);
71
-        $generatedTag = in_array($instance->tag, $tags)
72
-            ? $instance->buildTag()
73
-            : $instance->buildCustomField();
74
-        $generatedTag = apply_filters('site-reviews/builder/result', $generatedTag, $instance);
75
-        if (!$this->render) {
76
-            return $generatedTag;
77
-        }
78
-        echo $generatedTag;
79
-    }
80
-
81
-    /**
82
-     * @param string $property
83
-     * @param mixed $value
84
-     * @return void
85
-     */
86
-    public function __set($property, $value)
87
-    {
88
-        $properties = [
89
-            'args' => 'is_array',
90
-            'render' => 'is_bool',
91
-            'tag' => 'is_string',
92
-        ];
93
-        if (!isset($properties[$property])
94
-            || empty(array_filter([$value], $properties[$property]))
95
-        ) {
96
-            return;
97
-        }
98
-        $this->$property = $value;
99
-    }
100
-
101
-    /**
102
-     * @return void|string
103
-     */
104
-    public function getClosingTag()
105
-    {
106
-        if (empty($this->tag)) {
107
-            return;
108
-        }
109
-        return '</'.$this->tag.'>';
110
-    }
111
-
112
-    /**
113
-     * @return void|string
114
-     */
115
-    public function getOpeningTag()
116
-    {
117
-        if (empty($this->tag)) {
118
-            return;
119
-        }
120
-        $attributes = glsr(Attributes::class)->{$this->tag}($this->args)->toString();
121
-        return '<'.trim($this->tag.' '.$attributes).'>';
122
-    }
123
-
124
-    /**
125
-     * @return void|string
126
-     */
127
-    public function getTag()
128
-    {
129
-        if (in_array($this->tag, static::TAGS_SINGLE)) {
130
-            return $this->getOpeningTag();
131
-        }
132
-        if (!in_array($this->tag, static::TAGS_FORM)) {
133
-            return $this->buildDefaultTag();
134
-        }
135
-        return call_user_func([$this, 'buildForm'.ucfirst($this->tag)]).$this->buildFieldDescription();
136
-    }
137
-
138
-    /**
139
-     * @return string
140
-     */
141
-    public function raw(array $field)
142
-    {
143
-        unset($field['label']);
144
-        return $this->{$field['type']}($field);
145
-    }
146
-
147
-    /**
148
-     * @return string|void
149
-     */
150
-    protected function buildCustomField()
151
-    {
152
-        $className = $this->getCustomFieldClassName();
153
-        if (class_exists($className)) {
154
-            return (new $className($this))->build();
155
-        }
156
-        glsr_log()->error('Field missing: '.$className);
157
-    }
158
-
159
-    /**
160
-     * @return string|void
161
-     */
162
-    protected function buildDefaultTag($text = '')
163
-    {
164
-        if (empty($text)) {
165
-            $text = $this->args['text'];
166
-        }
167
-        return $this->getOpeningTag().$text.$this->getClosingTag();
168
-    }
169
-
170
-    /**
171
-     * @return string|void
172
-     */
173
-    protected function buildFieldDescription()
174
-    {
175
-        if (empty($this->args['description'])) {
176
-            return;
177
-        }
178
-        if ($this->args['is_widget']) {
179
-            return $this->small($this->args['description']);
180
-        }
181
-        return $this->p($this->args['description'], ['class' => 'description']);
182
-    }
183
-
184
-    /**
185
-     * @return string|void
186
-     */
187
-    protected function buildFormInput()
188
-    {
189
-        if (!in_array($this->args['type'], ['checkbox', 'radio'])) {
190
-            if (isset($this->args['multiple'])) {
191
-                $this->args['name'].= '[]';
192
-            }
193
-            return $this->buildFormLabel().$this->getOpeningTag();
194
-        }
195
-        return empty($this->args['options'])
196
-            ? $this->buildFormInputChoice()
197
-            : $this->buildFormInputMultiChoice();
198
-    }
199
-
200
-    /**
201
-     * @return string|void
202
-     */
203
-    protected function buildFormInputChoice()
204
-    {
205
-        if (!empty($this->args['text'])) {
206
-            $this->args['label'] = $this->args['text'];
207
-        }
208
-        if (!$this->args['is_public']) {
209
-            return $this->buildFormLabel([
210
-                'class' => 'glsr-'.$this->args['type'].'-label',
211
-                'text' => $this->getOpeningTag().' '.$this->args['label'].'<span></span>',
212
-            ]);
213
-        }
214
-        return $this->getOpeningTag().$this->buildFormLabel([
215
-            'class' => 'glsr-'.$this->args['type'].'-label',
216
-            'text' => $this->args['label'].'<span></span>',
217
-        ]);
218
-    }
219
-
220
-    /**
221
-     * @return string|void
222
-     */
223
-    protected function buildFormInputMultiChoice()
224
-    {
225
-        if ('checkbox' == $this->args['type']) {
226
-            $this->args['name'].= '[]';
227
-        }
228
-        $index = 0;
229
-        $options = array_reduce(array_keys($this->args['options']), function ($carry, $key) use (&$index) {
230
-            return $carry.$this->li($this->{$this->args['type']}([
231
-                'checked' => in_array($key, (array) $this->args['value']),
232
-                'id' => $this->args['id'].'-'.$index++,
233
-                'name' => $this->args['name'],
234
-                'text' => $this->args['options'][$key],
235
-                'value' => $key,
236
-            ]));
237
-        });
238
-        return $this->ul($options, [
239
-            'class' => $this->args['class'],
240
-            'id' => $this->args['id'],
241
-        ]);
242
-    }
243
-
244
-    /**
245
-     * @return void|string
246
-     */
247
-    protected function buildFormLabel(array $customArgs = [])
248
-    {
249
-        if (empty($this->args['label']) || 'hidden' == $this->args['type']) {
250
-            return;
251
-        }
252
-        return $this->label(wp_parse_args($customArgs, [
253
-            'for' => $this->args['id'],
254
-            'is_public' => $this->args['is_public'],
255
-            'text' => $this->args['label'],
256
-            'type' => $this->args['type'],
257
-        ]));
258
-    }
259
-
260
-    /**
261
-     * @return string|void
262
-     */
263
-    protected function buildFormSelect()
264
-    {
265
-        return $this->buildFormLabel().$this->buildDefaultTag($this->buildFormSelectOptions());
266
-    }
267
-
268
-    /**
269
-     * @return string|void
270
-     */
271
-    protected function buildFormSelectOptions()
272
-    {
273
-        return array_reduce(array_keys($this->args['options']), function ($carry, $key) {
274
-            return $carry.$this->option([
275
-                'selected' => $this->args['value'] === (string) $key,
276
-                'text' => $this->args['options'][$key],
277
-                'value' => $key,
278
-            ]);
279
-        });
280
-    }
281
-
282
-    /**
283
-     * @return string|void
284
-     */
285
-    protected function buildFormTextarea()
286
-    {
287
-        return $this->buildFormLabel().$this->buildDefaultTag($this->args['value']);
288
-    }
289
-
290
-    /**
291
-     * @return string|void
292
-     */
293
-    protected function buildTag()
294
-    {
295
-        $this->mergeArgsWithRequiredDefaults();
296
-        return $this->getTag();
297
-    }
298
-
299
-    /**
300
-     * @return string
301
-     */
302
-    protected function getCustomFieldClassName()
303
-    {
304
-        $classname = Helper::buildClassName($this->tag, __NAMESPACE__.'\Fields');
305
-        return apply_filters('site-reviews/builder/field/'.$this->tag, $classname);
306
-    }
307
-
308
-    /**
309
-     * @return void
310
-     */
311
-    protected function mergeArgsWithRequiredDefaults()
312
-    {
313
-        $className = $this->getCustomFieldClassName();
314
-        if (class_exists($className)) {
315
-            $this->args = $className::merge($this->args);
316
-        }
317
-        $this->args = glsr(BuilderDefaults::class)->merge($this->args);
318
-    }
319
-
320
-    /**
321
-     * @param string|array ...$params
322
-     * @return void
323
-     */
324
-    protected function normalize(...$params)
325
-    {
326
-        if (is_string($params[0]) || is_numeric($params[0])) {
327
-            $this->setNameOrTextAttributeForTag($params[0]);
328
-        }
329
-        if (is_array($params[0])) {
330
-            $this->args += $params[0];
331
-        } elseif (is_array($params[1])) {
332
-            $this->args += $params[1];
333
-        }
334
-        if (!isset($this->args['is_public'])) {
335
-            $this->args['is_public'] = false;
336
-        }
337
-    }
338
-
339
-    /**
340
-     * @param string $value
341
-     * @return void
342
-     */
343
-    protected function setNameOrTextAttributeForTag($value)
344
-    {
345
-        $attribute = in_array($this->tag, static::TAGS_FORM)
346
-            ? 'name'
347
-            : 'text';
348
-        $this->args[$attribute] = $value;
349
-    }
350
-
351
-    /**
352
-     * @param string $method
353
-     * @return void
354
-     */
355
-    protected function setTagFromMethod($method)
356
-    {
357
-        $this->tag = strtolower($method);
358
-        if (in_array($this->tag, static::INPUT_TYPES)) {
359
-            $this->args['type'] = $this->tag;
360
-            $this->tag = 'input';
361
-        }
362
-    }
21
+	const INPUT_TYPES = [
22
+		'checkbox', 'date', 'datetime-local', 'email', 'file', 'hidden', 'image', 'month',
23
+		'number', 'password', 'radio', 'range', 'reset', 'search', 'submit', 'tel', 'text', 'time',
24
+		'url', 'week',
25
+	];
26
+
27
+	const TAGS_FORM = [
28
+		'input', 'select', 'textarea',
29
+	];
30
+
31
+	const TAGS_SINGLE = [
32
+		'img',
33
+	];
34
+
35
+	const TAGS_STRUCTURE = [
36
+		'div', 'form', 'nav', 'ol', 'section', 'ul',
37
+	];
38
+
39
+	const TAGS_TEXT = [
40
+		'a', 'button', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'i', 'label', 'li', 'option', 'p', 'pre',
41
+		'small', 'span',
42
+	];
43
+
44
+	/**
45
+	 * @var array
46
+	 */
47
+	public $args = [];
48
+
49
+	/**
50
+	 * @var bool
51
+	 */
52
+	public $render = false;
53
+
54
+	/**
55
+	 * @var string
56
+	 */
57
+	public $tag;
58
+
59
+	/**
60
+	 * @param string $method
61
+	 * @param array $args
62
+	 * @return string|void
63
+	 */
64
+	public function __call($method, $args)
65
+	{
66
+		$instance = new static();
67
+		$instance->setTagFromMethod($method);
68
+		call_user_func_array([$instance, 'normalize'], $args += ['', '']);
69
+		$tags = array_merge(static::TAGS_FORM, static::TAGS_SINGLE, static::TAGS_STRUCTURE, static::TAGS_TEXT);
70
+		do_action_ref_array('site-reviews/builder', [$instance]);
71
+		$generatedTag = in_array($instance->tag, $tags)
72
+			? $instance->buildTag()
73
+			: $instance->buildCustomField();
74
+		$generatedTag = apply_filters('site-reviews/builder/result', $generatedTag, $instance);
75
+		if (!$this->render) {
76
+			return $generatedTag;
77
+		}
78
+		echo $generatedTag;
79
+	}
80
+
81
+	/**
82
+	 * @param string $property
83
+	 * @param mixed $value
84
+	 * @return void
85
+	 */
86
+	public function __set($property, $value)
87
+	{
88
+		$properties = [
89
+			'args' => 'is_array',
90
+			'render' => 'is_bool',
91
+			'tag' => 'is_string',
92
+		];
93
+		if (!isset($properties[$property])
94
+			|| empty(array_filter([$value], $properties[$property]))
95
+		) {
96
+			return;
97
+		}
98
+		$this->$property = $value;
99
+	}
100
+
101
+	/**
102
+	 * @return void|string
103
+	 */
104
+	public function getClosingTag()
105
+	{
106
+		if (empty($this->tag)) {
107
+			return;
108
+		}
109
+		return '</'.$this->tag.'>';
110
+	}
111
+
112
+	/**
113
+	 * @return void|string
114
+	 */
115
+	public function getOpeningTag()
116
+	{
117
+		if (empty($this->tag)) {
118
+			return;
119
+		}
120
+		$attributes = glsr(Attributes::class)->{$this->tag}($this->args)->toString();
121
+		return '<'.trim($this->tag.' '.$attributes).'>';
122
+	}
123
+
124
+	/**
125
+	 * @return void|string
126
+	 */
127
+	public function getTag()
128
+	{
129
+		if (in_array($this->tag, static::TAGS_SINGLE)) {
130
+			return $this->getOpeningTag();
131
+		}
132
+		if (!in_array($this->tag, static::TAGS_FORM)) {
133
+			return $this->buildDefaultTag();
134
+		}
135
+		return call_user_func([$this, 'buildForm'.ucfirst($this->tag)]).$this->buildFieldDescription();
136
+	}
137
+
138
+	/**
139
+	 * @return string
140
+	 */
141
+	public function raw(array $field)
142
+	{
143
+		unset($field['label']);
144
+		return $this->{$field['type']}($field);
145
+	}
146
+
147
+	/**
148
+	 * @return string|void
149
+	 */
150
+	protected function buildCustomField()
151
+	{
152
+		$className = $this->getCustomFieldClassName();
153
+		if (class_exists($className)) {
154
+			return (new $className($this))->build();
155
+		}
156
+		glsr_log()->error('Field missing: '.$className);
157
+	}
158
+
159
+	/**
160
+	 * @return string|void
161
+	 */
162
+	protected function buildDefaultTag($text = '')
163
+	{
164
+		if (empty($text)) {
165
+			$text = $this->args['text'];
166
+		}
167
+		return $this->getOpeningTag().$text.$this->getClosingTag();
168
+	}
169
+
170
+	/**
171
+	 * @return string|void
172
+	 */
173
+	protected function buildFieldDescription()
174
+	{
175
+		if (empty($this->args['description'])) {
176
+			return;
177
+		}
178
+		if ($this->args['is_widget']) {
179
+			return $this->small($this->args['description']);
180
+		}
181
+		return $this->p($this->args['description'], ['class' => 'description']);
182
+	}
183
+
184
+	/**
185
+	 * @return string|void
186
+	 */
187
+	protected function buildFormInput()
188
+	{
189
+		if (!in_array($this->args['type'], ['checkbox', 'radio'])) {
190
+			if (isset($this->args['multiple'])) {
191
+				$this->args['name'].= '[]';
192
+			}
193
+			return $this->buildFormLabel().$this->getOpeningTag();
194
+		}
195
+		return empty($this->args['options'])
196
+			? $this->buildFormInputChoice()
197
+			: $this->buildFormInputMultiChoice();
198
+	}
199
+
200
+	/**
201
+	 * @return string|void
202
+	 */
203
+	protected function buildFormInputChoice()
204
+	{
205
+		if (!empty($this->args['text'])) {
206
+			$this->args['label'] = $this->args['text'];
207
+		}
208
+		if (!$this->args['is_public']) {
209
+			return $this->buildFormLabel([
210
+				'class' => 'glsr-'.$this->args['type'].'-label',
211
+				'text' => $this->getOpeningTag().' '.$this->args['label'].'<span></span>',
212
+			]);
213
+		}
214
+		return $this->getOpeningTag().$this->buildFormLabel([
215
+			'class' => 'glsr-'.$this->args['type'].'-label',
216
+			'text' => $this->args['label'].'<span></span>',
217
+		]);
218
+	}
219
+
220
+	/**
221
+	 * @return string|void
222
+	 */
223
+	protected function buildFormInputMultiChoice()
224
+	{
225
+		if ('checkbox' == $this->args['type']) {
226
+			$this->args['name'].= '[]';
227
+		}
228
+		$index = 0;
229
+		$options = array_reduce(array_keys($this->args['options']), function ($carry, $key) use (&$index) {
230
+			return $carry.$this->li($this->{$this->args['type']}([
231
+				'checked' => in_array($key, (array) $this->args['value']),
232
+				'id' => $this->args['id'].'-'.$index++,
233
+				'name' => $this->args['name'],
234
+				'text' => $this->args['options'][$key],
235
+				'value' => $key,
236
+			]));
237
+		});
238
+		return $this->ul($options, [
239
+			'class' => $this->args['class'],
240
+			'id' => $this->args['id'],
241
+		]);
242
+	}
243
+
244
+	/**
245
+	 * @return void|string
246
+	 */
247
+	protected function buildFormLabel(array $customArgs = [])
248
+	{
249
+		if (empty($this->args['label']) || 'hidden' == $this->args['type']) {
250
+			return;
251
+		}
252
+		return $this->label(wp_parse_args($customArgs, [
253
+			'for' => $this->args['id'],
254
+			'is_public' => $this->args['is_public'],
255
+			'text' => $this->args['label'],
256
+			'type' => $this->args['type'],
257
+		]));
258
+	}
259
+
260
+	/**
261
+	 * @return string|void
262
+	 */
263
+	protected function buildFormSelect()
264
+	{
265
+		return $this->buildFormLabel().$this->buildDefaultTag($this->buildFormSelectOptions());
266
+	}
267
+
268
+	/**
269
+	 * @return string|void
270
+	 */
271
+	protected function buildFormSelectOptions()
272
+	{
273
+		return array_reduce(array_keys($this->args['options']), function ($carry, $key) {
274
+			return $carry.$this->option([
275
+				'selected' => $this->args['value'] === (string) $key,
276
+				'text' => $this->args['options'][$key],
277
+				'value' => $key,
278
+			]);
279
+		});
280
+	}
281
+
282
+	/**
283
+	 * @return string|void
284
+	 */
285
+	protected function buildFormTextarea()
286
+	{
287
+		return $this->buildFormLabel().$this->buildDefaultTag($this->args['value']);
288
+	}
289
+
290
+	/**
291
+	 * @return string|void
292
+	 */
293
+	protected function buildTag()
294
+	{
295
+		$this->mergeArgsWithRequiredDefaults();
296
+		return $this->getTag();
297
+	}
298
+
299
+	/**
300
+	 * @return string
301
+	 */
302
+	protected function getCustomFieldClassName()
303
+	{
304
+		$classname = Helper::buildClassName($this->tag, __NAMESPACE__.'\Fields');
305
+		return apply_filters('site-reviews/builder/field/'.$this->tag, $classname);
306
+	}
307
+
308
+	/**
309
+	 * @return void
310
+	 */
311
+	protected function mergeArgsWithRequiredDefaults()
312
+	{
313
+		$className = $this->getCustomFieldClassName();
314
+		if (class_exists($className)) {
315
+			$this->args = $className::merge($this->args);
316
+		}
317
+		$this->args = glsr(BuilderDefaults::class)->merge($this->args);
318
+	}
319
+
320
+	/**
321
+	 * @param string|array ...$params
322
+	 * @return void
323
+	 */
324
+	protected function normalize(...$params)
325
+	{
326
+		if (is_string($params[0]) || is_numeric($params[0])) {
327
+			$this->setNameOrTextAttributeForTag($params[0]);
328
+		}
329
+		if (is_array($params[0])) {
330
+			$this->args += $params[0];
331
+		} elseif (is_array($params[1])) {
332
+			$this->args += $params[1];
333
+		}
334
+		if (!isset($this->args['is_public'])) {
335
+			$this->args['is_public'] = false;
336
+		}
337
+	}
338
+
339
+	/**
340
+	 * @param string $value
341
+	 * @return void
342
+	 */
343
+	protected function setNameOrTextAttributeForTag($value)
344
+	{
345
+		$attribute = in_array($this->tag, static::TAGS_FORM)
346
+			? 'name'
347
+			: 'text';
348
+		$this->args[$attribute] = $value;
349
+	}
350
+
351
+	/**
352
+	 * @param string $method
353
+	 * @return void
354
+	 */
355
+	protected function setTagFromMethod($method)
356
+	{
357
+		$this->tag = strtolower($method);
358
+		if (in_array($this->tag, static::INPUT_TYPES)) {
359
+			$this->args['type'] = $this->tag;
360
+			$this->tag = 'input';
361
+		}
362
+	}
363 363
 }
Please login to merge, or discard this patch.
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -61,18 +61,18 @@  discard block
 block discarded – undo
61 61
      * @param array $args
62 62
      * @return string|void
63 63
      */
64
-    public function __call($method, $args)
64
+    public function __call( $method, $args )
65 65
     {
66 66
         $instance = new static();
67
-        $instance->setTagFromMethod($method);
68
-        call_user_func_array([$instance, 'normalize'], $args += ['', '']);
69
-        $tags = array_merge(static::TAGS_FORM, static::TAGS_SINGLE, static::TAGS_STRUCTURE, static::TAGS_TEXT);
70
-        do_action_ref_array('site-reviews/builder', [$instance]);
71
-        $generatedTag = in_array($instance->tag, $tags)
67
+        $instance->setTagFromMethod( $method );
68
+        call_user_func_array( [$instance, 'normalize'], $args += ['', ''] );
69
+        $tags = array_merge( static::TAGS_FORM, static::TAGS_SINGLE, static::TAGS_STRUCTURE, static::TAGS_TEXT );
70
+        do_action_ref_array( 'site-reviews/builder', [$instance] );
71
+        $generatedTag = in_array( $instance->tag, $tags )
72 72
             ? $instance->buildTag()
73 73
             : $instance->buildCustomField();
74
-        $generatedTag = apply_filters('site-reviews/builder/result', $generatedTag, $instance);
75
-        if (!$this->render) {
74
+        $generatedTag = apply_filters( 'site-reviews/builder/result', $generatedTag, $instance );
75
+        if( !$this->render ) {
76 76
             return $generatedTag;
77 77
         }
78 78
         echo $generatedTag;
@@ -83,15 +83,15 @@  discard block
 block discarded – undo
83 83
      * @param mixed $value
84 84
      * @return void
85 85
      */
86
-    public function __set($property, $value)
86
+    public function __set( $property, $value )
87 87
     {
88 88
         $properties = [
89 89
             'args' => 'is_array',
90 90
             'render' => 'is_bool',
91 91
             'tag' => 'is_string',
92 92
         ];
93
-        if (!isset($properties[$property])
94
-            || empty(array_filter([$value], $properties[$property]))
93
+        if( !isset($properties[$property])
94
+            || empty(array_filter( [$value], $properties[$property] ))
95 95
         ) {
96 96
             return;
97 97
         }
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
      */
104 104
     public function getClosingTag()
105 105
     {
106
-        if (empty($this->tag)) {
106
+        if( empty($this->tag) ) {
107 107
             return;
108 108
         }
109 109
         return '</'.$this->tag.'>';
@@ -114,11 +114,11 @@  discard block
 block discarded – undo
114 114
      */
115 115
     public function getOpeningTag()
116 116
     {
117
-        if (empty($this->tag)) {
117
+        if( empty($this->tag) ) {
118 118
             return;
119 119
         }
120
-        $attributes = glsr(Attributes::class)->{$this->tag}($this->args)->toString();
121
-        return '<'.trim($this->tag.' '.$attributes).'>';
120
+        $attributes = glsr( Attributes::class )->{$this->tag}($this->args)->toString();
121
+        return '<'.trim( $this->tag.' '.$attributes ).'>';
122 122
     }
123 123
 
124 124
     /**
@@ -126,19 +126,19 @@  discard block
 block discarded – undo
126 126
      */
127 127
     public function getTag()
128 128
     {
129
-        if (in_array($this->tag, static::TAGS_SINGLE)) {
129
+        if( in_array( $this->tag, static::TAGS_SINGLE ) ) {
130 130
             return $this->getOpeningTag();
131 131
         }
132
-        if (!in_array($this->tag, static::TAGS_FORM)) {
132
+        if( !in_array( $this->tag, static::TAGS_FORM ) ) {
133 133
             return $this->buildDefaultTag();
134 134
         }
135
-        return call_user_func([$this, 'buildForm'.ucfirst($this->tag)]).$this->buildFieldDescription();
135
+        return call_user_func( [$this, 'buildForm'.ucfirst( $this->tag )] ).$this->buildFieldDescription();
136 136
     }
137 137
 
138 138
     /**
139 139
      * @return string
140 140
      */
141
-    public function raw(array $field)
141
+    public function raw( array $field )
142 142
     {
143 143
         unset($field['label']);
144 144
         return $this->{$field['type']}($field);
@@ -150,18 +150,18 @@  discard block
 block discarded – undo
150 150
     protected function buildCustomField()
151 151
     {
152 152
         $className = $this->getCustomFieldClassName();
153
-        if (class_exists($className)) {
154
-            return (new $className($this))->build();
153
+        if( class_exists( $className ) ) {
154
+            return (new $className( $this ))->build();
155 155
         }
156
-        glsr_log()->error('Field missing: '.$className);
156
+        glsr_log()->error( 'Field missing: '.$className );
157 157
     }
158 158
 
159 159
     /**
160 160
      * @return string|void
161 161
      */
162
-    protected function buildDefaultTag($text = '')
162
+    protected function buildDefaultTag( $text = '' )
163 163
     {
164
-        if (empty($text)) {
164
+        if( empty($text) ) {
165 165
             $text = $this->args['text'];
166 166
         }
167 167
         return $this->getOpeningTag().$text.$this->getClosingTag();
@@ -172,13 +172,13 @@  discard block
 block discarded – undo
172 172
      */
173 173
     protected function buildFieldDescription()
174 174
     {
175
-        if (empty($this->args['description'])) {
175
+        if( empty($this->args['description']) ) {
176 176
             return;
177 177
         }
178
-        if ($this->args['is_widget']) {
179
-            return $this->small($this->args['description']);
178
+        if( $this->args['is_widget'] ) {
179
+            return $this->small( $this->args['description'] );
180 180
         }
181
-        return $this->p($this->args['description'], ['class' => 'description']);
181
+        return $this->p( $this->args['description'], ['class' => 'description'] );
182 182
     }
183 183
 
184 184
     /**
@@ -186,9 +186,9 @@  discard block
 block discarded – undo
186 186
      */
187 187
     protected function buildFormInput()
188 188
     {
189
-        if (!in_array($this->args['type'], ['checkbox', 'radio'])) {
190
-            if (isset($this->args['multiple'])) {
191
-                $this->args['name'].= '[]';
189
+        if( !in_array( $this->args['type'], ['checkbox', 'radio'] ) ) {
190
+            if( isset($this->args['multiple']) ) {
191
+                $this->args['name'] .= '[]';
192 192
             }
193 193
             return $this->buildFormLabel().$this->getOpeningTag();
194 194
         }
@@ -202,19 +202,19 @@  discard block
 block discarded – undo
202 202
      */
203 203
     protected function buildFormInputChoice()
204 204
     {
205
-        if (!empty($this->args['text'])) {
205
+        if( !empty($this->args['text']) ) {
206 206
             $this->args['label'] = $this->args['text'];
207 207
         }
208
-        if (!$this->args['is_public']) {
209
-            return $this->buildFormLabel([
208
+        if( !$this->args['is_public'] ) {
209
+            return $this->buildFormLabel( [
210 210
                 'class' => 'glsr-'.$this->args['type'].'-label',
211 211
                 'text' => $this->getOpeningTag().' '.$this->args['label'].'<span></span>',
212
-            ]);
212
+            ] );
213 213
         }
214
-        return $this->getOpeningTag().$this->buildFormLabel([
214
+        return $this->getOpeningTag().$this->buildFormLabel( [
215 215
             'class' => 'glsr-'.$this->args['type'].'-label',
216 216
             'text' => $this->args['label'].'<span></span>',
217
-        ]);
217
+        ] );
218 218
     }
219 219
 
220 220
     /**
@@ -222,39 +222,39 @@  discard block
 block discarded – undo
222 222
      */
223 223
     protected function buildFormInputMultiChoice()
224 224
     {
225
-        if ('checkbox' == $this->args['type']) {
226
-            $this->args['name'].= '[]';
225
+        if( 'checkbox' == $this->args['type'] ) {
226
+            $this->args['name'] .= '[]';
227 227
         }
228 228
         $index = 0;
229
-        $options = array_reduce(array_keys($this->args['options']), function ($carry, $key) use (&$index) {
230
-            return $carry.$this->li($this->{$this->args['type']}([
231
-                'checked' => in_array($key, (array) $this->args['value']),
229
+        $options = array_reduce( array_keys( $this->args['options'] ), function( $carry, $key ) use (&$index) {
230
+            return $carry.$this->li( $this->{$this->args['type']}([
231
+                'checked' => in_array( $key, (array)$this->args['value'] ),
232 232
                 'id' => $this->args['id'].'-'.$index++,
233 233
                 'name' => $this->args['name'],
234 234
                 'text' => $this->args['options'][$key],
235 235
                 'value' => $key,
236
-            ]));
236
+            ]) );
237 237
         });
238
-        return $this->ul($options, [
238
+        return $this->ul( $options, [
239 239
             'class' => $this->args['class'],
240 240
             'id' => $this->args['id'],
241
-        ]);
241
+        ] );
242 242
     }
243 243
 
244 244
     /**
245 245
      * @return void|string
246 246
      */
247
-    protected function buildFormLabel(array $customArgs = [])
247
+    protected function buildFormLabel( array $customArgs = [] )
248 248
     {
249
-        if (empty($this->args['label']) || 'hidden' == $this->args['type']) {
249
+        if( empty($this->args['label']) || 'hidden' == $this->args['type'] ) {
250 250
             return;
251 251
         }
252
-        return $this->label(wp_parse_args($customArgs, [
252
+        return $this->label( wp_parse_args( $customArgs, [
253 253
             'for' => $this->args['id'],
254 254
             'is_public' => $this->args['is_public'],
255 255
             'text' => $this->args['label'],
256 256
             'type' => $this->args['type'],
257
-        ]));
257
+        ] ) );
258 258
     }
259 259
 
260 260
     /**
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
      */
263 263
     protected function buildFormSelect()
264 264
     {
265
-        return $this->buildFormLabel().$this->buildDefaultTag($this->buildFormSelectOptions());
265
+        return $this->buildFormLabel().$this->buildDefaultTag( $this->buildFormSelectOptions() );
266 266
     }
267 267
 
268 268
     /**
@@ -270,12 +270,12 @@  discard block
 block discarded – undo
270 270
      */
271 271
     protected function buildFormSelectOptions()
272 272
     {
273
-        return array_reduce(array_keys($this->args['options']), function ($carry, $key) {
274
-            return $carry.$this->option([
275
-                'selected' => $this->args['value'] === (string) $key,
273
+        return array_reduce( array_keys( $this->args['options'] ), function( $carry, $key ) {
274
+            return $carry.$this->option( [
275
+                'selected' => $this->args['value'] === (string)$key,
276 276
                 'text' => $this->args['options'][$key],
277 277
                 'value' => $key,
278
-            ]);
278
+            ] );
279 279
         });
280 280
     }
281 281
 
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
      */
285 285
     protected function buildFormTextarea()
286 286
     {
287
-        return $this->buildFormLabel().$this->buildDefaultTag($this->args['value']);
287
+        return $this->buildFormLabel().$this->buildDefaultTag( $this->args['value'] );
288 288
     }
289 289
 
290 290
     /**
@@ -301,8 +301,8 @@  discard block
 block discarded – undo
301 301
      */
302 302
     protected function getCustomFieldClassName()
303 303
     {
304
-        $classname = Helper::buildClassName($this->tag, __NAMESPACE__.'\Fields');
305
-        return apply_filters('site-reviews/builder/field/'.$this->tag, $classname);
304
+        $classname = Helper::buildClassName( $this->tag, __NAMESPACE__.'\Fields' );
305
+        return apply_filters( 'site-reviews/builder/field/'.$this->tag, $classname );
306 306
     }
307 307
 
308 308
     /**
@@ -311,27 +311,27 @@  discard block
 block discarded – undo
311 311
     protected function mergeArgsWithRequiredDefaults()
312 312
     {
313 313
         $className = $this->getCustomFieldClassName();
314
-        if (class_exists($className)) {
315
-            $this->args = $className::merge($this->args);
314
+        if( class_exists( $className ) ) {
315
+            $this->args = $className::merge( $this->args );
316 316
         }
317
-        $this->args = glsr(BuilderDefaults::class)->merge($this->args);
317
+        $this->args = glsr( BuilderDefaults::class )->merge( $this->args );
318 318
     }
319 319
 
320 320
     /**
321 321
      * @param string|array ...$params
322 322
      * @return void
323 323
      */
324
-    protected function normalize(...$params)
324
+    protected function normalize( ...$params )
325 325
     {
326
-        if (is_string($params[0]) || is_numeric($params[0])) {
327
-            $this->setNameOrTextAttributeForTag($params[0]);
326
+        if( is_string( $params[0] ) || is_numeric( $params[0] ) ) {
327
+            $this->setNameOrTextAttributeForTag( $params[0] );
328 328
         }
329
-        if (is_array($params[0])) {
329
+        if( is_array( $params[0] ) ) {
330 330
             $this->args += $params[0];
331
-        } elseif (is_array($params[1])) {
331
+        } elseif( is_array( $params[1] ) ) {
332 332
             $this->args += $params[1];
333 333
         }
334
-        if (!isset($this->args['is_public'])) {
334
+        if( !isset($this->args['is_public']) ) {
335 335
             $this->args['is_public'] = false;
336 336
         }
337 337
     }
@@ -340,9 +340,9 @@  discard block
 block discarded – undo
340 340
      * @param string $value
341 341
      * @return void
342 342
      */
343
-    protected function setNameOrTextAttributeForTag($value)
343
+    protected function setNameOrTextAttributeForTag( $value )
344 344
     {
345
-        $attribute = in_array($this->tag, static::TAGS_FORM)
345
+        $attribute = in_array( $this->tag, static::TAGS_FORM )
346 346
             ? 'name'
347 347
             : 'text';
348 348
         $this->args[$attribute] = $value;
@@ -352,10 +352,10 @@  discard block
 block discarded – undo
352 352
      * @param string $method
353 353
      * @return void
354 354
      */
355
-    protected function setTagFromMethod($method)
355
+    protected function setTagFromMethod( $method )
356 356
     {
357
-        $this->tag = strtolower($method);
358
-        if (in_array($this->tag, static::INPUT_TYPES)) {
357
+        $this->tag = strtolower( $method );
358
+        if( in_array( $this->tag, static::INPUT_TYPES ) ) {
359 359
             $this->args['type'] = $this->tag;
360 360
             $this->tag = 'input';
361 361
         }
Please login to merge, or discard this patch.
plugin/Database/SqlQueries.php 2 patches
Indentation   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -8,23 +8,23 @@  discard block
 block discarded – undo
8 8
 
9 9
 class SqlQueries
10 10
 {
11
-    protected $db;
12
-    protected $postType;
11
+	protected $db;
12
+	protected $postType;
13 13
 
14
-    public function __construct()
15
-    {
16
-        global $wpdb;
17
-        $this->db = $wpdb;
18
-        $this->postType = Application::POST_TYPE;
19
-    }
14
+	public function __construct()
15
+	{
16
+		global $wpdb;
17
+		$this->db = $wpdb;
18
+		$this->postType = Application::POST_TYPE;
19
+	}
20 20
 
21
-    /**
22
-     * @param string $metaReviewId
23
-     * @return int
24
-     */
25
-    public function getPostIdFromReviewId($metaReviewId)
26
-    {
27
-        $postId = $this->db->get_var("
21
+	/**
22
+	 * @param string $metaReviewId
23
+	 * @return int
24
+	 */
25
+	public function getPostIdFromReviewId($metaReviewId)
26
+	{
27
+		$postId = $this->db->get_var("
28 28
             SELECT p.ID
29 29
             FROM {$this->db->posts} AS p
30 30
             INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id
@@ -32,17 +32,17 @@  discard block
 block discarded – undo
32 32
             AND m.meta_key = '_review_id'
33 33
             AND m.meta_value = '{$metaReviewId}'
34 34
         ");
35
-        return intval($postId);
36
-    }
35
+		return intval($postId);
36
+	}
37 37
 
38
-    /**
39
-     * @param int $lastPostId
40
-     * @param int $limit
41
-     * @return array
42
-     */
43
-    public function getReviewCounts(array $args, $lastPostId = 0, $limit = 500)
44
-    {
45
-        return (array) $this->db->get_results("
38
+	/**
39
+	 * @param int $lastPostId
40
+	 * @param int $limit
41
+	 * @return array
42
+	 */
43
+	public function getReviewCounts(array $args, $lastPostId = 0, $limit = 500)
44
+	{
45
+		return (array) $this->db->get_results("
46 46
             SELECT DISTINCT p.ID, m1.meta_value AS rating, m2.meta_value AS type
47 47
             FROM {$this->db->posts} AS p
48 48
             INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id
@@ -57,17 +57,17 @@  discard block
 block discarded – undo
57 57
             ORDER By p.ID ASC
58 58
             LIMIT {$limit}
59 59
         ");
60
-    }
60
+	}
61 61
 
62
-    /**
63
-     * @todo remove this?
64
-     * @param string $metaKey
65
-     * @return array
66
-     */
67
-    public function getReviewCountsFor($metaKey)
68
-    {
69
-        $metaKey = Str::prefix('_', $metaKey);
70
-        return (array) $this->db->get_results("
62
+	/**
63
+	 * @todo remove this?
64
+	 * @param string $metaKey
65
+	 * @return array
66
+	 */
67
+	public function getReviewCountsFor($metaKey)
68
+	{
69
+		$metaKey = Str::prefix('_', $metaKey);
70
+		return (array) $this->db->get_results("
71 71
             SELECT DISTINCT m.meta_value AS name, COUNT(*) num_posts
72 72
             FROM {$this->db->posts} AS p
73 73
             INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id
@@ -75,16 +75,16 @@  discard block
 block discarded – undo
75 75
             AND m.meta_key = '{$metaKey}'
76 76
             GROUP BY name
77 77
         ");
78
-    }
78
+	}
79 79
 
80
-    /**
81
-     * @todo remove this?
82
-     * @param string $reviewType
83
-     * @return array
84
-     */
85
-    public function getReviewIdsByType($reviewType)
86
-    {
87
-        $results = $this->db->get_col("
80
+	/**
81
+	 * @todo remove this?
82
+	 * @param string $reviewType
83
+	 * @return array
84
+	 */
85
+	public function getReviewIdsByType($reviewType)
86
+	{
87
+		$results = $this->db->get_col("
88 88
             SELECT DISTINCT m1.meta_value AS review_id
89 89
             FROM {$this->db->posts} AS p
90 90
             INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id
@@ -94,20 +94,20 @@  discard block
 block discarded – undo
94 94
             AND m2.meta_key = '_review_type'
95 95
             AND m2.meta_value = '{$reviewType}'
96 96
         ");
97
-        return array_keys(array_flip($results));
98
-    }
97
+		return array_keys(array_flip($results));
98
+	}
99 99
 
100
-    /**
101
-     * @param int $greaterThanId
102
-     * @param int $limit
103
-     * @return array
104
-     */
105
-    public function getReviewRatingsFromIds(array $postIds, $greaterThanId = 0, $limit = 100)
106
-    {
107
-        sort($postIds);
108
-        $postIds = array_slice($postIds, intval(array_search($greaterThanId, $postIds)), $limit);
109
-        $postIds = implode(',', $postIds);
110
-        return (array) $this->db->get_results("
100
+	/**
101
+	 * @param int $greaterThanId
102
+	 * @param int $limit
103
+	 * @return array
104
+	 */
105
+	public function getReviewRatingsFromIds(array $postIds, $greaterThanId = 0, $limit = 100)
106
+	{
107
+		sort($postIds);
108
+		$postIds = array_slice($postIds, intval(array_search($greaterThanId, $postIds)), $limit);
109
+		$postIds = implode(',', $postIds);
110
+		return (array) $this->db->get_results("
111 111
             SELECT p.ID, m.meta_value AS rating
112 112
             FROM {$this->db->posts} AS p
113 113
             INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id
@@ -120,20 +120,20 @@  discard block
 block discarded – undo
120 120
             ORDER By p.ID ASC
121 121
             LIMIT {$limit}
122 122
         ");
123
-    }
123
+	}
124 124
 
125
-    /**
126
-     * @param string $key
127
-     * @param string $status
128
-     * @return array
129
-     */
130
-    public function getReviewsMeta($key, $status = 'publish')
131
-    {
132
-        $postStatusQuery = 'all' != $status && !empty($status)
133
-            ? "AND p.post_status = '{$status}'"
134
-            : '';
135
-        $key = Str::prefix('_', $key);
136
-        $values = $this->db->get_col("
125
+	/**
126
+	 * @param string $key
127
+	 * @param string $status
128
+	 * @return array
129
+	 */
130
+	public function getReviewsMeta($key, $status = 'publish')
131
+	{
132
+		$postStatusQuery = 'all' != $status && !empty($status)
133
+			? "AND p.post_status = '{$status}'"
134
+			: '';
135
+		$key = Str::prefix('_', $key);
136
+		$values = $this->db->get_col("
137 137
             SELECT DISTINCT m.meta_value
138 138
             FROM {$this->db->postmeta} m
139 139
             LEFT JOIN {$this->db->posts} p ON p.ID = m.post_id
@@ -144,42 +144,42 @@  discard block
 block discarded – undo
144 144
             GROUP BY p.ID -- remove duplicate meta_value entries
145 145
             ORDER BY m.meta_id ASC -- sort by oldest meta_value
146 146
         ");
147
-        sort($values);
148
-        return $values;
149
-    }
147
+		sort($values);
148
+		return $values;
149
+	}
150 150
 
151
-    /**
152
-     * @param string $and
153
-     * @return string
154
-     */
155
-    protected function getAndForCounts(array $args, $and = '')
156
-    {
157
-        $postIds = implode(',', array_filter(Arr::get($args, 'post_ids', [])));
158
-        $termIds = implode(',', array_filter(Arr::get($args, 'term_ids', [])));
159
-        if (!empty($args['type'])) {
160
-            $and.= "AND m2.meta_value = '{$args['type']}' ";
161
-        }
162
-        if ($postIds) {
163
-            $and.= "AND m3.meta_key = '_assigned_to' AND m3.meta_value IN ({$postIds}) ";
164
-        }
165
-        if ($termIds) {
166
-            $and.= "AND tr.term_taxonomy_id IN ({$termIds}) ";
167
-        }
168
-        return apply_filters('site-reviews/query/and-for-counts', $and);
169
-    }
151
+	/**
152
+	 * @param string $and
153
+	 * @return string
154
+	 */
155
+	protected function getAndForCounts(array $args, $and = '')
156
+	{
157
+		$postIds = implode(',', array_filter(Arr::get($args, 'post_ids', [])));
158
+		$termIds = implode(',', array_filter(Arr::get($args, 'term_ids', [])));
159
+		if (!empty($args['type'])) {
160
+			$and.= "AND m2.meta_value = '{$args['type']}' ";
161
+		}
162
+		if ($postIds) {
163
+			$and.= "AND m3.meta_key = '_assigned_to' AND m3.meta_value IN ({$postIds}) ";
164
+		}
165
+		if ($termIds) {
166
+			$and.= "AND tr.term_taxonomy_id IN ({$termIds}) ";
167
+		}
168
+		return apply_filters('site-reviews/query/and-for-counts', $and);
169
+	}
170 170
 
171
-    /**
172
-     * @param string $innerJoin
173
-     * @return string
174
-     */
175
-    protected function getInnerJoinForCounts(array $args, $innerJoin = '')
176
-    {
177
-        if (!empty(Arr::get($args, 'post_ids'))) {
178
-            $innerJoin.= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id ";
179
-        }
180
-        if (!empty(Arr::get($args, 'term_ids'))) {
181
-            $innerJoin.= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id ";
182
-        }
183
-        return apply_filters('site-reviews/query/inner-join-for-counts', $innerJoin);
184
-    }
171
+	/**
172
+	 * @param string $innerJoin
173
+	 * @return string
174
+	 */
175
+	protected function getInnerJoinForCounts(array $args, $innerJoin = '')
176
+	{
177
+		if (!empty(Arr::get($args, 'post_ids'))) {
178
+			$innerJoin.= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id ";
179
+		}
180
+		if (!empty(Arr::get($args, 'term_ids'))) {
181
+			$innerJoin.= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id ";
182
+		}
183
+		return apply_filters('site-reviews/query/inner-join-for-counts', $innerJoin);
184
+	}
185 185
 }
Please login to merge, or discard this patch.
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -22,17 +22,17 @@  discard block
 block discarded – undo
22 22
      * @param string $metaReviewId
23 23
      * @return int
24 24
      */
25
-    public function getPostIdFromReviewId($metaReviewId)
25
+    public function getPostIdFromReviewId( $metaReviewId )
26 26
     {
27
-        $postId = $this->db->get_var("
27
+        $postId = $this->db->get_var( "
28 28
             SELECT p.ID
29 29
             FROM {$this->db->posts} AS p
30 30
             INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id
31 31
             WHERE p.post_type = '{$this->postType}'
32 32
             AND m.meta_key = '_review_id'
33 33
             AND m.meta_value = '{$metaReviewId}'
34
-        ");
35
-        return intval($postId);
34
+        " );
35
+        return intval( $postId );
36 36
     }
37 37
 
38 38
     /**
@@ -40,23 +40,23 @@  discard block
 block discarded – undo
40 40
      * @param int $limit
41 41
      * @return array
42 42
      */
43
-    public function getReviewCounts(array $args, $lastPostId = 0, $limit = 500)
43
+    public function getReviewCounts( array $args, $lastPostId = 0, $limit = 500 )
44 44
     {
45
-        return (array) $this->db->get_results("
45
+        return (array)$this->db->get_results( "
46 46
             SELECT DISTINCT p.ID, m1.meta_value AS rating, m2.meta_value AS type
47 47
             FROM {$this->db->posts} AS p
48 48
             INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id
49 49
             INNER JOIN {$this->db->postmeta} AS m2 ON p.ID = m2.post_id
50
-            {$this->getInnerJoinForCounts($args)}
50
+            {$this->getInnerJoinForCounts( $args )}
51 51
             WHERE p.ID > {$lastPostId}
52 52
             AND p.post_status = 'publish'
53 53
             AND p.post_type = '{$this->postType}'
54 54
             AND m1.meta_key = '_rating'
55 55
             AND m2.meta_key = '_review_type'
56
-            {$this->getAndForCounts($args)}
56
+            {$this->getAndForCounts( $args )}
57 57
             ORDER By p.ID ASC
58 58
             LIMIT {$limit}
59
-        ");
59
+        " );
60 60
     }
61 61
 
62 62
     /**
@@ -64,17 +64,17 @@  discard block
 block discarded – undo
64 64
      * @param string $metaKey
65 65
      * @return array
66 66
      */
67
-    public function getReviewCountsFor($metaKey)
67
+    public function getReviewCountsFor( $metaKey )
68 68
     {
69
-        $metaKey = Str::prefix('_', $metaKey);
70
-        return (array) $this->db->get_results("
69
+        $metaKey = Str::prefix( '_', $metaKey );
70
+        return (array)$this->db->get_results( "
71 71
             SELECT DISTINCT m.meta_value AS name, COUNT(*) num_posts
72 72
             FROM {$this->db->posts} AS p
73 73
             INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id
74 74
             WHERE p.post_type = '{$this->postType}'
75 75
             AND m.meta_key = '{$metaKey}'
76 76
             GROUP BY name
77
-        ");
77
+        " );
78 78
     }
79 79
 
80 80
     /**
@@ -82,9 +82,9 @@  discard block
 block discarded – undo
82 82
      * @param string $reviewType
83 83
      * @return array
84 84
      */
85
-    public function getReviewIdsByType($reviewType)
85
+    public function getReviewIdsByType( $reviewType )
86 86
     {
87
-        $results = $this->db->get_col("
87
+        $results = $this->db->get_col( "
88 88
             SELECT DISTINCT m1.meta_value AS review_id
89 89
             FROM {$this->db->posts} AS p
90 90
             INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id
@@ -93,8 +93,8 @@  discard block
 block discarded – undo
93 93
             AND m1.meta_key = '_review_id'
94 94
             AND m2.meta_key = '_review_type'
95 95
             AND m2.meta_value = '{$reviewType}'
96
-        ");
97
-        return array_keys(array_flip($results));
96
+        " );
97
+        return array_keys( array_flip( $results ) );
98 98
     }
99 99
 
100 100
     /**
@@ -102,12 +102,12 @@  discard block
 block discarded – undo
102 102
      * @param int $limit
103 103
      * @return array
104 104
      */
105
-    public function getReviewRatingsFromIds(array $postIds, $greaterThanId = 0, $limit = 100)
105
+    public function getReviewRatingsFromIds( array $postIds, $greaterThanId = 0, $limit = 100 )
106 106
     {
107
-        sort($postIds);
108
-        $postIds = array_slice($postIds, intval(array_search($greaterThanId, $postIds)), $limit);
109
-        $postIds = implode(',', $postIds);
110
-        return (array) $this->db->get_results("
107
+        sort( $postIds );
108
+        $postIds = array_slice( $postIds, intval( array_search( $greaterThanId, $postIds ) ), $limit );
109
+        $postIds = implode( ',', $postIds );
110
+        return (array)$this->db->get_results( "
111 111
             SELECT p.ID, m.meta_value AS rating
112 112
             FROM {$this->db->posts} AS p
113 113
             INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
             GROUP BY p.ID
120 120
             ORDER By p.ID ASC
121 121
             LIMIT {$limit}
122
-        ");
122
+        " );
123 123
     }
124 124
 
125 125
     /**
@@ -127,13 +127,13 @@  discard block
 block discarded – undo
127 127
      * @param string $status
128 128
      * @return array
129 129
      */
130
-    public function getReviewsMeta($key, $status = 'publish')
130
+    public function getReviewsMeta( $key, $status = 'publish' )
131 131
     {
132 132
         $postStatusQuery = 'all' != $status && !empty($status)
133 133
             ? "AND p.post_status = '{$status}'"
134 134
             : '';
135
-        $key = Str::prefix('_', $key);
136
-        $values = $this->db->get_col("
135
+        $key = Str::prefix( '_', $key );
136
+        $values = $this->db->get_col( "
137 137
             SELECT DISTINCT m.meta_value
138 138
             FROM {$this->db->postmeta} m
139 139
             LEFT JOIN {$this->db->posts} p ON p.ID = m.post_id
@@ -143,8 +143,8 @@  discard block
 block discarded – undo
143 143
             $postStatusQuery
144 144
             GROUP BY p.ID -- remove duplicate meta_value entries
145 145
             ORDER BY m.meta_id ASC -- sort by oldest meta_value
146
-        ");
147
-        sort($values);
146
+        " );
147
+        sort( $values );
148 148
         return $values;
149 149
     }
150 150
 
@@ -152,34 +152,34 @@  discard block
 block discarded – undo
152 152
      * @param string $and
153 153
      * @return string
154 154
      */
155
-    protected function getAndForCounts(array $args, $and = '')
155
+    protected function getAndForCounts( array $args, $and = '' )
156 156
     {
157
-        $postIds = implode(',', array_filter(Arr::get($args, 'post_ids', [])));
158
-        $termIds = implode(',', array_filter(Arr::get($args, 'term_ids', [])));
159
-        if (!empty($args['type'])) {
160
-            $and.= "AND m2.meta_value = '{$args['type']}' ";
157
+        $postIds = implode( ',', array_filter( Arr::get( $args, 'post_ids', [] ) ) );
158
+        $termIds = implode( ',', array_filter( Arr::get( $args, 'term_ids', [] ) ) );
159
+        if( !empty($args['type']) ) {
160
+            $and .= "AND m2.meta_value = '{$args['type']}' ";
161 161
         }
162
-        if ($postIds) {
163
-            $and.= "AND m3.meta_key = '_assigned_to' AND m3.meta_value IN ({$postIds}) ";
162
+        if( $postIds ) {
163
+            $and .= "AND m3.meta_key = '_assigned_to' AND m3.meta_value IN ({$postIds}) ";
164 164
         }
165
-        if ($termIds) {
166
-            $and.= "AND tr.term_taxonomy_id IN ({$termIds}) ";
165
+        if( $termIds ) {
166
+            $and .= "AND tr.term_taxonomy_id IN ({$termIds}) ";
167 167
         }
168
-        return apply_filters('site-reviews/query/and-for-counts', $and);
168
+        return apply_filters( 'site-reviews/query/and-for-counts', $and );
169 169
     }
170 170
 
171 171
     /**
172 172
      * @param string $innerJoin
173 173
      * @return string
174 174
      */
175
-    protected function getInnerJoinForCounts(array $args, $innerJoin = '')
175
+    protected function getInnerJoinForCounts( array $args, $innerJoin = '' )
176 176
     {
177
-        if (!empty(Arr::get($args, 'post_ids'))) {
178
-            $innerJoin.= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id ";
177
+        if( !empty(Arr::get( $args, 'post_ids' )) ) {
178
+            $innerJoin .= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id ";
179 179
         }
180
-        if (!empty(Arr::get($args, 'term_ids'))) {
181
-            $innerJoin.= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id ";
180
+        if( !empty(Arr::get( $args, 'term_ids' )) ) {
181
+            $innerJoin .= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id ";
182 182
         }
183
-        return apply_filters('site-reviews/query/inner-join-for-counts', $innerJoin);
183
+        return apply_filters( 'site-reviews/query/inner-join-for-counts', $innerJoin );
184 184
     }
185 185
 }
Please login to merge, or discard this patch.
plugin/Controllers/BlocksController.php 1 patch
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -8,86 +8,86 @@
 block discarded – undo
8 8
 
9 9
 class BlocksController extends Controller
10 10
 {
11
-    /**
12
-     * @param array $categories
13
-     * @return array
14
-     * @filter block_categories
15
-     */
16
-    public function filterBlockCategories($categories)
17
-    {
18
-        $categories = Arr::consolidateArray($categories);
19
-        $categories[] = [
20
-            'icon' => null,
21
-            'slug' => Application::ID,
22
-            'title' => glsr()->name,
23
-        ];
24
-        return $categories;
25
-    }
11
+	/**
12
+	 * @param array $categories
13
+	 * @return array
14
+	 * @filter block_categories
15
+	 */
16
+	public function filterBlockCategories($categories)
17
+	{
18
+		$categories = Arr::consolidateArray($categories);
19
+		$categories[] = [
20
+			'icon' => null,
21
+			'slug' => Application::ID,
22
+			'title' => glsr()->name,
23
+		];
24
+		return $categories;
25
+	}
26 26
 
27
-    /**
28
-     * @param array $editors
29
-     * @param string $postType
30
-     * @return array
31
-     * @filter classic_editor_enabled_editors_for_post_type
32
-     * @plugin classic-editor/classic-editor.php
33
-     */
34
-    public function filterEnabledEditors($editors, $postType)
35
-    {
36
-        return Application::POST_TYPE == $postType
37
-            ? ['block_editor' => false, 'classic_editor' => false]
38
-            : $editors;
39
-    }
27
+	/**
28
+	 * @param array $editors
29
+	 * @param string $postType
30
+	 * @return array
31
+	 * @filter classic_editor_enabled_editors_for_post_type
32
+	 * @plugin classic-editor/classic-editor.php
33
+	 */
34
+	public function filterEnabledEditors($editors, $postType)
35
+	{
36
+		return Application::POST_TYPE == $postType
37
+			? ['block_editor' => false, 'classic_editor' => false]
38
+			: $editors;
39
+	}
40 40
 
41
-    /**
42
-     * @param bool $bool
43
-     * @param string $postType
44
-     * @return bool
45
-     * @filter use_block_editor_for_post_type
46
-     */
47
-    public function filterUseBlockEditor($bool, $postType)
48
-    {
49
-        return Application::POST_TYPE == $postType
50
-            ? false
51
-            : $bool;
52
-    }
41
+	/**
42
+	 * @param bool $bool
43
+	 * @param string $postType
44
+	 * @return bool
45
+	 * @filter use_block_editor_for_post_type
46
+	 */
47
+	public function filterUseBlockEditor($bool, $postType)
48
+	{
49
+		return Application::POST_TYPE == $postType
50
+			? false
51
+			: $bool;
52
+	}
53 53
 
54
-    /**
55
-     * @return void
56
-     * @action init
57
-     */
58
-    public function registerAssets()
59
-    {
60
-        wp_register_style(
61
-            Application::ID.'/blocks',
62
-            glsr()->url('assets/styles/'.Application::ID.'-blocks.css'),
63
-            ['wp-edit-blocks'],
64
-            glsr()->version
65
-        );
66
-        wp_register_script(
67
-            Application::ID.'/blocks',
68
-            glsr()->url('assets/scripts/'.Application::ID.'-blocks.js'),
69
-            ['wp-api-fetch', 'wp-blocks', 'wp-i18n', 'wp-editor', 'wp-element', Application::ID],
70
-            glsr()->version
71
-        );
72
-    }
54
+	/**
55
+	 * @return void
56
+	 * @action init
57
+	 */
58
+	public function registerAssets()
59
+	{
60
+		wp_register_style(
61
+			Application::ID.'/blocks',
62
+			glsr()->url('assets/styles/'.Application::ID.'-blocks.css'),
63
+			['wp-edit-blocks'],
64
+			glsr()->version
65
+		);
66
+		wp_register_script(
67
+			Application::ID.'/blocks',
68
+			glsr()->url('assets/scripts/'.Application::ID.'-blocks.js'),
69
+			['wp-api-fetch', 'wp-blocks', 'wp-i18n', 'wp-editor', 'wp-element', Application::ID],
70
+			glsr()->version
71
+		);
72
+	}
73 73
 
74
-    /**
75
-     * @return void
76
-     * @action init
77
-     */
78
-    public function registerBlocks()
79
-    {
80
-        $blocks = [
81
-            'form', 'reviews', 'summary',
82
-        ];
83
-        foreach ($blocks as $block) {
84
-            $id = str_replace('_reviews', '', Application::ID.'_'.$block);
85
-            $blockClass = Helper::buildClassName($id.'-block', 'Blocks');
86
-            if (!class_exists($blockClass)) {
87
-                glsr_log()->error(sprintf('Class missing (%s)', $blockClass));
88
-                continue;
89
-            }
90
-            glsr($blockClass)->register($block);
91
-        }
92
-    }
74
+	/**
75
+	 * @return void
76
+	 * @action init
77
+	 */
78
+	public function registerBlocks()
79
+	{
80
+		$blocks = [
81
+			'form', 'reviews', 'summary',
82
+		];
83
+		foreach ($blocks as $block) {
84
+			$id = str_replace('_reviews', '', Application::ID.'_'.$block);
85
+			$blockClass = Helper::buildClassName($id.'-block', 'Blocks');
86
+			if (!class_exists($blockClass)) {
87
+				glsr_log()->error(sprintf('Class missing (%s)', $blockClass));
88
+				continue;
89
+			}
90
+			glsr($blockClass)->register($block);
91
+		}
92
+	}
93 93
 }
Please login to merge, or discard this patch.
plugin/Controllers/ListTableController.php 2 patches
Indentation   +247 added lines, -247 removed lines patch added patch discarded remove patch
@@ -14,266 +14,266 @@
 block discarded – undo
14 14
 
15 15
 class ListTableController extends Controller
16 16
 {
17
-    /**
18
-     * @return void
19
-     * @action admin_action_approve
20
-     */
21
-    public function approve()
22
-    {
23
-        if (Application::ID != filter_input(INPUT_GET, 'plugin')) {
24
-            return;
25
-        }
26
-        check_admin_referer('approve-review_'.($postId = $this->getPostId()));
27
-        wp_update_post([
28
-            'ID' => $postId,
29
-            'post_status' => 'publish',
30
-        ]);
31
-        wp_safe_redirect(wp_get_referer());
32
-        exit;
33
-    }
17
+	/**
18
+	 * @return void
19
+	 * @action admin_action_approve
20
+	 */
21
+	public function approve()
22
+	{
23
+		if (Application::ID != filter_input(INPUT_GET, 'plugin')) {
24
+			return;
25
+		}
26
+		check_admin_referer('approve-review_'.($postId = $this->getPostId()));
27
+		wp_update_post([
28
+			'ID' => $postId,
29
+			'post_status' => 'publish',
30
+		]);
31
+		wp_safe_redirect(wp_get_referer());
32
+		exit;
33
+	}
34 34
 
35
-    /**
36
-     * @param array $columns
37
-     * @return array
38
-     * @filter manage_.Application::POST_TYPE._posts_columns
39
-     */
40
-    public function filterColumnsForPostType($columns)
41
-    {
42
-        $columns = Arr::consolidateArray($columns);
43
-        $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE];
44
-        foreach ($postTypeColumns as $key => &$value) {
45
-            if (!array_key_exists($key, $columns) || !empty($value)) {
46
-                continue;
47
-            }
48
-            $value = $columns[$key];
49
-        }
50
-        if (count(glsr(Database::class)->getReviewsMeta('review_type')) < 2) {
51
-            unset($postTypeColumns['review_type']);
52
-        }
53
-        return array_filter($postTypeColumns, 'strlen');
54
-    }
35
+	/**
36
+	 * @param array $columns
37
+	 * @return array
38
+	 * @filter manage_.Application::POST_TYPE._posts_columns
39
+	 */
40
+	public function filterColumnsForPostType($columns)
41
+	{
42
+		$columns = Arr::consolidateArray($columns);
43
+		$postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE];
44
+		foreach ($postTypeColumns as $key => &$value) {
45
+			if (!array_key_exists($key, $columns) || !empty($value)) {
46
+				continue;
47
+			}
48
+			$value = $columns[$key];
49
+		}
50
+		if (count(glsr(Database::class)->getReviewsMeta('review_type')) < 2) {
51
+			unset($postTypeColumns['review_type']);
52
+		}
53
+		return array_filter($postTypeColumns, 'strlen');
54
+	}
55 55
 
56
-    /**
57
-     * @param string $status
58
-     * @param WP_Post $post
59
-     * @return string
60
-     * @filter post_date_column_status
61
-     */
62
-    public function filterDateColumnStatus($status, $post)
63
-    {
64
-        if (Application::POST_TYPE == Arr::get($post, 'post_type')) {
65
-            $status = __('Submitted', 'site-reviews');
66
-        }
67
-        return $status;
68
-    }
56
+	/**
57
+	 * @param string $status
58
+	 * @param WP_Post $post
59
+	 * @return string
60
+	 * @filter post_date_column_status
61
+	 */
62
+	public function filterDateColumnStatus($status, $post)
63
+	{
64
+		if (Application::POST_TYPE == Arr::get($post, 'post_type')) {
65
+			$status = __('Submitted', 'site-reviews');
66
+		}
67
+		return $status;
68
+	}
69 69
 
70
-    /**
71
-     * @param array $hidden
72
-     * @param WP_Screen $post
73
-     * @return array
74
-     * @filter default_hidden_columns
75
-     */
76
-    public function filterDefaultHiddenColumns($hidden, $screen)
77
-    {
78
-        if (Arr::get($screen, 'id') == 'edit-'.Application::POST_TYPE) {
79
-            $hidden = Arr::consolidateArray($hidden);
80
-            $hidden = array_unique(array_merge($hidden, [
81
-                'email', 'ip_address', 'response', 'reviewer',
82
-            ]));
83
-        }
84
-        return $hidden;
85
-    }
70
+	/**
71
+	 * @param array $hidden
72
+	 * @param WP_Screen $post
73
+	 * @return array
74
+	 * @filter default_hidden_columns
75
+	 */
76
+	public function filterDefaultHiddenColumns($hidden, $screen)
77
+	{
78
+		if (Arr::get($screen, 'id') == 'edit-'.Application::POST_TYPE) {
79
+			$hidden = Arr::consolidateArray($hidden);
80
+			$hidden = array_unique(array_merge($hidden, [
81
+				'email', 'ip_address', 'response', 'reviewer',
82
+			]));
83
+		}
84
+		return $hidden;
85
+	}
86 86
 
87
-    /**
88
-     * @param array $actions
89
-     * @param WP_Post $post
90
-     * @return array
91
-     * @filter post_row_actions
92
-     */
93
-    public function filterRowActions($actions, $post)
94
-    {
95
-        if (Application::POST_TYPE != Arr::get($post, 'post_type') || 'trash' == $post->post_status) {
96
-            return $actions;
97
-        }
98
-        unset($actions['inline hide-if-no-js']); //Remove Quick-edit
99
-        $rowActions = [
100
-            'approve' => esc_attr__('Approve', 'site-reviews'),
101
-            'unapprove' => esc_attr__('Unapprove', 'site-reviews'),
102
-        ];
103
-        $newActions = [];
104
-        foreach ($rowActions as $key => $text) {
105
-            $newActions[$key] = glsr(Builder::class)->a($text, [
106
-                'aria-label' => sprintf(esc_attr_x('%s this review', 'Approve the review', 'site-reviews'), $text),
107
-                'class' => 'glsr-change-status',
108
-                'href' => wp_nonce_url(
109
-                    admin_url('post.php?post='.$post->ID.'&action='.$key.'&plugin='.Application::ID),
110
-                    $key.'-review_'.$post->ID
111
-                ),
112
-            ]);
113
-        }
114
-        return $newActions + Arr::consolidateArray($actions);
115
-    }
87
+	/**
88
+	 * @param array $actions
89
+	 * @param WP_Post $post
90
+	 * @return array
91
+	 * @filter post_row_actions
92
+	 */
93
+	public function filterRowActions($actions, $post)
94
+	{
95
+		if (Application::POST_TYPE != Arr::get($post, 'post_type') || 'trash' == $post->post_status) {
96
+			return $actions;
97
+		}
98
+		unset($actions['inline hide-if-no-js']); //Remove Quick-edit
99
+		$rowActions = [
100
+			'approve' => esc_attr__('Approve', 'site-reviews'),
101
+			'unapprove' => esc_attr__('Unapprove', 'site-reviews'),
102
+		];
103
+		$newActions = [];
104
+		foreach ($rowActions as $key => $text) {
105
+			$newActions[$key] = glsr(Builder::class)->a($text, [
106
+				'aria-label' => sprintf(esc_attr_x('%s this review', 'Approve the review', 'site-reviews'), $text),
107
+				'class' => 'glsr-change-status',
108
+				'href' => wp_nonce_url(
109
+					admin_url('post.php?post='.$post->ID.'&action='.$key.'&plugin='.Application::ID),
110
+					$key.'-review_'.$post->ID
111
+				),
112
+			]);
113
+		}
114
+		return $newActions + Arr::consolidateArray($actions);
115
+	}
116 116
 
117
-    /**
118
-     * @param array $columns
119
-     * @return array
120
-     * @filter manage_edit-.Application::POST_TYPE._sortable_columns
121
-     */
122
-    public function filterSortableColumns($columns)
123
-    {
124
-        $columns = Arr::consolidateArray($columns);
125
-        $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE];
126
-        unset($postTypeColumns['cb']);
127
-        foreach ($postTypeColumns as $key => $value) {
128
-            if (Str::startsWith('taxonomy', $key)) {
129
-                continue;
130
-            }
131
-            $columns[$key] = $key;
132
-        }
133
-        return $columns;
134
-    }
117
+	/**
118
+	 * @param array $columns
119
+	 * @return array
120
+	 * @filter manage_edit-.Application::POST_TYPE._sortable_columns
121
+	 */
122
+	public function filterSortableColumns($columns)
123
+	{
124
+		$columns = Arr::consolidateArray($columns);
125
+		$postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE];
126
+		unset($postTypeColumns['cb']);
127
+		foreach ($postTypeColumns as $key => $value) {
128
+			if (Str::startsWith('taxonomy', $key)) {
129
+				continue;
130
+			}
131
+			$columns[$key] = $key;
132
+		}
133
+		return $columns;
134
+	}
135 135
 
136
-    /**
137
-     * @param string $columnName
138
-     * @param string $postType
139
-     * @return void
140
-     * @action bulk_edit_custom_box
141
-     */
142
-    public function renderBulkEditFields($columnName, $postType)
143
-    {
144
-        if ('assigned_to' == $columnName && Application::POST_TYPE == $postType) {
145
-            glsr()->render('partials/editor/bulk-edit-assigned-to');
146
-        }
147
-    }
136
+	/**
137
+	 * @param string $columnName
138
+	 * @param string $postType
139
+	 * @return void
140
+	 * @action bulk_edit_custom_box
141
+	 */
142
+	public function renderBulkEditFields($columnName, $postType)
143
+	{
144
+		if ('assigned_to' == $columnName && Application::POST_TYPE == $postType) {
145
+			glsr()->render('partials/editor/bulk-edit-assigned-to');
146
+		}
147
+	}
148 148
 
149
-    /**
150
-     * @param string $postType
151
-     * @return void
152
-     * @action restrict_manage_posts
153
-     */
154
-    public function renderColumnFilters($postType)
155
-    {
156
-        glsr(Columns::class)->renderFilters($postType);
157
-    }
149
+	/**
150
+	 * @param string $postType
151
+	 * @return void
152
+	 * @action restrict_manage_posts
153
+	 */
154
+	public function renderColumnFilters($postType)
155
+	{
156
+		glsr(Columns::class)->renderFilters($postType);
157
+	}
158 158
 
159
-    /**
160
-     * @param string $column
161
-     * @param string $postId
162
-     * @return void
163
-     * @action manage_posts_custom_column
164
-     */
165
-    public function renderColumnValues($column, $postId)
166
-    {
167
-        glsr(Columns::class)->renderValues($column, $postId);
168
-    }
159
+	/**
160
+	 * @param string $column
161
+	 * @param string $postId
162
+	 * @return void
163
+	 * @action manage_posts_custom_column
164
+	 */
165
+	public function renderColumnValues($column, $postId)
166
+	{
167
+		glsr(Columns::class)->renderValues($column, $postId);
168
+	}
169 169
 
170
-    /**
171
-     * @param int $postId
172
-     * @return void
173
-     * @action save_post_.Application::POST_TYPE
174
-     */
175
-    public function saveBulkEditFields($postId)
176
-    {
177
-        if (!current_user_can('edit_posts')) {
178
-            return;
179
-        }
180
-        $assignedTo = filter_input(INPUT_GET, 'assigned_to');
181
-        if ($assignedTo && get_post($assignedTo)) {
182
-            glsr(Database::class)->update($postId, 'assigned_to', $assignedTo);
183
-        }
184
-    }
170
+	/**
171
+	 * @param int $postId
172
+	 * @return void
173
+	 * @action save_post_.Application::POST_TYPE
174
+	 */
175
+	public function saveBulkEditFields($postId)
176
+	{
177
+		if (!current_user_can('edit_posts')) {
178
+			return;
179
+		}
180
+		$assignedTo = filter_input(INPUT_GET, 'assigned_to');
181
+		if ($assignedTo && get_post($assignedTo)) {
182
+			glsr(Database::class)->update($postId, 'assigned_to', $assignedTo);
183
+		}
184
+	}
185 185
 
186
-    /**
187
-     * @return void
188
-     * @action pre_get_posts
189
-     */
190
-    public function setQueryForColumn(WP_Query $query)
191
-    {
192
-        if (!$this->hasPermission($query)) {
193
-            return;
194
-        }
195
-        $this->setMetaQuery($query, [
196
-            'rating', 'review_type',
197
-        ]);
198
-        $this->setOrderby($query);
199
-    }
186
+	/**
187
+	 * @return void
188
+	 * @action pre_get_posts
189
+	 */
190
+	public function setQueryForColumn(WP_Query $query)
191
+	{
192
+		if (!$this->hasPermission($query)) {
193
+			return;
194
+		}
195
+		$this->setMetaQuery($query, [
196
+			'rating', 'review_type',
197
+		]);
198
+		$this->setOrderby($query);
199
+	}
200 200
 
201
-    /**
202
-     * @return void
203
-     * @action admin_action_unapprove
204
-     */
205
-    public function unapprove()
206
-    {
207
-        if (Application::ID != filter_input(INPUT_GET, 'plugin')) {
208
-            return;
209
-        }
210
-        check_admin_referer('unapprove-review_'.($postId = $this->getPostId()));
211
-        wp_update_post([
212
-            'ID' => $postId,
213
-            'post_status' => 'pending',
214
-        ]);
215
-        wp_safe_redirect(wp_get_referer());
216
-        exit;
217
-    }
201
+	/**
202
+	 * @return void
203
+	 * @action admin_action_unapprove
204
+	 */
205
+	public function unapprove()
206
+	{
207
+		if (Application::ID != filter_input(INPUT_GET, 'plugin')) {
208
+			return;
209
+		}
210
+		check_admin_referer('unapprove-review_'.($postId = $this->getPostId()));
211
+		wp_update_post([
212
+			'ID' => $postId,
213
+			'post_status' => 'pending',
214
+		]);
215
+		wp_safe_redirect(wp_get_referer());
216
+		exit;
217
+	}
218 218
 
219
-    /**
220
-     * Check if the translation string can be modified.
221
-     * @param string $domain
222
-     * @return bool
223
-     */
224
-    protected function canModifyTranslation($domain = 'default')
225
-    {
226
-        $screen = glsr_current_screen();
227
-        return 'default' == $domain
228
-            && 'edit' == $screen->base
229
-            && Application::POST_TYPE == $screen->post_type;
230
-    }
219
+	/**
220
+	 * Check if the translation string can be modified.
221
+	 * @param string $domain
222
+	 * @return bool
223
+	 */
224
+	protected function canModifyTranslation($domain = 'default')
225
+	{
226
+		$screen = glsr_current_screen();
227
+		return 'default' == $domain
228
+			&& 'edit' == $screen->base
229
+			&& Application::POST_TYPE == $screen->post_type;
230
+	}
231 231
 
232
-    /**
233
-     * @return bool
234
-     */
235
-    protected function hasPermission(WP_Query $query)
236
-    {
237
-        global $pagenow;
238
-        return is_admin()
239
-            && $query->is_main_query()
240
-            && Application::POST_TYPE == $query->get('post_type')
241
-            && 'edit.php' == $pagenow;
242
-    }
232
+	/**
233
+	 * @return bool
234
+	 */
235
+	protected function hasPermission(WP_Query $query)
236
+	{
237
+		global $pagenow;
238
+		return is_admin()
239
+			&& $query->is_main_query()
240
+			&& Application::POST_TYPE == $query->get('post_type')
241
+			&& 'edit.php' == $pagenow;
242
+	}
243 243
 
244
-    /**
245
-     * @return void
246
-     */
247
-    protected function setMetaQuery(WP_Query $query, array $metaKeys)
248
-    {
249
-        foreach ($metaKeys as $key) {
250
-            $value = (string) filter_input(INPUT_GET, $key);
251
-            if ('' === $value) {
252
-                continue;
253
-            }
254
-            $metaQuery = (array) $query->get('meta_query');
255
-            $metaQuery[] = [
256
-                'key' => Str::prefix('_', $key, '_'),
257
-                'value' => $value,
258
-            ];
259
-            $query->set('meta_query', array_filter($metaQuery));
260
-        }
261
-    }
244
+	/**
245
+	 * @return void
246
+	 */
247
+	protected function setMetaQuery(WP_Query $query, array $metaKeys)
248
+	{
249
+		foreach ($metaKeys as $key) {
250
+			$value = (string) filter_input(INPUT_GET, $key);
251
+			if ('' === $value) {
252
+				continue;
253
+			}
254
+			$metaQuery = (array) $query->get('meta_query');
255
+			$metaQuery[] = [
256
+				'key' => Str::prefix('_', $key, '_'),
257
+				'value' => $value,
258
+			];
259
+			$query->set('meta_query', array_filter($metaQuery));
260
+		}
261
+	}
262 262
 
263
-    /**
264
-     * @return void
265
-     */
266
-    protected function setOrderby(WP_Query $query)
267
-    {
268
-        $orderby = $query->get('orderby');
269
-        $columns = glsr()->postTypeColumns[Application::POST_TYPE];
270
-        unset($columns['cb'], $columns['title'], $columns['date']);
271
-        if (in_array($orderby, array_keys($columns))) {
272
-            if ('reviewer' == $orderby) {
273
-                $orderby = 'author';
274
-            }
275
-            $query->set('meta_key', Str::prefix('_', $orderby, '_'));
276
-            $query->set('orderby', 'meta_value');
277
-        }
278
-    }
263
+	/**
264
+	 * @return void
265
+	 */
266
+	protected function setOrderby(WP_Query $query)
267
+	{
268
+		$orderby = $query->get('orderby');
269
+		$columns = glsr()->postTypeColumns[Application::POST_TYPE];
270
+		unset($columns['cb'], $columns['title'], $columns['date']);
271
+		if (in_array($orderby, array_keys($columns))) {
272
+			if ('reviewer' == $orderby) {
273
+				$orderby = 'author';
274
+			}
275
+			$query->set('meta_key', Str::prefix('_', $orderby, '_'));
276
+			$query->set('orderby', 'meta_value');
277
+		}
278
+	}
279 279
 }
Please login to merge, or discard this patch.
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -20,15 +20,15 @@  discard block
 block discarded – undo
20 20
      */
21 21
     public function approve()
22 22
     {
23
-        if (Application::ID != filter_input(INPUT_GET, 'plugin')) {
23
+        if( Application::ID != filter_input( INPUT_GET, 'plugin' ) ) {
24 24
             return;
25 25
         }
26
-        check_admin_referer('approve-review_'.($postId = $this->getPostId()));
27
-        wp_update_post([
26
+        check_admin_referer( 'approve-review_'.($postId = $this->getPostId()) );
27
+        wp_update_post( [
28 28
             'ID' => $postId,
29 29
             'post_status' => 'publish',
30
-        ]);
31
-        wp_safe_redirect(wp_get_referer());
30
+        ] );
31
+        wp_safe_redirect( wp_get_referer() );
32 32
         exit;
33 33
     }
34 34
 
@@ -37,20 +37,20 @@  discard block
 block discarded – undo
37 37
      * @return array
38 38
      * @filter manage_.Application::POST_TYPE._posts_columns
39 39
      */
40
-    public function filterColumnsForPostType($columns)
40
+    public function filterColumnsForPostType( $columns )
41 41
     {
42
-        $columns = Arr::consolidateArray($columns);
42
+        $columns = Arr::consolidateArray( $columns );
43 43
         $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE];
44
-        foreach ($postTypeColumns as $key => &$value) {
45
-            if (!array_key_exists($key, $columns) || !empty($value)) {
44
+        foreach( $postTypeColumns as $key => &$value ) {
45
+            if( !array_key_exists( $key, $columns ) || !empty($value) ) {
46 46
                 continue;
47 47
             }
48 48
             $value = $columns[$key];
49 49
         }
50
-        if (count(glsr(Database::class)->getReviewsMeta('review_type')) < 2) {
50
+        if( count( glsr( Database::class )->getReviewsMeta( 'review_type' ) ) < 2 ) {
51 51
             unset($postTypeColumns['review_type']);
52 52
         }
53
-        return array_filter($postTypeColumns, 'strlen');
53
+        return array_filter( $postTypeColumns, 'strlen' );
54 54
     }
55 55
 
56 56
     /**
@@ -59,10 +59,10 @@  discard block
 block discarded – undo
59 59
      * @return string
60 60
      * @filter post_date_column_status
61 61
      */
62
-    public function filterDateColumnStatus($status, $post)
62
+    public function filterDateColumnStatus( $status, $post )
63 63
     {
64
-        if (Application::POST_TYPE == Arr::get($post, 'post_type')) {
65
-            $status = __('Submitted', 'site-reviews');
64
+        if( Application::POST_TYPE == Arr::get( $post, 'post_type' ) ) {
65
+            $status = __( 'Submitted', 'site-reviews' );
66 66
         }
67 67
         return $status;
68 68
     }
@@ -73,13 +73,13 @@  discard block
 block discarded – undo
73 73
      * @return array
74 74
      * @filter default_hidden_columns
75 75
      */
76
-    public function filterDefaultHiddenColumns($hidden, $screen)
76
+    public function filterDefaultHiddenColumns( $hidden, $screen )
77 77
     {
78
-        if (Arr::get($screen, 'id') == 'edit-'.Application::POST_TYPE) {
79
-            $hidden = Arr::consolidateArray($hidden);
80
-            $hidden = array_unique(array_merge($hidden, [
78
+        if( Arr::get( $screen, 'id' ) == 'edit-'.Application::POST_TYPE ) {
79
+            $hidden = Arr::consolidateArray( $hidden );
80
+            $hidden = array_unique( array_merge( $hidden, [
81 81
                 'email', 'ip_address', 'response', 'reviewer',
82
-            ]));
82
+            ] ) );
83 83
         }
84 84
         return $hidden;
85 85
     }
@@ -90,28 +90,28 @@  discard block
 block discarded – undo
90 90
      * @return array
91 91
      * @filter post_row_actions
92 92
      */
93
-    public function filterRowActions($actions, $post)
93
+    public function filterRowActions( $actions, $post )
94 94
     {
95
-        if (Application::POST_TYPE != Arr::get($post, 'post_type') || 'trash' == $post->post_status) {
95
+        if( Application::POST_TYPE != Arr::get( $post, 'post_type' ) || 'trash' == $post->post_status ) {
96 96
             return $actions;
97 97
         }
98 98
         unset($actions['inline hide-if-no-js']); //Remove Quick-edit
99 99
         $rowActions = [
100
-            'approve' => esc_attr__('Approve', 'site-reviews'),
101
-            'unapprove' => esc_attr__('Unapprove', 'site-reviews'),
100
+            'approve' => esc_attr__( 'Approve', 'site-reviews' ),
101
+            'unapprove' => esc_attr__( 'Unapprove', 'site-reviews' ),
102 102
         ];
103 103
         $newActions = [];
104
-        foreach ($rowActions as $key => $text) {
105
-            $newActions[$key] = glsr(Builder::class)->a($text, [
106
-                'aria-label' => sprintf(esc_attr_x('%s this review', 'Approve the review', 'site-reviews'), $text),
104
+        foreach( $rowActions as $key => $text ) {
105
+            $newActions[$key] = glsr( Builder::class )->a( $text, [
106
+                'aria-label' => sprintf( esc_attr_x( '%s this review', 'Approve the review', 'site-reviews' ), $text ),
107 107
                 'class' => 'glsr-change-status',
108 108
                 'href' => wp_nonce_url(
109
-                    admin_url('post.php?post='.$post->ID.'&action='.$key.'&plugin='.Application::ID),
109
+                    admin_url( 'post.php?post='.$post->ID.'&action='.$key.'&plugin='.Application::ID ),
110 110
                     $key.'-review_'.$post->ID
111 111
                 ),
112
-            ]);
112
+            ] );
113 113
         }
114
-        return $newActions + Arr::consolidateArray($actions);
114
+        return $newActions + Arr::consolidateArray( $actions );
115 115
     }
116 116
 
117 117
     /**
@@ -119,13 +119,13 @@  discard block
 block discarded – undo
119 119
      * @return array
120 120
      * @filter manage_edit-.Application::POST_TYPE._sortable_columns
121 121
      */
122
-    public function filterSortableColumns($columns)
122
+    public function filterSortableColumns( $columns )
123 123
     {
124
-        $columns = Arr::consolidateArray($columns);
124
+        $columns = Arr::consolidateArray( $columns );
125 125
         $postTypeColumns = glsr()->postTypeColumns[Application::POST_TYPE];
126 126
         unset($postTypeColumns['cb']);
127
-        foreach ($postTypeColumns as $key => $value) {
128
-            if (Str::startsWith('taxonomy', $key)) {
127
+        foreach( $postTypeColumns as $key => $value ) {
128
+            if( Str::startsWith( 'taxonomy', $key ) ) {
129 129
                 continue;
130 130
             }
131 131
             $columns[$key] = $key;
@@ -139,10 +139,10 @@  discard block
 block discarded – undo
139 139
      * @return void
140 140
      * @action bulk_edit_custom_box
141 141
      */
142
-    public function renderBulkEditFields($columnName, $postType)
142
+    public function renderBulkEditFields( $columnName, $postType )
143 143
     {
144
-        if ('assigned_to' == $columnName && Application::POST_TYPE == $postType) {
145
-            glsr()->render('partials/editor/bulk-edit-assigned-to');
144
+        if( 'assigned_to' == $columnName && Application::POST_TYPE == $postType ) {
145
+            glsr()->render( 'partials/editor/bulk-edit-assigned-to' );
146 146
         }
147 147
     }
148 148
 
@@ -151,9 +151,9 @@  discard block
 block discarded – undo
151 151
      * @return void
152 152
      * @action restrict_manage_posts
153 153
      */
154
-    public function renderColumnFilters($postType)
154
+    public function renderColumnFilters( $postType )
155 155
     {
156
-        glsr(Columns::class)->renderFilters($postType);
156
+        glsr( Columns::class )->renderFilters( $postType );
157 157
     }
158 158
 
159 159
     /**
@@ -162,9 +162,9 @@  discard block
 block discarded – undo
162 162
      * @return void
163 163
      * @action manage_posts_custom_column
164 164
      */
165
-    public function renderColumnValues($column, $postId)
165
+    public function renderColumnValues( $column, $postId )
166 166
     {
167
-        glsr(Columns::class)->renderValues($column, $postId);
167
+        glsr( Columns::class )->renderValues( $column, $postId );
168 168
     }
169 169
 
170 170
     /**
@@ -172,14 +172,14 @@  discard block
 block discarded – undo
172 172
      * @return void
173 173
      * @action save_post_.Application::POST_TYPE
174 174
      */
175
-    public function saveBulkEditFields($postId)
175
+    public function saveBulkEditFields( $postId )
176 176
     {
177
-        if (!current_user_can('edit_posts')) {
177
+        if( !current_user_can( 'edit_posts' ) ) {
178 178
             return;
179 179
         }
180
-        $assignedTo = filter_input(INPUT_GET, 'assigned_to');
181
-        if ($assignedTo && get_post($assignedTo)) {
182
-            glsr(Database::class)->update($postId, 'assigned_to', $assignedTo);
180
+        $assignedTo = filter_input( INPUT_GET, 'assigned_to' );
181
+        if( $assignedTo && get_post( $assignedTo ) ) {
182
+            glsr( Database::class )->update( $postId, 'assigned_to', $assignedTo );
183 183
         }
184 184
     }
185 185
 
@@ -187,15 +187,15 @@  discard block
 block discarded – undo
187 187
      * @return void
188 188
      * @action pre_get_posts
189 189
      */
190
-    public function setQueryForColumn(WP_Query $query)
190
+    public function setQueryForColumn( WP_Query $query )
191 191
     {
192
-        if (!$this->hasPermission($query)) {
192
+        if( !$this->hasPermission( $query ) ) {
193 193
             return;
194 194
         }
195
-        $this->setMetaQuery($query, [
195
+        $this->setMetaQuery( $query, [
196 196
             'rating', 'review_type',
197
-        ]);
198
-        $this->setOrderby($query);
197
+        ] );
198
+        $this->setOrderby( $query );
199 199
     }
200 200
 
201 201
     /**
@@ -204,15 +204,15 @@  discard block
 block discarded – undo
204 204
      */
205 205
     public function unapprove()
206 206
     {
207
-        if (Application::ID != filter_input(INPUT_GET, 'plugin')) {
207
+        if( Application::ID != filter_input( INPUT_GET, 'plugin' ) ) {
208 208
             return;
209 209
         }
210
-        check_admin_referer('unapprove-review_'.($postId = $this->getPostId()));
211
-        wp_update_post([
210
+        check_admin_referer( 'unapprove-review_'.($postId = $this->getPostId()) );
211
+        wp_update_post( [
212 212
             'ID' => $postId,
213 213
             'post_status' => 'pending',
214
-        ]);
215
-        wp_safe_redirect(wp_get_referer());
214
+        ] );
215
+        wp_safe_redirect( wp_get_referer() );
216 216
         exit;
217 217
     }
218 218
 
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
      * @param string $domain
222 222
      * @return bool
223 223
      */
224
-    protected function canModifyTranslation($domain = 'default')
224
+    protected function canModifyTranslation( $domain = 'default' )
225 225
     {
226 226
         $screen = glsr_current_screen();
227 227
         return 'default' == $domain
@@ -232,48 +232,48 @@  discard block
 block discarded – undo
232 232
     /**
233 233
      * @return bool
234 234
      */
235
-    protected function hasPermission(WP_Query $query)
235
+    protected function hasPermission( WP_Query $query )
236 236
     {
237 237
         global $pagenow;
238 238
         return is_admin()
239 239
             && $query->is_main_query()
240
-            && Application::POST_TYPE == $query->get('post_type')
240
+            && Application::POST_TYPE == $query->get( 'post_type' )
241 241
             && 'edit.php' == $pagenow;
242 242
     }
243 243
 
244 244
     /**
245 245
      * @return void
246 246
      */
247
-    protected function setMetaQuery(WP_Query $query, array $metaKeys)
247
+    protected function setMetaQuery( WP_Query $query, array $metaKeys )
248 248
     {
249
-        foreach ($metaKeys as $key) {
250
-            $value = (string) filter_input(INPUT_GET, $key);
251
-            if ('' === $value) {
249
+        foreach( $metaKeys as $key ) {
250
+            $value = (string)filter_input( INPUT_GET, $key );
251
+            if( '' === $value ) {
252 252
                 continue;
253 253
             }
254
-            $metaQuery = (array) $query->get('meta_query');
254
+            $metaQuery = (array)$query->get( 'meta_query' );
255 255
             $metaQuery[] = [
256
-                'key' => Str::prefix('_', $key, '_'),
256
+                'key' => Str::prefix( '_', $key, '_' ),
257 257
                 'value' => $value,
258 258
             ];
259
-            $query->set('meta_query', array_filter($metaQuery));
259
+            $query->set( 'meta_query', array_filter( $metaQuery ) );
260 260
         }
261 261
     }
262 262
 
263 263
     /**
264 264
      * @return void
265 265
      */
266
-    protected function setOrderby(WP_Query $query)
266
+    protected function setOrderby( WP_Query $query )
267 267
     {
268
-        $orderby = $query->get('orderby');
268
+        $orderby = $query->get( 'orderby' );
269 269
         $columns = glsr()->postTypeColumns[Application::POST_TYPE];
270 270
         unset($columns['cb'], $columns['title'], $columns['date']);
271
-        if (in_array($orderby, array_keys($columns))) {
272
-            if ('reviewer' == $orderby) {
271
+        if( in_array( $orderby, array_keys( $columns ) ) ) {
272
+            if( 'reviewer' == $orderby ) {
273 273
                 $orderby = 'author';
274 274
             }
275
-            $query->set('meta_key', Str::prefix('_', $orderby, '_'));
276
-            $query->set('orderby', 'meta_value');
275
+            $query->set( 'meta_key', Str::prefix( '_', $orderby, '_' ) );
276
+            $query->set( 'orderby', 'meta_value' );
277 277
         }
278 278
     }
279 279
 }
Please login to merge, or discard this patch.
plugin/Database.php 2 patches
Indentation   +155 added lines, -155 removed lines patch added patch discarded remove patch
@@ -12,168 +12,168 @@
 block discarded – undo
12 12
 
13 13
 class Database
14 14
 {
15
-    /**
16
-     * @param int $postId
17
-     * @param string $key
18
-     * @param bool $single
19
-     * @return mixed
20
-     */
21
-    public function get($postId, $key, $single = true)
22
-    {
23
-        $key = Str::prefix('_', $key);
24
-        return get_post_meta(intval($postId), $key, $single);
25
-    }
15
+	/**
16
+	 * @param int $postId
17
+	 * @param string $key
18
+	 * @param bool $single
19
+	 * @return mixed
20
+	 */
21
+	public function get($postId, $key, $single = true)
22
+	{
23
+		$key = Str::prefix('_', $key);
24
+		return get_post_meta(intval($postId), $key, $single);
25
+	}
26 26
 
27
-    /**
28
-     * @param int $postId
29
-     * @param string $assignedTo
30
-     * @return void|WP_Post
31
-     */
32
-    public function getAssignedToPost($postId, $assignedTo = '')
33
-    {
34
-        if (empty($assignedTo)) {
35
-            $assignedTo = $this->get($postId, 'assigned_to');
36
-        }
37
-        if (empty($assignedTo)) {
38
-            return;
39
-        }
40
-        $assignedPost = get_post($assignedTo);
41
-        if ($assignedPost instanceof WP_Post && $assignedPost->ID != $postId) {
42
-            return $assignedPost;
43
-        }
44
-    }
27
+	/**
28
+	 * @param int $postId
29
+	 * @param string $assignedTo
30
+	 * @return void|WP_Post
31
+	 */
32
+	public function getAssignedToPost($postId, $assignedTo = '')
33
+	{
34
+		if (empty($assignedTo)) {
35
+			$assignedTo = $this->get($postId, 'assigned_to');
36
+		}
37
+		if (empty($assignedTo)) {
38
+			return;
39
+		}
40
+		$assignedPost = get_post($assignedTo);
41
+		if ($assignedPost instanceof WP_Post && $assignedPost->ID != $postId) {
42
+			return $assignedPost;
43
+		}
44
+	}
45 45
 
46
-    /**
47
-     * @param string $metaKey
48
-     * @param string $metaValue
49
-     * @return array|int
50
-     */
51
-    public function getReviewCount($metaKey = '', $metaValue = '')
52
-    {
53
-        if (!$metaKey) {
54
-            return (array) wp_count_posts(Application::POST_TYPE);
55
-        }
56
-        $counts = glsr(Cache::class)->getReviewCountsFor($metaKey);
57
-        if (!$metaValue) {
58
-            return $counts;
59
-        }
60
-        return Arr::get($counts, $metaValue, 0);
61
-    }
46
+	/**
47
+	 * @param string $metaKey
48
+	 * @param string $metaValue
49
+	 * @return array|int
50
+	 */
51
+	public function getReviewCount($metaKey = '', $metaValue = '')
52
+	{
53
+		if (!$metaKey) {
54
+			return (array) wp_count_posts(Application::POST_TYPE);
55
+		}
56
+		$counts = glsr(Cache::class)->getReviewCountsFor($metaKey);
57
+		if (!$metaValue) {
58
+			return $counts;
59
+		}
60
+		return Arr::get($counts, $metaValue, 0);
61
+	}
62 62
 
63
-    /**
64
-     * @param string $metaReviewType
65
-     * @return array
66
-     */
67
-    public function getReviewIdsByType($metaReviewType)
68
-    {
69
-        return glsr(SqlQueries::class)->getReviewIdsByType($metaReviewType);
70
-    }
63
+	/**
64
+	 * @param string $metaReviewType
65
+	 * @return array
66
+	 */
67
+	public function getReviewIdsByType($metaReviewType)
68
+	{
69
+		return glsr(SqlQueries::class)->getReviewIdsByType($metaReviewType);
70
+	}
71 71
 
72
-    /**
73
-     * @param string $key
74
-     * @param string $status
75
-     * @return array
76
-     */
77
-    public function getReviewsMeta($key, $status = 'publish')
78
-    {
79
-        return glsr(SqlQueries::class)->getReviewsMeta($key, $status);
80
-    }
72
+	/**
73
+	 * @param string $key
74
+	 * @param string $status
75
+	 * @return array
76
+	 */
77
+	public function getReviewsMeta($key, $status = 'publish')
78
+	{
79
+		return glsr(SqlQueries::class)->getReviewsMeta($key, $status);
80
+	}
81 81
 
82
-    /**
83
-     * @param string $field
84
-     * @return array
85
-     */
86
-    public function getTermIds(array $values, $field)
87
-    {
88
-        $termIds = [];
89
-        foreach ($values as $value) {
90
-            $term = get_term_by($field, $value, Application::TAXONOMY);
91
-            if (!isset($term->term_id)) {
92
-                continue;
93
-            }
94
-            $termIds[] = $term->term_id;
95
-        }
96
-        return $termIds;
97
-    }
82
+	/**
83
+	 * @param string $field
84
+	 * @return array
85
+	 */
86
+	public function getTermIds(array $values, $field)
87
+	{
88
+		$termIds = [];
89
+		foreach ($values as $value) {
90
+			$term = get_term_by($field, $value, Application::TAXONOMY);
91
+			if (!isset($term->term_id)) {
92
+				continue;
93
+			}
94
+			$termIds[] = $term->term_id;
95
+		}
96
+		return $termIds;
97
+	}
98 98
 
99
-    /**
100
-     * @return array
101
-     */
102
-    public function getTerms(array $args = [])
103
-    {
104
-        $args = wp_parse_args($args, [
105
-            'count' => false,
106
-            'fields' => 'id=>name',
107
-            'hide_empty' => false,
108
-            'taxonomy' => Application::TAXONOMY,
109
-        ]);
110
-        $terms = get_terms($args);
111
-        if (is_wp_error($terms)) {
112
-            glsr_log()->error($terms->get_error_message());
113
-            return [];
114
-        }
115
-        return $terms;
116
-    }
99
+	/**
100
+	 * @return array
101
+	 */
102
+	public function getTerms(array $args = [])
103
+	{
104
+		$args = wp_parse_args($args, [
105
+			'count' => false,
106
+			'fields' => 'id=>name',
107
+			'hide_empty' => false,
108
+			'taxonomy' => Application::TAXONOMY,
109
+		]);
110
+		$terms = get_terms($args);
111
+		if (is_wp_error($terms)) {
112
+			glsr_log()->error($terms->get_error_message());
113
+			return [];
114
+		}
115
+		return $terms;
116
+	}
117 117
 
118
-    /**
119
-     * @param string $searchTerm
120
-     * @return void|string
121
-     */
122
-    public function searchPosts($searchTerm)
123
-    {
124
-        $args = [
125
-            'post_status' => 'publish',
126
-            'post_type' => 'any',
127
-        ];
128
-        if (is_numeric($searchTerm)) {
129
-            $args['post__in'] = [$searchTerm];
130
-        } else {
131
-            $args['orderby'] = 'relevance';
132
-            $args['posts_per_page'] = 10;
133
-            $args['s'] = $searchTerm;
134
-        }
135
-        $queryBuilder = glsr(QueryBuilder::class);
136
-        add_filter('posts_search', [$queryBuilder, 'filterSearchByTitle'], 500, 2);
137
-        $search = new WP_Query($args);
138
-        remove_filter('posts_search', [$queryBuilder, 'filterSearchByTitle'], 500);
139
-        if (!$search->have_posts()) {
140
-            return;
141
-        }
142
-        $results = '';
143
-        while ($search->have_posts()) {
144
-            $search->the_post();
145
-            ob_start();
146
-            glsr()->render('partials/editor/search-result', [
147
-                'ID' => get_the_ID(),
148
-                'permalink' => esc_url((string) get_permalink()),
149
-                'title' => esc_attr(get_the_title()),
150
-            ]);
151
-            $results.= ob_get_clean();
152
-        }
153
-        wp_reset_postdata();
154
-        return $results;
155
-    }
118
+	/**
119
+	 * @param string $searchTerm
120
+	 * @return void|string
121
+	 */
122
+	public function searchPosts($searchTerm)
123
+	{
124
+		$args = [
125
+			'post_status' => 'publish',
126
+			'post_type' => 'any',
127
+		];
128
+		if (is_numeric($searchTerm)) {
129
+			$args['post__in'] = [$searchTerm];
130
+		} else {
131
+			$args['orderby'] = 'relevance';
132
+			$args['posts_per_page'] = 10;
133
+			$args['s'] = $searchTerm;
134
+		}
135
+		$queryBuilder = glsr(QueryBuilder::class);
136
+		add_filter('posts_search', [$queryBuilder, 'filterSearchByTitle'], 500, 2);
137
+		$search = new WP_Query($args);
138
+		remove_filter('posts_search', [$queryBuilder, 'filterSearchByTitle'], 500);
139
+		if (!$search->have_posts()) {
140
+			return;
141
+		}
142
+		$results = '';
143
+		while ($search->have_posts()) {
144
+			$search->the_post();
145
+			ob_start();
146
+			glsr()->render('partials/editor/search-result', [
147
+				'ID' => get_the_ID(),
148
+				'permalink' => esc_url((string) get_permalink()),
149
+				'title' => esc_attr(get_the_title()),
150
+			]);
151
+			$results.= ob_get_clean();
152
+		}
153
+		wp_reset_postdata();
154
+		return $results;
155
+	}
156 156
 
157
-    /**
158
-     * @param int $postId
159
-     * @param string $key
160
-     * @param mixed $value
161
-     * @return int|bool
162
-     */
163
-    public function set($postId, $key, $value)
164
-    {
165
-        $key = Str::prefix('_', $key);
166
-        return update_post_meta($postId, $key, $value);
167
-    }
157
+	/**
158
+	 * @param int $postId
159
+	 * @param string $key
160
+	 * @param mixed $value
161
+	 * @return int|bool
162
+	 */
163
+	public function set($postId, $key, $value)
164
+	{
165
+		$key = Str::prefix('_', $key);
166
+		return update_post_meta($postId, $key, $value);
167
+	}
168 168
 
169
-    /**
170
-     * @param int $postId
171
-     * @param string $key
172
-     * @param mixed $value
173
-     * @return int|bool
174
-     */
175
-    public function update($postId, $key, $value)
176
-    {
177
-        return $this->set($postId, $key, $value);
178
-    }
169
+	/**
170
+	 * @param int $postId
171
+	 * @param string $key
172
+	 * @param mixed $value
173
+	 * @return int|bool
174
+	 */
175
+	public function update($postId, $key, $value)
176
+	{
177
+		return $this->set($postId, $key, $value);
178
+	}
179 179
 }
Please login to merge, or discard this patch.
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -18,10 +18,10 @@  discard block
 block discarded – undo
18 18
      * @param bool $single
19 19
      * @return mixed
20 20
      */
21
-    public function get($postId, $key, $single = true)
21
+    public function get( $postId, $key, $single = true )
22 22
     {
23
-        $key = Str::prefix('_', $key);
24
-        return get_post_meta(intval($postId), $key, $single);
23
+        $key = Str::prefix( '_', $key );
24
+        return get_post_meta( intval( $postId ), $key, $single );
25 25
     }
26 26
 
27 27
     /**
@@ -29,16 +29,16 @@  discard block
 block discarded – undo
29 29
      * @param string $assignedTo
30 30
      * @return void|WP_Post
31 31
      */
32
-    public function getAssignedToPost($postId, $assignedTo = '')
32
+    public function getAssignedToPost( $postId, $assignedTo = '' )
33 33
     {
34
-        if (empty($assignedTo)) {
35
-            $assignedTo = $this->get($postId, 'assigned_to');
34
+        if( empty($assignedTo) ) {
35
+            $assignedTo = $this->get( $postId, 'assigned_to' );
36 36
         }
37
-        if (empty($assignedTo)) {
37
+        if( empty($assignedTo) ) {
38 38
             return;
39 39
         }
40
-        $assignedPost = get_post($assignedTo);
41
-        if ($assignedPost instanceof WP_Post && $assignedPost->ID != $postId) {
40
+        $assignedPost = get_post( $assignedTo );
41
+        if( $assignedPost instanceof WP_Post && $assignedPost->ID != $postId ) {
42 42
             return $assignedPost;
43 43
         }
44 44
     }
@@ -48,25 +48,25 @@  discard block
 block discarded – undo
48 48
      * @param string $metaValue
49 49
      * @return array|int
50 50
      */
51
-    public function getReviewCount($metaKey = '', $metaValue = '')
51
+    public function getReviewCount( $metaKey = '', $metaValue = '' )
52 52
     {
53
-        if (!$metaKey) {
54
-            return (array) wp_count_posts(Application::POST_TYPE);
53
+        if( !$metaKey ) {
54
+            return (array)wp_count_posts( Application::POST_TYPE );
55 55
         }
56
-        $counts = glsr(Cache::class)->getReviewCountsFor($metaKey);
57
-        if (!$metaValue) {
56
+        $counts = glsr( Cache::class )->getReviewCountsFor( $metaKey );
57
+        if( !$metaValue ) {
58 58
             return $counts;
59 59
         }
60
-        return Arr::get($counts, $metaValue, 0);
60
+        return Arr::get( $counts, $metaValue, 0 );
61 61
     }
62 62
 
63 63
     /**
64 64
      * @param string $metaReviewType
65 65
      * @return array
66 66
      */
67
-    public function getReviewIdsByType($metaReviewType)
67
+    public function getReviewIdsByType( $metaReviewType )
68 68
     {
69
-        return glsr(SqlQueries::class)->getReviewIdsByType($metaReviewType);
69
+        return glsr( SqlQueries::class )->getReviewIdsByType( $metaReviewType );
70 70
     }
71 71
 
72 72
     /**
@@ -74,21 +74,21 @@  discard block
 block discarded – undo
74 74
      * @param string $status
75 75
      * @return array
76 76
      */
77
-    public function getReviewsMeta($key, $status = 'publish')
77
+    public function getReviewsMeta( $key, $status = 'publish' )
78 78
     {
79
-        return glsr(SqlQueries::class)->getReviewsMeta($key, $status);
79
+        return glsr( SqlQueries::class )->getReviewsMeta( $key, $status );
80 80
     }
81 81
 
82 82
     /**
83 83
      * @param string $field
84 84
      * @return array
85 85
      */
86
-    public function getTermIds(array $values, $field)
86
+    public function getTermIds( array $values, $field )
87 87
     {
88 88
         $termIds = [];
89
-        foreach ($values as $value) {
90
-            $term = get_term_by($field, $value, Application::TAXONOMY);
91
-            if (!isset($term->term_id)) {
89
+        foreach( $values as $value ) {
90
+            $term = get_term_by( $field, $value, Application::TAXONOMY );
91
+            if( !isset($term->term_id) ) {
92 92
                 continue;
93 93
             }
94 94
             $termIds[] = $term->term_id;
@@ -99,17 +99,17 @@  discard block
 block discarded – undo
99 99
     /**
100 100
      * @return array
101 101
      */
102
-    public function getTerms(array $args = [])
102
+    public function getTerms( array $args = [] )
103 103
     {
104
-        $args = wp_parse_args($args, [
104
+        $args = wp_parse_args( $args, [
105 105
             'count' => false,
106 106
             'fields' => 'id=>name',
107 107
             'hide_empty' => false,
108 108
             'taxonomy' => Application::TAXONOMY,
109
-        ]);
110
-        $terms = get_terms($args);
111
-        if (is_wp_error($terms)) {
112
-            glsr_log()->error($terms->get_error_message());
109
+        ] );
110
+        $terms = get_terms( $args );
111
+        if( is_wp_error( $terms ) ) {
112
+            glsr_log()->error( $terms->get_error_message() );
113 113
             return [];
114 114
         }
115 115
         return $terms;
@@ -119,36 +119,36 @@  discard block
 block discarded – undo
119 119
      * @param string $searchTerm
120 120
      * @return void|string
121 121
      */
122
-    public function searchPosts($searchTerm)
122
+    public function searchPosts( $searchTerm )
123 123
     {
124 124
         $args = [
125 125
             'post_status' => 'publish',
126 126
             'post_type' => 'any',
127 127
         ];
128
-        if (is_numeric($searchTerm)) {
128
+        if( is_numeric( $searchTerm ) ) {
129 129
             $args['post__in'] = [$searchTerm];
130 130
         } else {
131 131
             $args['orderby'] = 'relevance';
132 132
             $args['posts_per_page'] = 10;
133 133
             $args['s'] = $searchTerm;
134 134
         }
135
-        $queryBuilder = glsr(QueryBuilder::class);
136
-        add_filter('posts_search', [$queryBuilder, 'filterSearchByTitle'], 500, 2);
137
-        $search = new WP_Query($args);
138
-        remove_filter('posts_search', [$queryBuilder, 'filterSearchByTitle'], 500);
139
-        if (!$search->have_posts()) {
135
+        $queryBuilder = glsr( QueryBuilder::class );
136
+        add_filter( 'posts_search', [$queryBuilder, 'filterSearchByTitle'], 500, 2 );
137
+        $search = new WP_Query( $args );
138
+        remove_filter( 'posts_search', [$queryBuilder, 'filterSearchByTitle'], 500 );
139
+        if( !$search->have_posts() ) {
140 140
             return;
141 141
         }
142 142
         $results = '';
143
-        while ($search->have_posts()) {
143
+        while( $search->have_posts() ) {
144 144
             $search->the_post();
145 145
             ob_start();
146
-            glsr()->render('partials/editor/search-result', [
146
+            glsr()->render( 'partials/editor/search-result', [
147 147
                 'ID' => get_the_ID(),
148
-                'permalink' => esc_url((string) get_permalink()),
149
-                'title' => esc_attr(get_the_title()),
150
-            ]);
151
-            $results.= ob_get_clean();
148
+                'permalink' => esc_url( (string)get_permalink() ),
149
+                'title' => esc_attr( get_the_title() ),
150
+            ] );
151
+            $results .= ob_get_clean();
152 152
         }
153 153
         wp_reset_postdata();
154 154
         return $results;
@@ -160,10 +160,10 @@  discard block
 block discarded – undo
160 160
      * @param mixed $value
161 161
      * @return int|bool
162 162
      */
163
-    public function set($postId, $key, $value)
163
+    public function set( $postId, $key, $value )
164 164
     {
165
-        $key = Str::prefix('_', $key);
166
-        return update_post_meta($postId, $key, $value);
165
+        $key = Str::prefix( '_', $key );
166
+        return update_post_meta( $postId, $key, $value );
167 167
     }
168 168
 
169 169
     /**
@@ -172,8 +172,8 @@  discard block
 block discarded – undo
172 172
      * @param mixed $value
173 173
      * @return int|bool
174 174
      */
175
-    public function update($postId, $key, $value)
175
+    public function update( $postId, $key, $value )
176 176
     {
177
-        return $this->set($postId, $key, $value);
177
+        return $this->set( $postId, $key, $value );
178 178
     }
179 179
 }
Please login to merge, or discard this patch.
plugin/Shortcodes/SiteReviewsFormShortcode.php 2 patches
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -6,29 +6,29 @@
 block discarded – undo
6 6
 
7 7
 class SiteReviewsFormShortcode extends Shortcode
8 8
 {
9
-    protected function hideOptions()
10
-    {
11
-        return [
12
-            'rating' => __('Hide the rating field', 'site-reviews'),
13
-            'title' => __('Hide the title field', 'site-reviews'),
14
-            'content' => __('Hide the review field', 'site-reviews'),
15
-            'name' => __('Hide the name field', 'site-reviews'),
16
-            'email' => __('Hide the email field', 'site-reviews'),
17
-            'terms' => __('Hide the terms field', 'site-reviews'),
18
-        ];
19
-    }
9
+	protected function hideOptions()
10
+	{
11
+		return [
12
+			'rating' => __('Hide the rating field', 'site-reviews'),
13
+			'title' => __('Hide the title field', 'site-reviews'),
14
+			'content' => __('Hide the review field', 'site-reviews'),
15
+			'name' => __('Hide the name field', 'site-reviews'),
16
+			'email' => __('Hide the email field', 'site-reviews'),
17
+			'terms' => __('Hide the terms field', 'site-reviews'),
18
+		];
19
+	}
20 20
 
21
-    /**
22
-     * @param array|string $atts
23
-     * @param string $type
24
-     * @return array
25
-     */
26
-    public function normalizeAtts($atts, $type = 'shortcode')
27
-    {
28
-        $atts = parent::normalizeAtts($atts, $type);
29
-        if (empty($atts['id'])) {
30
-            $atts['id'] = Application::PREFIX.substr(md5(serialize($atts)), 0, 8);
31
-        }
32
-        return $atts;
33
-    }
21
+	/**
22
+	 * @param array|string $atts
23
+	 * @param string $type
24
+	 * @return array
25
+	 */
26
+	public function normalizeAtts($atts, $type = 'shortcode')
27
+	{
28
+		$atts = parent::normalizeAtts($atts, $type);
29
+		if (empty($atts['id'])) {
30
+			$atts['id'] = Application::PREFIX.substr(md5(serialize($atts)), 0, 8);
31
+		}
32
+		return $atts;
33
+	}
34 34
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -9,12 +9,12 @@  discard block
 block discarded – undo
9 9
     protected function hideOptions()
10 10
     {
11 11
         return [
12
-            'rating' => __('Hide the rating field', 'site-reviews'),
13
-            'title' => __('Hide the title field', 'site-reviews'),
14
-            'content' => __('Hide the review field', 'site-reviews'),
15
-            'name' => __('Hide the name field', 'site-reviews'),
16
-            'email' => __('Hide the email field', 'site-reviews'),
17
-            'terms' => __('Hide the terms field', 'site-reviews'),
12
+            'rating' => __( 'Hide the rating field', 'site-reviews' ),
13
+            'title' => __( 'Hide the title field', 'site-reviews' ),
14
+            'content' => __( 'Hide the review field', 'site-reviews' ),
15
+            'name' => __( 'Hide the name field', 'site-reviews' ),
16
+            'email' => __( 'Hide the email field', 'site-reviews' ),
17
+            'terms' => __( 'Hide the terms field', 'site-reviews' ),
18 18
         ];
19 19
     }
20 20
 
@@ -23,11 +23,11 @@  discard block
 block discarded – undo
23 23
      * @param string $type
24 24
      * @return array
25 25
      */
26
-    public function normalizeAtts($atts, $type = 'shortcode')
26
+    public function normalizeAtts( $atts, $type = 'shortcode' )
27 27
     {
28
-        $atts = parent::normalizeAtts($atts, $type);
29
-        if (empty($atts['id'])) {
30
-            $atts['id'] = Application::PREFIX.substr(md5(serialize($atts)), 0, 8);
28
+        $atts = parent::normalizeAtts( $atts, $type );
29
+        if( empty($atts['id']) ) {
30
+            $atts['id'] = Application::PREFIX.substr( md5( serialize( $atts ) ), 0, 8 );
31 31
         }
32 32
         return $atts;
33 33
     }
Please login to merge, or discard this patch.