Passed
Push — master ( 925e6d...054ae2 )
by Paul
08:03 queued 03:39
created
plugin/Modules/Schema/BaseType.php 1 patch
Indentation   +221 added lines, -221 removed lines patch added patch discarded remove patch
@@ -13,248 +13,248 @@
 block discarded – undo
13 13
 
14 14
 abstract class BaseType implements ArrayAccess, JsonSerializable, Type
15 15
 {
16
-    /**
17
-     * @var array
18
-     */
19
-    public $allowed = [];
16
+	/**
17
+	 * @var array
18
+	 */
19
+	public $allowed = [];
20 20
 
21
-    /**
22
-     * @var array
23
-     */
24
-    public $parents = [];
21
+	/**
22
+	 * @var array
23
+	 */
24
+	public $parents = [];
25 25
 
26
-    /**
27
-     * @var array
28
-     */
29
-    protected $properties = [];
26
+	/**
27
+	 * @var array
28
+	 */
29
+	protected $properties = [];
30 30
 
31
-    /**
32
-     * @var string
33
-     */
34
-    protected $type;
31
+	/**
32
+	 * @var string
33
+	 */
34
+	protected $type;
35 35
 
36
-    /**
37
-     * @param string $method
38
-     * @return static
39
-     */
40
-    public function __call($method, array $arguments)
41
-    {
42
-        return $this->setProperty($method, Arr::get($arguments, 0));
43
-    }
36
+	/**
37
+	 * @param string $method
38
+	 * @return static
39
+	 */
40
+	public function __call($method, array $arguments)
41
+	{
42
+		return $this->setProperty($method, Arr::get($arguments, 0));
43
+	}
44 44
 
45
-    /**
46
-     * @param string $type
47
-     */
48
-    public function __construct($type = null)
49
-    {
50
-        $this->type = !is_string($type)
51
-            ? (new ReflectionClass($this))->getShortName()
52
-            : $type;
53
-        $this->setAllowedProperties();
54
-    }
45
+	/**
46
+	 * @param string $type
47
+	 */
48
+	public function __construct($type = null)
49
+	{
50
+		$this->type = !is_string($type)
51
+			? (new ReflectionClass($this))->getShortName()
52
+			: $type;
53
+		$this->setAllowedProperties();
54
+	}
55 55
 
56
-    /**
57
-     * @return string
58
-     */
59
-    public function __toString()
60
-    {
61
-        return $this->toScript();
62
-    }
56
+	/**
57
+	 * @return string
58
+	 */
59
+	public function __toString()
60
+	{
61
+		return $this->toScript();
62
+	}
63 63
 
64
-    /**
65
-     * @return static
66
-     */
67
-    public function addProperties(array $properties)
68
-    {
69
-        foreach ($properties as $property => $value) {
70
-            $this->setProperty($property, $value);
71
-        }
72
-        return $this;
73
-    }
64
+	/**
65
+	 * @return static
66
+	 */
67
+	public function addProperties(array $properties)
68
+	{
69
+		foreach ($properties as $property => $value) {
70
+			$this->setProperty($property, $value);
71
+		}
72
+		return $this;
73
+	}
74 74
 
75
-    /**
76
-     * @return string
77
-     */
78
-    public function getContext()
79
-    {
80
-        return 'https://schema.org';
81
-    }
75
+	/**
76
+	 * @return string
77
+	 */
78
+	public function getContext()
79
+	{
80
+		return 'https://schema.org';
81
+	}
82 82
 
83
-    /**
84
-     * @return array
85
-     */
86
-    public function getProperties()
87
-    {
88
-        return $this->properties;
89
-    }
83
+	/**
84
+	 * @return array
85
+	 */
86
+	public function getProperties()
87
+	{
88
+		return $this->properties;
89
+	}
90 90
 
91
-    /**
92
-     * @param string $property
93
-     * @param mixed $default
94
-     * @return mixed
95
-     */
96
-    public function getProperty($property, $default = null)
97
-    {
98
-        return Arr::get($this->properties, $property, $default);
99
-    }
91
+	/**
92
+	 * @param string $property
93
+	 * @param mixed $default
94
+	 * @return mixed
95
+	 */
96
+	public function getProperty($property, $default = null)
97
+	{
98
+		return Arr::get($this->properties, $property, $default);
99
+	}
100 100
 
101
-    /**
102
-     * @return string
103
-     */
104
-    public function getType()
105
-    {
106
-        return $this->type;
107
-    }
101
+	/**
102
+	 * @return string
103
+	 */
104
+	public function getType()
105
+	{
106
+		return $this->type;
107
+	}
108 108
 
109
-    /**
110
-     * @param bool $condition
111
-     * @param mixed $callback
112
-     * @return static
113
-     */
114
-    public function doIf($condition, $callback)
115
-    {
116
-        if ($condition) {
117
-            $callback($this);
118
-        }
119
-        return $this;
120
-    }
109
+	/**
110
+	 * @param bool $condition
111
+	 * @param mixed $callback
112
+	 * @return static
113
+	 */
114
+	public function doIf($condition, $callback)
115
+	{
116
+		if ($condition) {
117
+			$callback($this);
118
+		}
119
+		return $this;
120
+	}
121 121
 
122
-    /**
123
-     * @return array
124
-     */
125
-    public function jsonSerialize()
126
-    {
127
-        return $this->toArray();
128
-    }
122
+	/**
123
+	 * @return array
124
+	 */
125
+	public function jsonSerialize()
126
+	{
127
+		return $this->toArray();
128
+	}
129 129
 
130
-    /**
131
-     * @param mixed $offset
132
-     * @return bool
133
-     */
134
-    public function offsetExists($offset)
135
-    {
136
-        return array_key_exists($offset, $this->properties);
137
-    }
130
+	/**
131
+	 * @param mixed $offset
132
+	 * @return bool
133
+	 */
134
+	public function offsetExists($offset)
135
+	{
136
+		return array_key_exists($offset, $this->properties);
137
+	}
138 138
 
139
-    /**
140
-     * @param string $offset
141
-     * @return mixed
142
-     */
143
-    public function offsetGet($offset)
144
-    {
145
-        return $this->getProperty($offset);
146
-    }
139
+	/**
140
+	 * @param string $offset
141
+	 * @return mixed
142
+	 */
143
+	public function offsetGet($offset)
144
+	{
145
+		return $this->getProperty($offset);
146
+	}
147 147
 
148
-    /**
149
-     * @param string $offset
150
-     * @param mixed $value
151
-     * @return void
152
-     */
153
-    public function offsetSet($offset, $value)
154
-    {
155
-        $this->setProperty($offset, $value);
156
-    }
148
+	/**
149
+	 * @param string $offset
150
+	 * @param mixed $value
151
+	 * @return void
152
+	 */
153
+	public function offsetSet($offset, $value)
154
+	{
155
+		$this->setProperty($offset, $value);
156
+	}
157 157
 
158
-    /**
159
-     * @param string $offset
160
-     * @return void
161
-     */
162
-    public function offsetUnset($offset)
163
-    {
164
-        unset($this->properties[$offset]);
165
-    }
158
+	/**
159
+	 * @param string $offset
160
+	 * @return void
161
+	 */
162
+	public function offsetUnset($offset)
163
+	{
164
+		unset($this->properties[$offset]);
165
+	}
166 166
 
167
-    /**
168
-     * @param string $property
169
-     * @param mixed $value
170
-     * @return static
171
-     */
172
-    public function setProperty($property, $value)
173
-    {
174
-        if (!in_array($property, $this->allowed)
175
-            && 'UnknownType' != (new ReflectionClass($this))->getShortName()) {
176
-            glsr_log()->warning($this->getType().' does not allow the "'.$property.'" property');
177
-            return $this;
178
-        }
179
-        $this->properties[$property] = $value;
180
-        return $this;
181
-    }
167
+	/**
168
+	 * @param string $property
169
+	 * @param mixed $value
170
+	 * @return static
171
+	 */
172
+	public function setProperty($property, $value)
173
+	{
174
+		if (!in_array($property, $this->allowed)
175
+			&& 'UnknownType' != (new ReflectionClass($this))->getShortName()) {
176
+			glsr_log()->warning($this->getType().' does not allow the "'.$property.'" property');
177
+			return $this;
178
+		}
179
+		$this->properties[$property] = $value;
180
+		return $this;
181
+	}
182 182
 
183
-    /**
184
-     * @return array
185
-     */
186
-    public function toArray()
187
-    {
188
-        return [
189
-            '@context' => $this->getContext(),
190
-            '@type' => $this->getType(),
191
-        ] + $this->serializeProperty($this->getProperties());
192
-    }
183
+	/**
184
+	 * @return array
185
+	 */
186
+	public function toArray()
187
+	{
188
+		return [
189
+			'@context' => $this->getContext(),
190
+			'@type' => $this->getType(),
191
+		] + $this->serializeProperty($this->getProperties());
192
+	}
193 193
 
194
-    /**
195
-     * @return string
196
-     */
197
-    public function toScript()
198
-    {
199
-        return sprintf('<script type="application/ld+json">%s</script>',
200
-            json_encode($this->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)
201
-        );
202
-    }
194
+	/**
195
+	 * @return string
196
+	 */
197
+	public function toScript()
198
+	{
199
+		return sprintf('<script type="application/ld+json">%s</script>',
200
+			json_encode($this->toArray(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)
201
+		);
202
+	}
203 203
 
204
-    /**
205
-     * @param array|null $parents
206
-     * @return array
207
-     */
208
-    protected function getParents($parents = null)
209
-    {
210
-        if (!isset($parents)) {
211
-            $parents = $this->parents;
212
-        }
213
-        $newParents = $parents;
214
-        foreach ($parents as $parent) {
215
-            $parentClass = Helper::buildClassName($parent, __NAMESPACE__);
216
-            if (!class_exists($parentClass)) {
217
-                continue;
218
-            }
219
-            $newParents = array_merge($newParents, $this->getParents((new $parentClass())->parents));
220
-        }
221
-        return array_values(array_unique($newParents));
222
-    }
204
+	/**
205
+	 * @param array|null $parents
206
+	 * @return array
207
+	 */
208
+	protected function getParents($parents = null)
209
+	{
210
+		if (!isset($parents)) {
211
+			$parents = $this->parents;
212
+		}
213
+		$newParents = $parents;
214
+		foreach ($parents as $parent) {
215
+			$parentClass = Helper::buildClassName($parent, __NAMESPACE__);
216
+			if (!class_exists($parentClass)) {
217
+				continue;
218
+			}
219
+			$newParents = array_merge($newParents, $this->getParents((new $parentClass())->parents));
220
+		}
221
+		return array_values(array_unique($newParents));
222
+	}
223 223
 
224
-    /**
225
-     * @return void
226
-     */
227
-    protected function setAllowedProperties()
228
-    {
229
-        $parents = $this->getParents();
230
-        foreach ($parents as $parent) {
231
-            $parentClass = Helper::buildClassName($parent, __NAMESPACE__);
232
-            if (!class_exists($parentClass)) {
233
-                continue;
234
-            }
235
-            $this->allowed = array_values(array_unique(array_merge((new $parentClass())->allowed, $this->allowed)));
236
-        }
237
-    }
224
+	/**
225
+	 * @return void
226
+	 */
227
+	protected function setAllowedProperties()
228
+	{
229
+		$parents = $this->getParents();
230
+		foreach ($parents as $parent) {
231
+			$parentClass = Helper::buildClassName($parent, __NAMESPACE__);
232
+			if (!class_exists($parentClass)) {
233
+				continue;
234
+			}
235
+			$this->allowed = array_values(array_unique(array_merge((new $parentClass())->allowed, $this->allowed)));
236
+		}
237
+	}
238 238
 
239
-    /**
240
-     * @param mixed $property
241
-     * @return array|string
242
-     */
243
-    protected function serializeProperty($property)
244
-    {
245
-        if (is_array($property)) {
246
-            return array_map([$this, 'serializeProperty'], $property);
247
-        }
248
-        if ($property instanceof Type) {
249
-            $property = $property->toArray();
250
-            unset($property['@context']);
251
-        }
252
-        if ($property instanceof DateTimeInterface) {
253
-            $property = $property->format(DateTime::ATOM);
254
-        }
255
-        if (is_object($property)) {
256
-            throw new InvalidProperty();
257
-        }
258
-        return $property;
259
-    }
239
+	/**
240
+	 * @param mixed $property
241
+	 * @return array|string
242
+	 */
243
+	protected function serializeProperty($property)
244
+	{
245
+		if (is_array($property)) {
246
+			return array_map([$this, 'serializeProperty'], $property);
247
+		}
248
+		if ($property instanceof Type) {
249
+			$property = $property->toArray();
250
+			unset($property['@context']);
251
+		}
252
+		if ($property instanceof DateTimeInterface) {
253
+			$property = $property->format(DateTime::ATOM);
254
+		}
255
+		if (is_object($property)) {
256
+			throw new InvalidProperty();
257
+		}
258
+		return $property;
259
+	}
260 260
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/Settings.php 1 patch
Indentation   +235 added lines, -235 removed lines patch added patch discarded remove patch
@@ -11,239 +11,239 @@
 block discarded – undo
11 11
 
12 12
 class Settings
13 13
 {
14
-    /**
15
-     * @var array
16
-     */
17
-    public $settings;
18
-
19
-    /**
20
-     * @param string $id
21
-     * @return string
22
-     */
23
-    public function buildFields($id)
24
-    {
25
-        $this->settings = glsr(DefaultsManager::class)->settings();
26
-        $method = Helper::buildMethodName($id, 'getTemplateDataFor');
27
-        $data = !method_exists($this, $method)
28
-            ? $this->getTemplateData($id)
29
-            : $this->$method($id);
30
-        return glsr(Template::class)->build('pages/settings/'.$id, $data);
31
-    }
32
-
33
-    /**
34
-     * @return string
35
-     */
36
-    protected function getFieldDefault(array $field)
37
-    {
38
-        return Arr::get($field, 'default');
39
-    }
40
-
41
-    /**
42
-     * @return string
43
-     */
44
-    protected function getFieldNameForDependsOn($path)
45
-    {
46
-        $fieldName = Str::convertPathToName($path, OptionManager::databaseKey());
47
-        return $this->isMultiDependency($path)
48
-            ? $fieldName.'[]'
49
-            : $fieldName;
50
-    }
51
-
52
-    /**
53
-     * @return array
54
-     */
55
-    protected function getSettingFields($path)
56
-    {
57
-        return array_filter($this->settings, function ($key) use ($path) {
58
-            return Str::startsWith($path, $key);
59
-        }, ARRAY_FILTER_USE_KEY);
60
-    }
61
-
62
-    /**
63
-     * @return string
64
-     */
65
-    protected function getSettingRows(array $fields)
66
-    {
67
-        $rows = '';
68
-        foreach ($fields as $name => $field) {
69
-            $field = wp_parse_args($field, [
70
-                'is_setting' => true,
71
-                'name' => $name,
72
-            ]);
73
-            $rows.= new Field($this->normalize($field));
74
-        }
75
-        return $rows;
76
-    }
77
-
78
-    /**
79
-     * @param string $id
80
-     * @return array
81
-     */
82
-    protected function getTemplateData($id)
83
-    {
84
-        $fields = $this->getSettingFields($this->normalizeSettingPath($id));
85
-        return [
86
-            'context' => [
87
-                'rows' => $this->getSettingRows($fields),
88
-            ],
89
-        ];
90
-    }
91
-
92
-    /**
93
-     * @param string $id
94
-     * @return array
95
-     */
96
-    protected function getTemplateDataForAddons($id)
97
-    {
98
-        $fields = $this->getSettingFields($this->normalizeSettingPath($id));
99
-        $settings = Arr::convertDotNotationArray($fields);
100
-        $settingKeys = array_keys($settings['settings']['addons']);
101
-        $results = [];
102
-        foreach ($settingKeys as $key) {
103
-            $addonFields = array_filter($fields, function ($path) use ($key) {
104
-                return Str::startsWith('settings.addons.'.$key, $path);
105
-            }, ARRAY_FILTER_USE_KEY);
106
-            $results[$key] = $this->getSettingRows($addonFields);
107
-        }
108
-        ksort($results);
109
-        return [
110
-            'settings' => $results,
111
-        ];
112
-    }
113
-
114
-    /**
115
-     * @param string $id
116
-     * @return array
117
-     */
118
-    protected function getTemplateDataForLicenses($id)
119
-    {
120
-        $fields = $this->getSettingFields($this->normalizeSettingPath($id));
121
-        ksort($fields);
122
-        return [
123
-            'context' => [
124
-                'rows' => $this->getSettingRows($fields),
125
-            ],
126
-        ];
127
-    }
128
-
129
-    /**
130
-     * @return array
131
-     */
132
-    protected function getTemplateDataForTranslations()
133
-    {
134
-        $translations = glsr(Translation::class)->renderAll();
135
-        $class = empty($translations)
136
-            ? 'glsr-hidden'
137
-            : '';
138
-        return [
139
-            'context' => [
140
-                'class' => $class,
141
-                'database_key' => OptionManager::databaseKey(),
142
-                'translations' => $translations,
143
-            ],
144
-        ];
145
-    }
146
-
147
-    /**
148
-     * @param string $path
149
-     * @param string|array $expectedValue
150
-     * @return bool
151
-     */
152
-    protected function isFieldHidden($path, $expectedValue)
153
-    {
154
-        $optionValue = glsr(OptionManager::class)->get(
155
-            $path,
156
-            Arr::get(glsr()->defaults, $path)
157
-        );
158
-        if (is_array($expectedValue)) {
159
-            return is_array($optionValue)
160
-                ? 0 === count(array_intersect($optionValue, $expectedValue))
161
-                : !in_array($optionValue, $expectedValue);
162
-        }
163
-        return $optionValue != $expectedValue;
164
-    }
165
-
166
-    /**
167
-     * @return bool
168
-     */
169
-    protected function isMultiDependency($path)
170
-    {
171
-        if (isset($this->settings[$path])) {
172
-            $field = $this->settings[$path];
173
-            return ('checkbox' == $field['type'] && !empty($field['options']))
174
-                || !empty($field['multiple']);
175
-        }
176
-        return false;
177
-    }
178
-
179
-    /**
180
-     * @return array
181
-     */
182
-    protected function normalize(array $field)
183
-    {
184
-        $field = $this->normalizeDependsOn($field);
185
-        $field = $this->normalizeLabelAndLegend($field);
186
-        $field = $this->normalizeValue($field);
187
-        return $field;
188
-    }
189
-
190
-    /**
191
-     * @return array
192
-     */
193
-    protected function normalizeDependsOn(array $field)
194
-    {
195
-        if (!empty($field['depends_on']) && is_array($field['depends_on'])) {
196
-            $isFieldHidden = false;
197
-            $conditions = [];
198
-            foreach ($field['depends_on'] as $path => $value) {
199
-                $conditions[] = [
200
-                    'name' => $this->getFieldNameForDependsOn($path),
201
-                    'value' => $value,
202
-                ];
203
-                if ($this->isFieldHidden($path, $value)) {
204
-                    $isFieldHidden = true;
205
-                }
206
-            }
207
-            $field['data-depends'] = json_encode($conditions, JSON_HEX_APOS | JSON_HEX_QUOT);
208
-            $field['is_hidden'] = $isFieldHidden;
209
-        }
210
-        return $field;
211
-    }
212
-
213
-    /**
214
-     * @return array
215
-     */
216
-    protected function normalizeLabelAndLegend(array $field)
217
-    {
218
-        if (!empty($field['label'])) {
219
-            $field['legend'] = $field['label'];
220
-            unset($field['label']);
221
-        } else {
222
-            $field['is_valid'] = false;
223
-            glsr_log()->warning('Setting field is missing a label')->debug($field);
224
-        }
225
-        return $field;
226
-    }
227
-
228
-    /**
229
-     * @return array
230
-     */
231
-    protected function normalizeValue(array $field)
232
-    {
233
-        if (!isset($field['value'])) {
234
-            $field['value'] = glsr(OptionManager::class)->get(
235
-                $field['name'],
236
-                $this->getFieldDefault($field)
237
-            );
238
-        }
239
-        return $field;
240
-    }
241
-
242
-    /**
243
-     * @return string
244
-     */
245
-    protected function normalizeSettingPath($path)
246
-    {
247
-        return Str::prefix('settings.', rtrim($path, '.'));
248
-    }
14
+	/**
15
+	 * @var array
16
+	 */
17
+	public $settings;
18
+
19
+	/**
20
+	 * @param string $id
21
+	 * @return string
22
+	 */
23
+	public function buildFields($id)
24
+	{
25
+		$this->settings = glsr(DefaultsManager::class)->settings();
26
+		$method = Helper::buildMethodName($id, 'getTemplateDataFor');
27
+		$data = !method_exists($this, $method)
28
+			? $this->getTemplateData($id)
29
+			: $this->$method($id);
30
+		return glsr(Template::class)->build('pages/settings/'.$id, $data);
31
+	}
32
+
33
+	/**
34
+	 * @return string
35
+	 */
36
+	protected function getFieldDefault(array $field)
37
+	{
38
+		return Arr::get($field, 'default');
39
+	}
40
+
41
+	/**
42
+	 * @return string
43
+	 */
44
+	protected function getFieldNameForDependsOn($path)
45
+	{
46
+		$fieldName = Str::convertPathToName($path, OptionManager::databaseKey());
47
+		return $this->isMultiDependency($path)
48
+			? $fieldName.'[]'
49
+			: $fieldName;
50
+	}
51
+
52
+	/**
53
+	 * @return array
54
+	 */
55
+	protected function getSettingFields($path)
56
+	{
57
+		return array_filter($this->settings, function ($key) use ($path) {
58
+			return Str::startsWith($path, $key);
59
+		}, ARRAY_FILTER_USE_KEY);
60
+	}
61
+
62
+	/**
63
+	 * @return string
64
+	 */
65
+	protected function getSettingRows(array $fields)
66
+	{
67
+		$rows = '';
68
+		foreach ($fields as $name => $field) {
69
+			$field = wp_parse_args($field, [
70
+				'is_setting' => true,
71
+				'name' => $name,
72
+			]);
73
+			$rows.= new Field($this->normalize($field));
74
+		}
75
+		return $rows;
76
+	}
77
+
78
+	/**
79
+	 * @param string $id
80
+	 * @return array
81
+	 */
82
+	protected function getTemplateData($id)
83
+	{
84
+		$fields = $this->getSettingFields($this->normalizeSettingPath($id));
85
+		return [
86
+			'context' => [
87
+				'rows' => $this->getSettingRows($fields),
88
+			],
89
+		];
90
+	}
91
+
92
+	/**
93
+	 * @param string $id
94
+	 * @return array
95
+	 */
96
+	protected function getTemplateDataForAddons($id)
97
+	{
98
+		$fields = $this->getSettingFields($this->normalizeSettingPath($id));
99
+		$settings = Arr::convertDotNotationArray($fields);
100
+		$settingKeys = array_keys($settings['settings']['addons']);
101
+		$results = [];
102
+		foreach ($settingKeys as $key) {
103
+			$addonFields = array_filter($fields, function ($path) use ($key) {
104
+				return Str::startsWith('settings.addons.'.$key, $path);
105
+			}, ARRAY_FILTER_USE_KEY);
106
+			$results[$key] = $this->getSettingRows($addonFields);
107
+		}
108
+		ksort($results);
109
+		return [
110
+			'settings' => $results,
111
+		];
112
+	}
113
+
114
+	/**
115
+	 * @param string $id
116
+	 * @return array
117
+	 */
118
+	protected function getTemplateDataForLicenses($id)
119
+	{
120
+		$fields = $this->getSettingFields($this->normalizeSettingPath($id));
121
+		ksort($fields);
122
+		return [
123
+			'context' => [
124
+				'rows' => $this->getSettingRows($fields),
125
+			],
126
+		];
127
+	}
128
+
129
+	/**
130
+	 * @return array
131
+	 */
132
+	protected function getTemplateDataForTranslations()
133
+	{
134
+		$translations = glsr(Translation::class)->renderAll();
135
+		$class = empty($translations)
136
+			? 'glsr-hidden'
137
+			: '';
138
+		return [
139
+			'context' => [
140
+				'class' => $class,
141
+				'database_key' => OptionManager::databaseKey(),
142
+				'translations' => $translations,
143
+			],
144
+		];
145
+	}
146
+
147
+	/**
148
+	 * @param string $path
149
+	 * @param string|array $expectedValue
150
+	 * @return bool
151
+	 */
152
+	protected function isFieldHidden($path, $expectedValue)
153
+	{
154
+		$optionValue = glsr(OptionManager::class)->get(
155
+			$path,
156
+			Arr::get(glsr()->defaults, $path)
157
+		);
158
+		if (is_array($expectedValue)) {
159
+			return is_array($optionValue)
160
+				? 0 === count(array_intersect($optionValue, $expectedValue))
161
+				: !in_array($optionValue, $expectedValue);
162
+		}
163
+		return $optionValue != $expectedValue;
164
+	}
165
+
166
+	/**
167
+	 * @return bool
168
+	 */
169
+	protected function isMultiDependency($path)
170
+	{
171
+		if (isset($this->settings[$path])) {
172
+			$field = $this->settings[$path];
173
+			return ('checkbox' == $field['type'] && !empty($field['options']))
174
+				|| !empty($field['multiple']);
175
+		}
176
+		return false;
177
+	}
178
+
179
+	/**
180
+	 * @return array
181
+	 */
182
+	protected function normalize(array $field)
183
+	{
184
+		$field = $this->normalizeDependsOn($field);
185
+		$field = $this->normalizeLabelAndLegend($field);
186
+		$field = $this->normalizeValue($field);
187
+		return $field;
188
+	}
189
+
190
+	/**
191
+	 * @return array
192
+	 */
193
+	protected function normalizeDependsOn(array $field)
194
+	{
195
+		if (!empty($field['depends_on']) && is_array($field['depends_on'])) {
196
+			$isFieldHidden = false;
197
+			$conditions = [];
198
+			foreach ($field['depends_on'] as $path => $value) {
199
+				$conditions[] = [
200
+					'name' => $this->getFieldNameForDependsOn($path),
201
+					'value' => $value,
202
+				];
203
+				if ($this->isFieldHidden($path, $value)) {
204
+					$isFieldHidden = true;
205
+				}
206
+			}
207
+			$field['data-depends'] = json_encode($conditions, JSON_HEX_APOS | JSON_HEX_QUOT);
208
+			$field['is_hidden'] = $isFieldHidden;
209
+		}
210
+		return $field;
211
+	}
212
+
213
+	/**
214
+	 * @return array
215
+	 */
216
+	protected function normalizeLabelAndLegend(array $field)
217
+	{
218
+		if (!empty($field['label'])) {
219
+			$field['legend'] = $field['label'];
220
+			unset($field['label']);
221
+		} else {
222
+			$field['is_valid'] = false;
223
+			glsr_log()->warning('Setting field is missing a label')->debug($field);
224
+		}
225
+		return $field;
226
+	}
227
+
228
+	/**
229
+	 * @return array
230
+	 */
231
+	protected function normalizeValue(array $field)
232
+	{
233
+		if (!isset($field['value'])) {
234
+			$field['value'] = glsr(OptionManager::class)->get(
235
+				$field['name'],
236
+				$this->getFieldDefault($field)
237
+			);
238
+		}
239
+		return $field;
240
+	}
241
+
242
+	/**
243
+	 * @return string
244
+	 */
245
+	protected function normalizeSettingPath($path)
246
+	{
247
+		return Str::prefix('settings.', rtrim($path, '.'));
248
+	}
249 249
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/Fields/Field.php 1 patch
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -7,73 +7,73 @@
 block discarded – undo
7 7
 
8 8
 abstract class Field
9 9
 {
10
-    /**
11
-     * @var Builder
12
-     */
13
-    protected $builder;
10
+	/**
11
+	 * @var Builder
12
+	 */
13
+	protected $builder;
14 14
 
15
-    public function __construct(Builder $builder)
16
-    {
17
-        $this->builder = $builder;
18
-    }
15
+	public function __construct(Builder $builder)
16
+	{
17
+		$this->builder = $builder;
18
+	}
19 19
 
20
-    /**
21
-     * @return string|void
22
-     */
23
-    public function build()
24
-    {
25
-        glsr_log()->error('Build method is not implemented for '.get_class($this));
26
-    }
20
+	/**
21
+	 * @return string|void
22
+	 */
23
+	public function build()
24
+	{
25
+		glsr_log()->error('Build method is not implemented for '.get_class($this));
26
+	}
27 27
 
28
-    /**
29
-     * @return array
30
-     */
31
-    public static function defaults()
32
-    {
33
-        return [];
34
-    }
28
+	/**
29
+	 * @return array
30
+	 */
31
+	public static function defaults()
32
+	{
33
+		return [];
34
+	}
35 35
 
36
-    /**
37
-     * @return array
38
-     */
39
-    public static function merge(array $args)
40
-    {
41
-        $merged = array_merge(
42
-            wp_parse_args($args, static::defaults()),
43
-            static::required()
44
-        );
45
-        $merged['class'] = implode(' ', static::mergedAttribute('class', ' ', $args));
46
-        $merged['style'] = implode(';', static::mergedAttribute('style', ';', $args));
47
-        return $merged;
48
-    }
36
+	/**
37
+	 * @return array
38
+	 */
39
+	public static function merge(array $args)
40
+	{
41
+		$merged = array_merge(
42
+			wp_parse_args($args, static::defaults()),
43
+			static::required()
44
+		);
45
+		$merged['class'] = implode(' ', static::mergedAttribute('class', ' ', $args));
46
+		$merged['style'] = implode(';', static::mergedAttribute('style', ';', $args));
47
+		return $merged;
48
+	}
49 49
 
50
-    /**
51
-     * @param string $delimiter
52
-     * @param string $key
53
-     * @return array
54
-     */
55
-    public static function mergedAttribute($key, $delimiter, array $args)
56
-    {
57
-        return array_filter(array_merge(
58
-            explode($delimiter, Arr::get($args, $key)),
59
-            explode($delimiter, Arr::get(static::defaults(), $key)),
60
-            explode($delimiter, Arr::get(static::required(), $key))
61
-        ));
62
-    }
50
+	/**
51
+	 * @param string $delimiter
52
+	 * @param string $key
53
+	 * @return array
54
+	 */
55
+	public static function mergedAttribute($key, $delimiter, array $args)
56
+	{
57
+		return array_filter(array_merge(
58
+			explode($delimiter, Arr::get($args, $key)),
59
+			explode($delimiter, Arr::get(static::defaults(), $key)),
60
+			explode($delimiter, Arr::get(static::required(), $key))
61
+		));
62
+	}
63 63
 
64
-    /**
65
-     * @return array
66
-     */
67
-    public static function required()
68
-    {
69
-        return [];
70
-    }
64
+	/**
65
+	 * @return array
66
+	 */
67
+	public static function required()
68
+	{
69
+		return [];
70
+	}
71 71
 
72
-    /**
73
-     * @return void
74
-     */
75
-    protected function mergeFieldArgs()
76
-    {
77
-        $this->builder->args = static::merge($this->builder->args);
78
-    }
72
+	/**
73
+	 * @return void
74
+	 */
75
+	protected function mergeFieldArgs()
76
+	{
77
+		$this->builder->args = static::merge($this->builder->args);
78
+	}
79 79
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/Template.php 1 patch
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -7,78 +7,78 @@
 block discarded – undo
7 7
 
8 8
 class Template
9 9
 {
10
-    /**
11
-     * @param string $templatePath
12
-     * @return void|string
13
-     */
14
-    public function build($templatePath, array $data = [])
15
-    {
16
-        $data = $this->normalize($data);
17
-        ob_start();
18
-        glsr()->render($templatePath, $data);
19
-        $template = ob_get_clean();
20
-        $path = Str::removePrefix('templates/', $templatePath);
21
-        $template = apply_filters('site-reviews/build/template/'.$path, $template, $data);
22
-        $template = $this->interpolate($template, $data, $path);
23
-        $template = apply_filters('site-reviews/rendered/template', $template, $templatePath, $data);
24
-        $template = apply_filters('site-reviews/rendered/template/'.$path, $template, $data);
25
-        return $template;
26
-    }
10
+	/**
11
+	 * @param string $templatePath
12
+	 * @return void|string
13
+	 */
14
+	public function build($templatePath, array $data = [])
15
+	{
16
+		$data = $this->normalize($data);
17
+		ob_start();
18
+		glsr()->render($templatePath, $data);
19
+		$template = ob_get_clean();
20
+		$path = Str::removePrefix('templates/', $templatePath);
21
+		$template = apply_filters('site-reviews/build/template/'.$path, $template, $data);
22
+		$template = $this->interpolate($template, $data, $path);
23
+		$template = apply_filters('site-reviews/rendered/template', $template, $templatePath, $data);
24
+		$template = apply_filters('site-reviews/rendered/template/'.$path, $template, $data);
25
+		return $template;
26
+	}
27 27
 
28
-    /**
29
-     * Interpolate context values into template placeholders.
30
-     * @param string $template
31
-     * @param string $templatePath
32
-     * @return string
33
-     */
34
-    public function interpolate($template, array $data = [], $templatePath)
35
-    {
36
-        $context = $this->normalizeContext(Arr::get($data, 'context', []));
37
-        $context = apply_filters('site-reviews/interpolate/'.$templatePath, $context, $template, $data);
38
-        foreach ($context as $key => $value) {
39
-            $template = strtr(
40
-                $template,
41
-                array_fill_keys(['{'.$key.'}', '{{ '.$key.' }}'], $value)
42
-            );
43
-        }
44
-        return trim($template);
45
-    }
28
+	/**
29
+	 * Interpolate context values into template placeholders.
30
+	 * @param string $template
31
+	 * @param string $templatePath
32
+	 * @return string
33
+	 */
34
+	public function interpolate($template, array $data = [], $templatePath)
35
+	{
36
+		$context = $this->normalizeContext(Arr::get($data, 'context', []));
37
+		$context = apply_filters('site-reviews/interpolate/'.$templatePath, $context, $template, $data);
38
+		foreach ($context as $key => $value) {
39
+			$template = strtr(
40
+				$template,
41
+				array_fill_keys(['{'.$key.'}', '{{ '.$key.' }}'], $value)
42
+			);
43
+		}
44
+		return trim($template);
45
+	}
46 46
 
47
-    /**
48
-     * @param string $templatePath
49
-     * @return void|string
50
-     */
51
-    public function render($templatePath, array $data = [])
52
-    {
53
-        echo $this->build($templatePath, $data);
54
-    }
47
+	/**
48
+	 * @param string $templatePath
49
+	 * @return void|string
50
+	 */
51
+	public function render($templatePath, array $data = [])
52
+	{
53
+		echo $this->build($templatePath, $data);
54
+	}
55 55
 
56
-    /**
57
-     * @return array
58
-     */
59
-    protected function normalize(array $data)
60
-    {
61
-        $arrayKeys = ['context', 'globals'];
62
-        $data = wp_parse_args($data, array_fill_keys($arrayKeys, []));
63
-        foreach ($arrayKeys as $key) {
64
-            if (is_array($data[$key])) {
65
-                continue;
66
-            }
67
-            $data[$key] = [];
68
-        }
69
-        return $data;
70
-    }
56
+	/**
57
+	 * @return array
58
+	 */
59
+	protected function normalize(array $data)
60
+	{
61
+		$arrayKeys = ['context', 'globals'];
62
+		$data = wp_parse_args($data, array_fill_keys($arrayKeys, []));
63
+		foreach ($arrayKeys as $key) {
64
+			if (is_array($data[$key])) {
65
+				continue;
66
+			}
67
+			$data[$key] = [];
68
+		}
69
+		return $data;
70
+	}
71 71
 
72
-    /**
73
-     * @return array
74
-     */
75
-    protected function normalizeContext(array $context)
76
-    {
77
-        $context = array_filter($context, function ($value) {
78
-            return !is_array($value) && !is_object($value);
79
-        });
80
-        return array_map(function ($value) {
81
-            return (string) $value;
82
-        }, $context);
83
-    }
72
+	/**
73
+	 * @return array
74
+	 */
75
+	protected function normalizeContext(array $context)
76
+	{
77
+		$context = array_filter($context, function ($value) {
78
+			return !is_array($value) && !is_object($value);
79
+		});
80
+		return array_map(function ($value) {
81
+			return (string) $value;
82
+		}, $context);
83
+	}
84 84
 }
Please login to merge, or discard this patch.
plugin/Modules/Upgrader/Upgrade_3_0_0.php 1 patch
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -8,160 +8,160 @@
 block discarded – undo
8 8
 
9 9
 class Upgrade_3_0_0
10 10
 {
11
-    const MAPPED_SETTINGS = [
12
-        'settings.general.notification' => 'settings.general.notifications', // array
13
-        'settings.general.notification_email' => 'settings.general.notification_email',
14
-        'settings.general.notification_message' => 'settings.general.notification_message',
15
-        'settings.general.require.approval' => 'settings.general.require.approval',
16
-        'settings.general.require.login' => 'settings.general.require.login',
17
-        'settings.general.require.login_register' => 'settings.general.require.login_register',
18
-        'settings.general.webhook_url' => 'settings.general.notification_slack',
19
-        'settings.reviews-form.akismet' => 'settings.submissions.akismet',
20
-        'settings.reviews-form.blacklist.action' => 'settings.submissions.blacklist.action',
21
-        'settings.reviews-form.blacklist.entries' => 'settings.submissions.blacklist.entries',
22
-        'settings.reviews-form.recaptcha.integration' => 'settings.submissions.recaptcha.integration',
23
-        'settings.reviews-form.recaptcha.key' => 'settings.submissions.recaptcha.key',
24
-        'settings.reviews-form.recaptcha.position' => 'settings.submissions.recaptcha.position',
25
-        'settings.reviews-form.recaptcha.secret' => 'settings.submissions.recaptcha.secret',
26
-        'settings.reviews-form.required' => 'settings.submissions.required', // array
27
-        'settings.reviews.assigned_links.enabled' => 'settings.reviews.assigned_links',
28
-        'settings.reviews.avatars.enabled' => 'settings.reviews.avatars',
29
-        'settings.reviews.date.custom' => 'settings.reviews.date.custom',
30
-        'settings.reviews.date.format' => 'settings.reviews.date.format',
31
-        'settings.reviews.excerpt.enabled' => 'settings.reviews.excerpts',
32
-        'settings.reviews.excerpt.length' => 'settings.reviews.excerpts_length',
33
-        'settings.reviews.schema.address' => 'settings.schema.address',
34
-        'settings.reviews.schema.description.custom' => 'settings.schema.description.custom',
35
-        'settings.reviews.schema.description.default' => 'settings.schema.description.default',
36
-        'settings.reviews.schema.highprice' => 'settings.schema.highprice',
37
-        'settings.reviews.schema.image.custom' => 'settings.schema.image.custom',
38
-        'settings.reviews.schema.image.default' => 'settings.schema.image.default',
39
-        'settings.reviews.schema.lowprice' => 'settings.schema.lowprice',
40
-        'settings.reviews.schema.name.custom' => 'settings.schema.name.custom',
41
-        'settings.reviews.schema.name.default' => 'settings.schema.name.default',
42
-        'settings.reviews.schema.pricecurrency' => 'settings.schema.pricecurrency',
43
-        'settings.reviews.schema.pricerange' => 'settings.schema.pricerange',
44
-        'settings.reviews.schema.telephone' => 'settings.schema.telephone',
45
-        'settings.reviews.schema.type.custom' => 'settings.schema.type.custom',
46
-        'settings.reviews.schema.type.default' => 'settings.schema.type.default',
47
-        'settings.reviews.schema.url.custom' => 'settings.schema.url.custom',
48
-        'settings.reviews.schema.url.default' => 'settings.schema.url.default',
49
-        'version' => 'version_upgraded_from',
50
-    ];
11
+	const MAPPED_SETTINGS = [
12
+		'settings.general.notification' => 'settings.general.notifications', // array
13
+		'settings.general.notification_email' => 'settings.general.notification_email',
14
+		'settings.general.notification_message' => 'settings.general.notification_message',
15
+		'settings.general.require.approval' => 'settings.general.require.approval',
16
+		'settings.general.require.login' => 'settings.general.require.login',
17
+		'settings.general.require.login_register' => 'settings.general.require.login_register',
18
+		'settings.general.webhook_url' => 'settings.general.notification_slack',
19
+		'settings.reviews-form.akismet' => 'settings.submissions.akismet',
20
+		'settings.reviews-form.blacklist.action' => 'settings.submissions.blacklist.action',
21
+		'settings.reviews-form.blacklist.entries' => 'settings.submissions.blacklist.entries',
22
+		'settings.reviews-form.recaptcha.integration' => 'settings.submissions.recaptcha.integration',
23
+		'settings.reviews-form.recaptcha.key' => 'settings.submissions.recaptcha.key',
24
+		'settings.reviews-form.recaptcha.position' => 'settings.submissions.recaptcha.position',
25
+		'settings.reviews-form.recaptcha.secret' => 'settings.submissions.recaptcha.secret',
26
+		'settings.reviews-form.required' => 'settings.submissions.required', // array
27
+		'settings.reviews.assigned_links.enabled' => 'settings.reviews.assigned_links',
28
+		'settings.reviews.avatars.enabled' => 'settings.reviews.avatars',
29
+		'settings.reviews.date.custom' => 'settings.reviews.date.custom',
30
+		'settings.reviews.date.format' => 'settings.reviews.date.format',
31
+		'settings.reviews.excerpt.enabled' => 'settings.reviews.excerpts',
32
+		'settings.reviews.excerpt.length' => 'settings.reviews.excerpts_length',
33
+		'settings.reviews.schema.address' => 'settings.schema.address',
34
+		'settings.reviews.schema.description.custom' => 'settings.schema.description.custom',
35
+		'settings.reviews.schema.description.default' => 'settings.schema.description.default',
36
+		'settings.reviews.schema.highprice' => 'settings.schema.highprice',
37
+		'settings.reviews.schema.image.custom' => 'settings.schema.image.custom',
38
+		'settings.reviews.schema.image.default' => 'settings.schema.image.default',
39
+		'settings.reviews.schema.lowprice' => 'settings.schema.lowprice',
40
+		'settings.reviews.schema.name.custom' => 'settings.schema.name.custom',
41
+		'settings.reviews.schema.name.default' => 'settings.schema.name.default',
42
+		'settings.reviews.schema.pricecurrency' => 'settings.schema.pricecurrency',
43
+		'settings.reviews.schema.pricerange' => 'settings.schema.pricerange',
44
+		'settings.reviews.schema.telephone' => 'settings.schema.telephone',
45
+		'settings.reviews.schema.type.custom' => 'settings.schema.type.custom',
46
+		'settings.reviews.schema.type.default' => 'settings.schema.type.default',
47
+		'settings.reviews.schema.url.custom' => 'settings.schema.url.custom',
48
+		'settings.reviews.schema.url.default' => 'settings.schema.url.default',
49
+		'version' => 'version_upgraded_from',
50
+	];
51 51
 
52
-    /**
53
-     * @var array
54
-     */
55
-    protected $newSettings;
52
+	/**
53
+	 * @var array
54
+	 */
55
+	protected $newSettings;
56 56
 
57
-    /**
58
-     * @var array
59
-     */
60
-    protected $oldSettings;
57
+	/**
58
+	 * @var array
59
+	 */
60
+	protected $oldSettings;
61 61
 
62
-    public function __construct()
63
-    {
64
-        $this->migrateSettings();
65
-    }
62
+	public function __construct()
63
+	{
64
+		$this->migrateSettings();
65
+	}
66 66
 
67
-    /**
68
-     * @return void
69
-     */
70
-    public function migrateSettings()
71
-    {
72
-        $this->newSettings = $this->getNewSettings();
73
-        $this->oldSettings = $this->getOldSettings();
74
-        if (empty($this->oldSettings)) {
75
-            return;
76
-        }
77
-        foreach (static::MAPPED_SETTINGS as $old => $new) {
78
-            if (empty($this->oldSettings[$old])) {
79
-                continue;
80
-            }
81
-            $this->newSettings[$new] = $this->oldSettings[$old];
82
-        }
83
-        $this->migrateNotificationSettings();
84
-        $this->migrateRecaptchaSettings();
85
-        $this->migrateRequiredSettings();
86
-        $oldSettings = Arr::convertDotNotationArray($this->oldSettings);
87
-        $newSettings = Arr::convertDotNotationArray($this->newSettings);
88
-        if (isset($oldSettings['settings']['strings']) && is_array($oldSettings['settings']['strings'])) {
89
-            $newSettings['settings']['strings'] = $oldSettings['settings']['strings'];
90
-        }
91
-        glsr(OptionManager::class)->set($newSettings);
92
-    }
67
+	/**
68
+	 * @return void
69
+	 */
70
+	public function migrateSettings()
71
+	{
72
+		$this->newSettings = $this->getNewSettings();
73
+		$this->oldSettings = $this->getOldSettings();
74
+		if (empty($this->oldSettings)) {
75
+			return;
76
+		}
77
+		foreach (static::MAPPED_SETTINGS as $old => $new) {
78
+			if (empty($this->oldSettings[$old])) {
79
+				continue;
80
+			}
81
+			$this->newSettings[$new] = $this->oldSettings[$old];
82
+		}
83
+		$this->migrateNotificationSettings();
84
+		$this->migrateRecaptchaSettings();
85
+		$this->migrateRequiredSettings();
86
+		$oldSettings = Arr::convertDotNotationArray($this->oldSettings);
87
+		$newSettings = Arr::convertDotNotationArray($this->newSettings);
88
+		if (isset($oldSettings['settings']['strings']) && is_array($oldSettings['settings']['strings'])) {
89
+			$newSettings['settings']['strings'] = $oldSettings['settings']['strings'];
90
+		}
91
+		glsr(OptionManager::class)->set($newSettings);
92
+	}
93 93
 
94
-    /**
95
-     * @return array
96
-     */
97
-    protected function getNewSettings()
98
-    {
99
-        return wp_parse_args(
100
-            Arr::flattenArray(glsr(OptionManager::class)->all()),
101
-            glsr(DefaultsManager::class)->defaults()
102
-        );
103
-    }
94
+	/**
95
+	 * @return array
96
+	 */
97
+	protected function getNewSettings()
98
+	{
99
+		return wp_parse_args(
100
+			Arr::flattenArray(glsr(OptionManager::class)->all()),
101
+			glsr(DefaultsManager::class)->defaults()
102
+		);
103
+	}
104 104
 
105
-    /**
106
-     * @return array
107
-     */
108
-    protected function getOldSettings()
109
-    {
110
-        $defaults = array_fill_keys(array_keys(static::MAPPED_SETTINGS), '');
111
-        $settings = Arr::flattenArray((array) get_option('geminilabs_site_reviews-v2', []));
112
-        if (!empty($settings)) {
113
-            $settings = wp_parse_args($settings, $defaults);
114
-        }
115
-        return $settings;
116
-    }
105
+	/**
106
+	 * @return array
107
+	 */
108
+	protected function getOldSettings()
109
+	{
110
+		$defaults = array_fill_keys(array_keys(static::MAPPED_SETTINGS), '');
111
+		$settings = Arr::flattenArray((array) get_option('geminilabs_site_reviews-v2', []));
112
+		if (!empty($settings)) {
113
+			$settings = wp_parse_args($settings, $defaults);
114
+		}
115
+		return $settings;
116
+	}
117 117
 
118
-    /**
119
-     * @return void
120
-     */
121
-    protected function migrateNotificationSettings()
122
-    {
123
-        $notifications = [
124
-            'custom' => 'custom',
125
-            'default' => 'admin',
126
-            'webhook' => 'slack',
127
-        ];
128
-        $this->newSettings['settings.general.notifications'] = [];
129
-        foreach ($notifications as $old => $new) {
130
-            if ($this->oldSettings['settings.general.notification'] != $old) {
131
-                continue;
132
-            }
133
-            $this->newSettings['settings.general.notifications'][] = $new;
134
-        }
135
-    }
118
+	/**
119
+	 * @return void
120
+	 */
121
+	protected function migrateNotificationSettings()
122
+	{
123
+		$notifications = [
124
+			'custom' => 'custom',
125
+			'default' => 'admin',
126
+			'webhook' => 'slack',
127
+		];
128
+		$this->newSettings['settings.general.notifications'] = [];
129
+		foreach ($notifications as $old => $new) {
130
+			if ($this->oldSettings['settings.general.notification'] != $old) {
131
+				continue;
132
+			}
133
+			$this->newSettings['settings.general.notifications'][] = $new;
134
+		}
135
+	}
136 136
 
137
-    /**
138
-     * @return void
139
-     */
140
-    protected function migrateRecaptchaSettings()
141
-    {
142
-        $recaptcha = [
143
-            'BadgePosition' => $this->oldSettings['settings.reviews-form.recaptcha.position'],
144
-            'SecretKey' => $this->oldSettings['settings.reviews-form.recaptcha.secret'],
145
-            'SiteKey' => $this->oldSettings['settings.reviews-form.recaptcha.key'],
146
-        ];
147
-        if (in_array($this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'])) {
148
-            $this->newSettings['settings.submissions.recaptcha.integration'] = 'all';
149
-        }
150
-        if ('invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration']) {
151
-            $recaptcha = wp_parse_args((array) get_site_option('ic-settings', [], false), $recaptcha);
152
-        }
153
-        $this->newSettings['settings.submissions.recaptcha.key'] = $recaptcha['SiteKey'];
154
-        $this->newSettings['settings.submissions.recaptcha.secret'] = $recaptcha['SecretKey'];
155
-        $this->newSettings['settings.submissions.recaptcha.position'] = $recaptcha['BadgePosition'];
156
-    }
137
+	/**
138
+	 * @return void
139
+	 */
140
+	protected function migrateRecaptchaSettings()
141
+	{
142
+		$recaptcha = [
143
+			'BadgePosition' => $this->oldSettings['settings.reviews-form.recaptcha.position'],
144
+			'SecretKey' => $this->oldSettings['settings.reviews-form.recaptcha.secret'],
145
+			'SiteKey' => $this->oldSettings['settings.reviews-form.recaptcha.key'],
146
+		];
147
+		if (in_array($this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'])) {
148
+			$this->newSettings['settings.submissions.recaptcha.integration'] = 'all';
149
+		}
150
+		if ('invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration']) {
151
+			$recaptcha = wp_parse_args((array) get_site_option('ic-settings', [], false), $recaptcha);
152
+		}
153
+		$this->newSettings['settings.submissions.recaptcha.key'] = $recaptcha['SiteKey'];
154
+		$this->newSettings['settings.submissions.recaptcha.secret'] = $recaptcha['SecretKey'];
155
+		$this->newSettings['settings.submissions.recaptcha.position'] = $recaptcha['BadgePosition'];
156
+	}
157 157
 
158
-    /**
159
-     * @return void
160
-     */
161
-    protected function migrateRequiredSettings()
162
-    {
163
-        $this->newSettings['settings.submissions.required'] = array_filter((array) $this->oldSettings['settings.reviews-form.required']);
164
-        $this->newSettings['settings.submissions.required'][] = 'rating';
165
-        $this->newSettings['settings.submissions.required'][] = 'terms';
166
-    }
158
+	/**
159
+	 * @return void
160
+	 */
161
+	protected function migrateRequiredSettings()
162
+	{
163
+		$this->newSettings['settings.submissions.required'] = array_filter((array) $this->oldSettings['settings.reviews-form.required']);
164
+		$this->newSettings['settings.submissions.required'][] = 'rating';
165
+		$this->newSettings['settings.submissions.required'][] = 'terms';
166
+	}
167 167
 }
Please login to merge, or discard this patch.
plugin/Modules/Style.php 1 patch
Indentation   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -12,144 +12,144 @@
 block discarded – undo
12 12
 
13 13
 class Style
14 14
 {
15
-    /**
16
-     * @var array
17
-     */
18
-    public $fields;
15
+	/**
16
+	 * @var array
17
+	 */
18
+	public $fields;
19 19
 
20
-    /**
21
-     * @var string
22
-     */
23
-    public $style;
20
+	/**
21
+	 * @var string
22
+	 */
23
+	public $style;
24 24
 
25
-    /**
26
-     * @var array
27
-     */
28
-    public $pagination;
25
+	/**
26
+	 * @var array
27
+	 */
28
+	public $pagination;
29 29
 
30
-    /**
31
-     * @var array
32
-     */
33
-    public $validation;
30
+	/**
31
+	 * @var array
32
+	 */
33
+	public $validation;
34 34
 
35
-    public function __construct()
36
-    {
37
-        $this->style = glsr(OptionManager::class)->get('settings.general.style', 'default');
38
-        $this->setConfig();
39
-    }
35
+	public function __construct()
36
+	{
37
+		$this->style = glsr(OptionManager::class)->get('settings.general.style', 'default');
38
+		$this->setConfig();
39
+	}
40 40
 
41
-    /**
42
-     * @param string $view
43
-     * @return string
44
-     */
45
-    public function filterView($view)
46
-    {
47
-        $styledViews = [
48
-            'templates/form/field',
49
-            'templates/form/response',
50
-            'templates/form/submit-button',
51
-            'templates/reviews-form',
52
-        ];
53
-        if (!preg_match('('.implode('|', $styledViews).')', $view)) {
54
-            return $view;
55
-        }
56
-        $views = $this->generatePossibleViews($view);
57
-        foreach ($views as $possibleView) {
58
-            if (!file_exists(glsr()->file($possibleView))) {
59
-                continue;
60
-            }
61
-            return Str::removePrefix('views/', $possibleView);
62
-        }
63
-        return $view;
64
-    }
41
+	/**
42
+	 * @param string $view
43
+	 * @return string
44
+	 */
45
+	public function filterView($view)
46
+	{
47
+		$styledViews = [
48
+			'templates/form/field',
49
+			'templates/form/response',
50
+			'templates/form/submit-button',
51
+			'templates/reviews-form',
52
+		];
53
+		if (!preg_match('('.implode('|', $styledViews).')', $view)) {
54
+			return $view;
55
+		}
56
+		$views = $this->generatePossibleViews($view);
57
+		foreach ($views as $possibleView) {
58
+			if (!file_exists(glsr()->file($possibleView))) {
59
+				continue;
60
+			}
61
+			return Str::removePrefix('views/', $possibleView);
62
+		}
63
+		return $view;
64
+	}
65 65
 
66
-    /**
67
-     * @return string
68
-     */
69
-    public function get()
70
-    {
71
-        return apply_filters('site-reviews/style', $this->style);
72
-    }
66
+	/**
67
+	 * @return string
68
+	 */
69
+	public function get()
70
+	{
71
+		return apply_filters('site-reviews/style', $this->style);
72
+	}
73 73
 
74
-    /**
75
-     * @return array
76
-     */
77
-    public function setConfig()
78
-    {
79
-        $config = shortcode_atts(
80
-            array_fill_keys(['fields', 'pagination', 'validation'], []),
81
-            glsr()->config('styles/'.$this->style)
82
-        );
83
-        $this->fields = glsr(StyleFieldsDefaults::class)->restrict($config['fields']);
84
-        $this->pagination = glsr(PaginationDefaults::class)->restrict($config['pagination']);
85
-        $this->validation = glsr(StyleValidationDefaults::class)->restrict($config['validation']);
86
-    }
74
+	/**
75
+	 * @return array
76
+	 */
77
+	public function setConfig()
78
+	{
79
+		$config = shortcode_atts(
80
+			array_fill_keys(['fields', 'pagination', 'validation'], []),
81
+			glsr()->config('styles/'.$this->style)
82
+		);
83
+		$this->fields = glsr(StyleFieldsDefaults::class)->restrict($config['fields']);
84
+		$this->pagination = glsr(PaginationDefaults::class)->restrict($config['pagination']);
85
+		$this->validation = glsr(StyleValidationDefaults::class)->restrict($config['validation']);
86
+	}
87 87
 
88
-    /**
89
-     * @return void
90
-     */
91
-    public function modifyField(Builder $instance)
92
-    {
93
-        if (!$this->isPublicInstance($instance) || empty(array_filter($this->fields))) {
94
-            return;
95
-        }
96
-        call_user_func_array([$this, 'customize'], [$instance]);
97
-    }
88
+	/**
89
+	 * @return void
90
+	 */
91
+	public function modifyField(Builder $instance)
92
+	{
93
+		if (!$this->isPublicInstance($instance) || empty(array_filter($this->fields))) {
94
+			return;
95
+		}
96
+		call_user_func_array([$this, 'customize'], [$instance]);
97
+	}
98 98
 
99
-    /**
100
-     * @return array
101
-     */
102
-    public function paginationArgs(array $args)
103
-    {
104
-        return wp_parse_args($args, $this->pagination);
105
-    }
99
+	/**
100
+	 * @return array
101
+	 */
102
+	public function paginationArgs(array $args)
103
+	{
104
+		return wp_parse_args($args, $this->pagination);
105
+	}
106 106
 
107
-    /**
108
-     * @return void
109
-     */
110
-    protected function customize(Builder $instance)
111
-    {
112
-        if (!array_key_exists($instance->tag, $this->fields)) {
113
-            return;
114
-        }
115
-        $args = wp_parse_args($instance->args, array_fill_keys(['class', 'type'], ''));
116
-        $key = $instance->tag.'_'.$args['type'];
117
-        $classes = Arr::get($this->fields, $key, Arr::get($this->fields, $instance->tag));
118
-        $instance->args['class'] = trim($args['class'].' '.$classes);
119
-        do_action_ref_array('site-reviews/customize/'.$this->style, [$instance]);
120
-    }
107
+	/**
108
+	 * @return void
109
+	 */
110
+	protected function customize(Builder $instance)
111
+	{
112
+		if (!array_key_exists($instance->tag, $this->fields)) {
113
+			return;
114
+		}
115
+		$args = wp_parse_args($instance->args, array_fill_keys(['class', 'type'], ''));
116
+		$key = $instance->tag.'_'.$args['type'];
117
+		$classes = Arr::get($this->fields, $key, Arr::get($this->fields, $instance->tag));
118
+		$instance->args['class'] = trim($args['class'].' '.$classes);
119
+		do_action_ref_array('site-reviews/customize/'.$this->style, [$instance]);
120
+	}
121 121
 
122
-    /**
123
-     * @param string $view
124
-     * @return array
125
-     */
126
-    protected function generatePossibleViews($view)
127
-    {
128
-        $basename = basename($view);
129
-        $basepath = rtrim($view, $basename);
130
-        $customPath = 'views/partials/styles/'.$this->style.'/';
131
-        $parts = explode('_', $basename);
132
-        $views = [
133
-            $customPath.$basename,
134
-            $customPath.$parts[0],
135
-            $view,
136
-            $basepath.$parts[0],
137
-        ];
138
-        return array_filter($views);
139
-    }
122
+	/**
123
+	 * @param string $view
124
+	 * @return array
125
+	 */
126
+	protected function generatePossibleViews($view)
127
+	{
128
+		$basename = basename($view);
129
+		$basepath = rtrim($view, $basename);
130
+		$customPath = 'views/partials/styles/'.$this->style.'/';
131
+		$parts = explode('_', $basename);
132
+		$views = [
133
+			$customPath.$basename,
134
+			$customPath.$parts[0],
135
+			$view,
136
+			$basepath.$parts[0],
137
+		];
138
+		return array_filter($views);
139
+	}
140 140
 
141
-    /**
142
-     * @return bool
143
-     */
144
-    protected function isPublicInstance(Builder $instance)
145
-    {
146
-        $args = wp_parse_args($instance->args, [
147
-            'is_public' => false,
148
-            'is_raw' => false,
149
-        ]);
150
-        if (is_admin() || !$args['is_public'] || $args['is_raw']) {
151
-            return false;
152
-        }
153
-        return true;
154
-    }
141
+	/**
142
+	 * @return bool
143
+	 */
144
+	protected function isPublicInstance(Builder $instance)
145
+	{
146
+		$args = wp_parse_args($instance->args, [
147
+			'is_public' => false,
148
+			'is_raw' => false,
149
+		]);
150
+		if (is_admin() || !$args['is_public'] || $args['is_raw']) {
151
+			return false;
152
+		}
153
+		return true;
154
+	}
155 155
 }
Please login to merge, or discard this patch.
plugin/Review.php 1 patch
Indentation   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -12,173 +12,173 @@
 block discarded – undo
12 12
 
13 13
 class Review implements \ArrayAccess
14 14
 {
15
-    public $assigned_to;
16
-    public $author;
17
-    public $avatar;
18
-    public $content;
19
-    public $custom;
20
-    public $date;
21
-    public $email;
22
-    public $ID;
23
-    public $ip_address;
24
-    public $modified;
25
-    public $pinned;
26
-    public $rating;
27
-    public $response;
28
-    public $review_id;
29
-    public $review_type;
30
-    public $status;
31
-    public $term_ids;
32
-    public $title;
33
-    public $url;
34
-    public $user_id;
15
+	public $assigned_to;
16
+	public $author;
17
+	public $avatar;
18
+	public $content;
19
+	public $custom;
20
+	public $date;
21
+	public $email;
22
+	public $ID;
23
+	public $ip_address;
24
+	public $modified;
25
+	public $pinned;
26
+	public $rating;
27
+	public $response;
28
+	public $review_id;
29
+	public $review_type;
30
+	public $status;
31
+	public $term_ids;
32
+	public $title;
33
+	public $url;
34
+	public $user_id;
35 35
 
36
-    public function __construct(WP_Post $post)
37
-    {
38
-        if (Application::POST_TYPE != $post->post_type) {
39
-            return;
40
-        }
41
-        $this->content = $post->post_content;
42
-        $this->date = $post->post_date;
43
-        $this->ID = intval($post->ID);
44
-        $this->status = $post->post_status;
45
-        $this->title = $post->post_title;
46
-        $this->user_id = intval($post->post_author);
47
-        $this->setProperties($post);
48
-        $this->setTermIds($post);
49
-    }
36
+	public function __construct(WP_Post $post)
37
+	{
38
+		if (Application::POST_TYPE != $post->post_type) {
39
+			return;
40
+		}
41
+		$this->content = $post->post_content;
42
+		$this->date = $post->post_date;
43
+		$this->ID = intval($post->ID);
44
+		$this->status = $post->post_status;
45
+		$this->title = $post->post_title;
46
+		$this->user_id = intval($post->post_author);
47
+		$this->setProperties($post);
48
+		$this->setTermIds($post);
49
+	}
50 50
 
51
-    /**
52
-     * @return mixed
53
-     */
54
-    public function __get($key)
55
-    {
56
-        return $this->offsetGet($key);
57
-    }
51
+	/**
52
+	 * @return mixed
53
+	 */
54
+	public function __get($key)
55
+	{
56
+		return $this->offsetGet($key);
57
+	}
58 58
 
59
-    /**
60
-     * @return string
61
-     */
62
-    public function __toString()
63
-    {
64
-        return (string) $this->build();
65
-    }
59
+	/**
60
+	 * @return string
61
+	 */
62
+	public function __toString()
63
+	{
64
+		return (string) $this->build();
65
+	}
66 66
 
67
-    /**
68
-     * @return ReviewHtml
69
-     */
70
-    public function build(array $args = [])
71
-    {
72
-        if (empty($this->ID)) {
73
-            return new ReviewHtml($this);
74
-        }
75
-        $partial = glsr(SiteReviewsPartial::class);
76
-        $partial->args = glsr(SiteReviewsDefaults::class)->merge($args);
77
-        $partial->options = Arr::flattenArray(glsr(OptionManager::class)->all());
78
-        return $partial->buildReview($this);
79
-    }
67
+	/**
68
+	 * @return ReviewHtml
69
+	 */
70
+	public function build(array $args = [])
71
+	{
72
+		if (empty($this->ID)) {
73
+			return new ReviewHtml($this);
74
+		}
75
+		$partial = glsr(SiteReviewsPartial::class);
76
+		$partial->args = glsr(SiteReviewsDefaults::class)->merge($args);
77
+		$partial->options = Arr::flattenArray(glsr(OptionManager::class)->all());
78
+		return $partial->buildReview($this);
79
+	}
80 80
 
81
-    /**
82
-     * @param mixed $key
83
-     * @return bool
84
-     */
85
-    public function offsetExists($key)
86
-    {
87
-        return property_exists($this, $key) || array_key_exists($key, (array) $this->custom);
88
-    }
81
+	/**
82
+	 * @param mixed $key
83
+	 * @return bool
84
+	 */
85
+	public function offsetExists($key)
86
+	{
87
+		return property_exists($this, $key) || array_key_exists($key, (array) $this->custom);
88
+	}
89 89
 
90
-    /**
91
-     * @param mixed $key
92
-     * @return mixed
93
-     */
94
-    public function offsetGet($key)
95
-    {
96
-        return property_exists($this, $key)
97
-            ? $this->$key
98
-            : Arr::get($this->custom, $key, null);
99
-    }
90
+	/**
91
+	 * @param mixed $key
92
+	 * @return mixed
93
+	 */
94
+	public function offsetGet($key)
95
+	{
96
+		return property_exists($this, $key)
97
+			? $this->$key
98
+			: Arr::get($this->custom, $key, null);
99
+	}
100 100
 
101
-    /**
102
-     * @param mixed $key
103
-     * @param mixed $value
104
-     * @return void
105
-     */
106
-    public function offsetSet($key, $value)
107
-    {
108
-        if (property_exists($this, $key)) {
109
-            $this->$key = $value;
110
-            return;
111
-        }
112
-        if (!is_array($this->custom)) {
113
-            $this->custom = array_filter((array) $this->custom);
114
-        }
115
-        $this->custom[$key] = $value;
116
-    }
101
+	/**
102
+	 * @param mixed $key
103
+	 * @param mixed $value
104
+	 * @return void
105
+	 */
106
+	public function offsetSet($key, $value)
107
+	{
108
+		if (property_exists($this, $key)) {
109
+			$this->$key = $value;
110
+			return;
111
+		}
112
+		if (!is_array($this->custom)) {
113
+			$this->custom = array_filter((array) $this->custom);
114
+		}
115
+		$this->custom[$key] = $value;
116
+	}
117 117
 
118
-    /**
119
-     * @param mixed $key
120
-     * @return void
121
-     */
122
-    public function offsetUnset($key)
123
-    {
124
-        $this->offsetSet($key, null);
125
-    }
118
+	/**
119
+	 * @param mixed $key
120
+	 * @return void
121
+	 */
122
+	public function offsetUnset($key)
123
+	{
124
+		$this->offsetSet($key, null);
125
+	}
126 126
 
127
-    /**
128
-     * @return void
129
-     */
130
-    public function render()
131
-    {
132
-        echo $this->build();
133
-    }
127
+	/**
128
+	 * @return void
129
+	 */
130
+	public function render()
131
+	{
132
+		echo $this->build();
133
+	}
134 134
 
135
-    /**
136
-     * @return bool
137
-     */
138
-    protected function isModified(array $properties)
139
-    {
140
-        return $this->date != $properties['date']
141
-            || $this->content != $properties['content']
142
-            || $this->title != $properties['title'];
143
-    }
135
+	/**
136
+	 * @return bool
137
+	 */
138
+	protected function isModified(array $properties)
139
+	{
140
+		return $this->date != $properties['date']
141
+			|| $this->content != $properties['content']
142
+			|| $this->title != $properties['title'];
143
+	}
144 144
 
145
-    /**
146
-     * @return void
147
-     */
148
-    protected function setProperties(WP_Post $post)
149
-    {
150
-        $defaults = [
151
-            'author' => __('Anonymous', 'site-reviews'),
152
-            'date' => '',
153
-            'review_id' => '',
154
-            'review_type' => 'local',
155
-        ];
156
-        $meta = array_filter(
157
-            array_map('array_shift', array_filter((array) get_post_meta($post->ID))),
158
-            'strlen'
159
-        );
160
-        $meta = array_merge($defaults, Arr::unprefixArrayKeys($meta));
161
-        $properties = glsr(CreateReviewDefaults::class)->restrict(array_merge($defaults, $meta));
162
-        $this->modified = $this->isModified($properties);
163
-        array_walk($properties, function ($value, $key) {
164
-            if (!property_exists($this, $key) || isset($this->$key)) {
165
-                return;
166
-            }
167
-            $this->$key = maybe_unserialize($value);
168
-        });
169
-    }
145
+	/**
146
+	 * @return void
147
+	 */
148
+	protected function setProperties(WP_Post $post)
149
+	{
150
+		$defaults = [
151
+			'author' => __('Anonymous', 'site-reviews'),
152
+			'date' => '',
153
+			'review_id' => '',
154
+			'review_type' => 'local',
155
+		];
156
+		$meta = array_filter(
157
+			array_map('array_shift', array_filter((array) get_post_meta($post->ID))),
158
+			'strlen'
159
+		);
160
+		$meta = array_merge($defaults, Arr::unprefixArrayKeys($meta));
161
+		$properties = glsr(CreateReviewDefaults::class)->restrict(array_merge($defaults, $meta));
162
+		$this->modified = $this->isModified($properties);
163
+		array_walk($properties, function ($value, $key) {
164
+			if (!property_exists($this, $key) || isset($this->$key)) {
165
+				return;
166
+			}
167
+			$this->$key = maybe_unserialize($value);
168
+		});
169
+	}
170 170
 
171
-    /**
172
-     * @return void
173
-     */
174
-    protected function setTermIds(WP_Post $post)
175
-    {
176
-        $this->term_ids = [];
177
-        if (!is_array($terms = get_the_terms($post, Application::TAXONOMY))) {
178
-            return;
179
-        }
180
-        foreach ($terms as $term) {
181
-            $this->term_ids[] = $term->term_id;
182
-        }
183
-    }
171
+	/**
172
+	 * @return void
173
+	 */
174
+	protected function setTermIds(WP_Post $post)
175
+	{
176
+		$this->term_ids = [];
177
+		if (!is_array($terms = get_the_terms($post, Application::TAXONOMY))) {
178
+			return;
179
+		}
180
+		foreach ($terms as $term) {
181
+			$this->term_ids[] = $term->term_id;
182
+		}
183
+	}
184 184
 }
Please login to merge, or discard this patch.
plugin/Database.php 1 patch
Indentation   +158 added lines, -158 removed lines patch added patch discarded remove patch
@@ -12,171 +12,171 @@
 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
-        if ('all' == $status || empty($status)) {
80
-            $status = get_post_stati(['exclude_from_search' => false]);
81
-        }
82
-        return glsr(SqlQueries::class)->getReviewsMeta($key, $status);
83
-    }
72
+	/**
73
+	 * @param string $key
74
+	 * @param string $status
75
+	 * @return array
76
+	 */
77
+	public function getReviewsMeta($key, $status = 'publish')
78
+	{
79
+		if ('all' == $status || empty($status)) {
80
+			$status = get_post_stati(['exclude_from_search' => false]);
81
+		}
82
+		return glsr(SqlQueries::class)->getReviewsMeta($key, $status);
83
+	}
84 84
 
85
-    /**
86
-     * @param string $field
87
-     * @return array
88
-     */
89
-    public function getTermIds(array $values, $field)
90
-    {
91
-        $termIds = [];
92
-        foreach ($values as $value) {
93
-            $term = get_term_by($field, $value, Application::TAXONOMY);
94
-            if (!isset($term->term_id)) {
95
-                continue;
96
-            }
97
-            $termIds[] = $term->term_id;
98
-        }
99
-        return $termIds;
100
-    }
85
+	/**
86
+	 * @param string $field
87
+	 * @return array
88
+	 */
89
+	public function getTermIds(array $values, $field)
90
+	{
91
+		$termIds = [];
92
+		foreach ($values as $value) {
93
+			$term = get_term_by($field, $value, Application::TAXONOMY);
94
+			if (!isset($term->term_id)) {
95
+				continue;
96
+			}
97
+			$termIds[] = $term->term_id;
98
+		}
99
+		return $termIds;
100
+	}
101 101
 
102
-    /**
103
-     * @return array
104
-     */
105
-    public function getTerms(array $args = [])
106
-    {
107
-        $args = wp_parse_args($args, [
108
-            'count' => false,
109
-            'fields' => 'id=>name',
110
-            'hide_empty' => false,
111
-            'taxonomy' => Application::TAXONOMY,
112
-        ]);
113
-        $terms = get_terms($args);
114
-        if (is_wp_error($terms)) {
115
-            glsr_log()->error($terms->get_error_message());
116
-            return [];
117
-        }
118
-        return $terms;
119
-    }
102
+	/**
103
+	 * @return array
104
+	 */
105
+	public function getTerms(array $args = [])
106
+	{
107
+		$args = wp_parse_args($args, [
108
+			'count' => false,
109
+			'fields' => 'id=>name',
110
+			'hide_empty' => false,
111
+			'taxonomy' => Application::TAXONOMY,
112
+		]);
113
+		$terms = get_terms($args);
114
+		if (is_wp_error($terms)) {
115
+			glsr_log()->error($terms->get_error_message());
116
+			return [];
117
+		}
118
+		return $terms;
119
+	}
120 120
 
121
-    /**
122
-     * @param string $searchTerm
123
-     * @return void|string
124
-     */
125
-    public function searchPosts($searchTerm)
126
-    {
127
-        $args = [
128
-            'post_status' => 'publish',
129
-            'post_type' => 'any',
130
-        ];
131
-        if (is_numeric($searchTerm)) {
132
-            $args['post__in'] = [$searchTerm];
133
-        } else {
134
-            $args['orderby'] = 'relevance';
135
-            $args['posts_per_page'] = 10;
136
-            $args['s'] = $searchTerm;
137
-        }
138
-        $queryBuilder = glsr(QueryBuilder::class);
139
-        add_filter('posts_search', [$queryBuilder, 'filterSearchByTitle'], 500, 2);
140
-        $search = new WP_Query($args);
141
-        remove_filter('posts_search', [$queryBuilder, 'filterSearchByTitle'], 500);
142
-        if (!$search->have_posts()) {
143
-            return;
144
-        }
145
-        $results = '';
146
-        while ($search->have_posts()) {
147
-            $search->the_post();
148
-            ob_start();
149
-            glsr()->render('partials/editor/search-result', [
150
-                'ID' => get_the_ID(),
151
-                'permalink' => esc_url((string) get_permalink()),
152
-                'title' => esc_attr(get_the_title()),
153
-            ]);
154
-            $results.= ob_get_clean();
155
-        }
156
-        wp_reset_postdata();
157
-        return $results;
158
-    }
121
+	/**
122
+	 * @param string $searchTerm
123
+	 * @return void|string
124
+	 */
125
+	public function searchPosts($searchTerm)
126
+	{
127
+		$args = [
128
+			'post_status' => 'publish',
129
+			'post_type' => 'any',
130
+		];
131
+		if (is_numeric($searchTerm)) {
132
+			$args['post__in'] = [$searchTerm];
133
+		} else {
134
+			$args['orderby'] = 'relevance';
135
+			$args['posts_per_page'] = 10;
136
+			$args['s'] = $searchTerm;
137
+		}
138
+		$queryBuilder = glsr(QueryBuilder::class);
139
+		add_filter('posts_search', [$queryBuilder, 'filterSearchByTitle'], 500, 2);
140
+		$search = new WP_Query($args);
141
+		remove_filter('posts_search', [$queryBuilder, 'filterSearchByTitle'], 500);
142
+		if (!$search->have_posts()) {
143
+			return;
144
+		}
145
+		$results = '';
146
+		while ($search->have_posts()) {
147
+			$search->the_post();
148
+			ob_start();
149
+			glsr()->render('partials/editor/search-result', [
150
+				'ID' => get_the_ID(),
151
+				'permalink' => esc_url((string) get_permalink()),
152
+				'title' => esc_attr(get_the_title()),
153
+			]);
154
+			$results.= ob_get_clean();
155
+		}
156
+		wp_reset_postdata();
157
+		return $results;
158
+	}
159 159
 
160
-    /**
161
-     * @param int $postId
162
-     * @param string $key
163
-     * @param mixed $value
164
-     * @return int|bool
165
-     */
166
-    public function set($postId, $key, $value)
167
-    {
168
-        $key = Str::prefix('_', $key);
169
-        return update_post_meta($postId, $key, $value);
170
-    }
160
+	/**
161
+	 * @param int $postId
162
+	 * @param string $key
163
+	 * @param mixed $value
164
+	 * @return int|bool
165
+	 */
166
+	public function set($postId, $key, $value)
167
+	{
168
+		$key = Str::prefix('_', $key);
169
+		return update_post_meta($postId, $key, $value);
170
+	}
171 171
 
172
-    /**
173
-     * @param int $postId
174
-     * @param string $key
175
-     * @param mixed $value
176
-     * @return int|bool
177
-     */
178
-    public function update($postId, $key, $value)
179
-    {
180
-        return $this->set($postId, $key, $value);
181
-    }
172
+	/**
173
+	 * @param int $postId
174
+	 * @param string $key
175
+	 * @param mixed $value
176
+	 * @return int|bool
177
+	 */
178
+	public function update($postId, $key, $value)
179
+	{
180
+		return $this->set($postId, $key, $value);
181
+	}
182 182
 }
Please login to merge, or discard this patch.
helpers.php 1 patch
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -9,25 +9,25 @@  discard block
 block discarded – undo
9 9
  * @return mixed
10 10
  */
11 11
 add_filter('plugins_loaded', function () {
12
-    $hooks = array(
13
-        'glsr_calculate_ratings' => 1,
14
-        'glsr_create_review' => 2,
15
-        'glsr_debug' => 10,
16
-        'glsr_get' => 4,
17
-        'glsr_get_option' => 4,
18
-        'glsr_get_options' => 1,
19
-        'glsr_get_review' => 2,
20
-        'glsr_get_reviews' => 2,
21
-        'glsr_log' => 3,
22
-        'glsr_star_rating' => 2,
23
-    );
24
-    foreach ($hooks as $function => $acceptedArgs) {
25
-        add_filter($function, function () use ($function) {
26
-            $args = func_get_args();
27
-            array_shift($args); // remove the fallback value
28
-            return call_user_func_array($function, $args);
29
-        }, 10, $acceptedArgs);
30
-    }
12
+	$hooks = array(
13
+		'glsr_calculate_ratings' => 1,
14
+		'glsr_create_review' => 2,
15
+		'glsr_debug' => 10,
16
+		'glsr_get' => 4,
17
+		'glsr_get_option' => 4,
18
+		'glsr_get_options' => 1,
19
+		'glsr_get_review' => 2,
20
+		'glsr_get_reviews' => 2,
21
+		'glsr_log' => 3,
22
+		'glsr_star_rating' => 2,
23
+	);
24
+	foreach ($hooks as $function => $acceptedArgs) {
25
+		add_filter($function, function () use ($function) {
26
+			$args = func_get_args();
27
+			array_shift($args); // remove the fallback value
28
+			return call_user_func_array($function, $args);
29
+		}, 10, $acceptedArgs);
30
+	}
31 31
 });
32 32
 
33 33
 /**
@@ -35,10 +35,10 @@  discard block
 block discarded – undo
35 35
  */
36 36
 function glsr($alias = null)
37 37
 {
38
-    $app = \GeminiLabs\SiteReviews\Application::load();
39
-    return !empty($alias)
40
-        ? $app->make($alias)
41
-        : $app;
38
+	$app = \GeminiLabs\SiteReviews\Application::load();
39
+	return !empty($alias)
40
+		? $app->make($alias)
41
+		: $app;
42 42
 }
43 43
 
44 44
 /**
@@ -48,15 +48,15 @@  discard block
 block discarded – undo
48 48
  */
49 49
 function glsr_array_column(array $array, $column)
50 50
 {
51
-    $result = array();
52
-    foreach ($array as $subarray) {
53
-        $subarray = (array) $subarray;
54
-        if (!isset($subarray[$column])) {
55
-            continue;
56
-        }
57
-        $result[] = $subarray[$column];
58
-    }
59
-    return $result;
51
+	$result = array();
52
+	foreach ($array as $subarray) {
53
+		$subarray = (array) $subarray;
54
+		if (!isset($subarray[$column])) {
55
+			continue;
56
+		}
57
+		$result[] = $subarray[$column];
58
+	}
59
+	return $result;
60 60
 }
61 61
 
62 62
 /**
@@ -64,8 +64,8 @@  discard block
 block discarded – undo
64 64
  */
65 65
 function glsr_calculate_ratings()
66 66
 {
67
-    glsr('Controllers\AdminController')->routerCountReviews(false);
68
-    glsr_log()->notice(__('Recalculated rating counts.', 'site-reviews'));
67
+	glsr('Controllers\AdminController')->routerCountReviews(false);
68
+	glsr_log()->notice(__('Recalculated rating counts.', 'site-reviews'));
69 69
 }
70 70
 
71 71
 /**
@@ -73,10 +73,10 @@  discard block
 block discarded – undo
73 73
  */
74 74
 function glsr_create_review($reviewValues = array())
75 75
 {
76
-    $review = new \GeminiLabs\SiteReviews\Commands\CreateReview(
77
-        \GeminiLabs\SiteReviews\Helpers\Arr::consolidateArray($reviewValues)
78
-    );
79
-    return glsr('Database\ReviewManager')->create($review);
76
+	$review = new \GeminiLabs\SiteReviews\Commands\CreateReview(
77
+		\GeminiLabs\SiteReviews\Helpers\Arr::consolidateArray($reviewValues)
78
+	);
79
+	return glsr('Database\ReviewManager')->create($review);
80 80
 }
81 81
 
82 82
 /**
@@ -84,12 +84,12 @@  discard block
 block discarded – undo
84 84
  */
85 85
 function glsr_current_screen()
86 86
 {
87
-    if (function_exists('get_current_screen')) {
88
-        $screen = get_current_screen();
89
-    }
90
-    return empty($screen)
91
-        ? (object) array_fill_keys(['base', 'id', 'post_type'], null)
92
-        : $screen;
87
+	if (function_exists('get_current_screen')) {
88
+		$screen = get_current_screen();
89
+	}
90
+	return empty($screen)
91
+		? (object) array_fill_keys(['base', 'id', 'post_type'], null)
92
+		: $screen;
93 93
 }
94 94
 
95 95
 /**
@@ -98,16 +98,16 @@  discard block
 block discarded – undo
98 98
  */
99 99
 function glsr_debug(...$vars)
100 100
 {
101
-    if (1 == count($vars)) {
102
-        $value = htmlspecialchars(print_r($vars[0], true), ENT_QUOTES, 'UTF-8');
103
-        printf('<div class="glsr-debug"><pre>%s</pre></div>', $value);
104
-    } else {
105
-        echo '<div class="glsr-debug-group">';
106
-        foreach ($vars as $var) {
107
-            glsr_debug($var);
108
-        }
109
-        echo '</div>';
110
-    }
101
+	if (1 == count($vars)) {
102
+		$value = htmlspecialchars(print_r($vars[0], true), ENT_QUOTES, 'UTF-8');
103
+		printf('<div class="glsr-debug"><pre>%s</pre></div>', $value);
104
+	} else {
105
+		echo '<div class="glsr-debug-group">';
106
+		foreach ($vars as $var) {
107
+			glsr_debug($var);
108
+		}
109
+		echo '</div>';
110
+	}
111 111
 }
112 112
 
113 113
 /**
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
  */
119 119
 function glsr_get($array, $path = '', $fallback = '')
120 120
 {
121
-    return \GeminiLabs\SiteReviews\Helpers\Arr::get($array, $path, $fallback);
121
+	return \GeminiLabs\SiteReviews\Helpers\Arr::get($array, $path, $fallback);
122 122
 }
123 123
 
124 124
 /**
@@ -129,9 +129,9 @@  discard block
 block discarded – undo
129 129
  */
130 130
 function glsr_get_option($path = '', $fallback = '', $cast = '')
131 131
 {
132
-    return is_string($path)
133
-        ? glsr('Database\OptionManager')->get(\GeminiLabs\SiteReviews\Helpers\Str::prefix('settings.', $path), $fallback, $cast)
134
-        : $fallback;
132
+	return is_string($path)
133
+		? glsr('Database\OptionManager')->get(\GeminiLabs\SiteReviews\Helpers\Str::prefix('settings.', $path), $fallback, $cast)
134
+		: $fallback;
135 135
 }
136 136
 
137 137
 /**
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
  */
140 140
 function glsr_get_options()
141 141
 {
142
-    return glsr('Database\OptionManager')->get('settings');
142
+	return glsr('Database\OptionManager')->get('settings');
143 143
 }
144 144
 
145 145
 /**
@@ -148,13 +148,13 @@  discard block
 block discarded – undo
148 148
  */
149 149
 function glsr_get_review($post)
150 150
 {
151
-    if (is_numeric($post)) {
152
-        $post = get_post($post);
153
-    }
154
-    if (!($post instanceof WP_Post)) {
155
-        $post = new WP_Post((object) []);
156
-    }
157
-    return glsr('Database\ReviewManager')->single($post);
151
+	if (is_numeric($post)) {
152
+		$post = get_post($post);
153
+	}
154
+	if (!($post instanceof WP_Post)) {
155
+		$post = new WP_Post((object) []);
156
+	}
157
+	return glsr('Database\ReviewManager')->single($post);
158 158
 }
159 159
 
160 160
 /**
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
  */
163 163
 function glsr_get_reviews($args = array())
164 164
 {
165
-    return glsr('Database\ReviewManager')->get(\GeminiLabs\SiteReviews\Helpers\Arr::consolidateArray($args));
165
+	return glsr('Database\ReviewManager')->get(\GeminiLabs\SiteReviews\Helpers\Arr::consolidateArray($args));
166 166
 }
167 167
 
168 168
 /**
@@ -170,12 +170,12 @@  discard block
 block discarded – undo
170 170
  */
171 171
 function glsr_log()
172 172
 {
173
-    $args = func_get_args();
174
-    $console = glsr('Modules\Console');
175
-    if ($value = \GeminiLabs\SiteReviews\Helpers\Arr::get($args, '0')) {
176
-        return $console->debug($value, \GeminiLabs\SiteReviews\Helpers\Arr::get($args, '1', []));
177
-    }
178
-    return $console;
173
+	$args = func_get_args();
174
+	$console = glsr('Modules\Console');
175
+	if ($value = \GeminiLabs\SiteReviews\Helpers\Arr::get($args, '0')) {
176
+		return $console->debug($value, \GeminiLabs\SiteReviews\Helpers\Arr::get($args, '1', []));
177
+	}
178
+	return $console;
179 179
 }
180 180
 
181 181
 /**
@@ -183,5 +183,5 @@  discard block
 block discarded – undo
183 183
  */
184 184
 function glsr_star_rating($rating)
185 185
 {
186
-    return glsr('Modules\Html\Partial')->build('star-rating', ['rating' => $rating]);
186
+	return glsr('Modules\Html\Partial')->build('star-rating', ['rating' => $rating]);
187 187
 }
Please login to merge, or discard this patch.