Passed
Push — master ( ccb079...7906b4 )
by Paul
04:39
created
plugin/Helpers/Arr.php 1 patch
Indentation   +211 added lines, -211 removed lines patch added patch discarded remove patch
@@ -4,215 +4,215 @@
 block discarded – undo
4 4
 
5 5
 class Arr
6 6
 {
7
-    /**
8
-     * @return bool
9
-     */
10
-    public static function compare(array $arr1, array $arr2)
11
-    {
12
-        sort($arr1);
13
-        sort($arr2);
14
-        return $arr1 == $arr2;
15
-    }
16
-
17
-    /**
18
-     * @param mixed $array
19
-     * @return array
20
-     */
21
-    public static function consolidate($array)
22
-    {
23
-        return is_array($array) || is_object($array)
24
-            ? (array) $array
25
-            : [];
26
-    }
27
-
28
-    /**
29
-     * @return array
30
-     */
31
-    public static function convertFromDotNotation(array $array)
32
-    {
33
-        $results = [];
34
-        foreach ($array as $path => $value) {
35
-            $results = static::set($results, $path, $value);
36
-        }
37
-        return $results;
38
-    }
39
-
40
-    /**
41
-     * @param string $string
42
-     * @param mixed $callback
43
-     * @return array
44
-     */
45
-    public static function convertFromString($string, $callback = null)
46
-    {
47
-        $array = array_map('trim', explode(',', $string));
48
-        return $callback
49
-            ? array_filter($array, $callback)
50
-            : array_filter($array);
51
-    }
52
-
53
-    /**
54
-     * @param bool $flattenValue
55
-     * @param string $prefix
56
-     * @return array
57
-     */
58
-    public static function flatten(array $array, $flattenValue = false, $prefix = '')
59
-    {
60
-        $result = [];
61
-        foreach ($array as $key => $value) {
62
-            $newKey = ltrim($prefix.'.'.$key, '.');
63
-            if (static::isIndexedAndFlat($value)) {
64
-                if ($flattenValue) {
65
-                    $value = '['.implode(', ', $value).']';
66
-                }
67
-            } elseif (is_array($value)) {
68
-                $result = array_merge($result, static::flatten($value, $flattenValue, $newKey));
69
-                continue;
70
-            }
71
-            $result[$newKey] = $value;
72
-        }
73
-        return $result;
74
-    }
75
-
76
-    /**
77
-     * Get a value from an array of values using a dot-notation path as reference.
78
-     * @param mixed $data
79
-     * @param string $path
80
-     * @param mixed $fallback
81
-     * @return mixed
82
-     */
83
-    public static function get($data, $path = '', $fallback = '')
84
-    {
85
-        $data = static::consolidate($data);
86
-        $keys = explode('.', $path);
87
-        foreach ($keys as $key) {
88
-            if (!isset($data[$key])) {
89
-                return $fallback;
90
-            }
91
-            $data = $data[$key];
92
-        }
93
-        return $data;
94
-    }
95
-
96
-    /**
97
-     * @param string $key
98
-     * @return array
99
-     */
100
-    public static function insertAfter($key, array $array, array $insert)
101
-    {
102
-        return static::insert($array, $insert, $key, 'after');
103
-    }
104
-
105
-    /**
106
-     * @param string $key
107
-     * @return array
108
-     */
109
-    public static function insertBefore($key, array $array, array $insert)
110
-    {
111
-        return static::insert($array, $insert, $key, 'before');
112
-    }
113
-
114
-    /**
115
-     * @param string $key
116
-     * @param string $position
117
-     * @return array
118
-     */
119
-    public static function insert(array $array, array $insert, $key, $position = 'before')
120
-    {
121
-        $keyPosition = intval(array_search($key, array_keys($array)));
122
-        if ('after' == $position) {
123
-            ++$keyPosition;
124
-        }
125
-        if (false !== $keyPosition) {
126
-            $result = array_slice($array, 0, $keyPosition);
127
-            $result = array_merge($result, $insert);
128
-            return array_merge($result, array_slice($array, $keyPosition));
129
-        }
130
-        return array_merge($array, $insert);
131
-    }
132
-
133
-    /**
134
-     * @param mixed $array
135
-     * @return bool
136
-     */
137
-    public static function isIndexedAndFlat($array)
138
-    {
139
-        if (!is_array($array) || array_filter($array, 'is_array')) {
140
-            return false;
141
-        }
142
-        return wp_is_numeric_array($array);
143
-    }
144
-
145
-    /**
146
-     * @param bool $prefixed
147
-     * @return array
148
-     */
149
-    public static function prefixKeys(array $values, $prefixed = true)
150
-    {
151
-        $trim = '_';
152
-        $prefix = $prefixed
153
-            ? $trim
154
-            : '';
155
-        $prefixed = [];
156
-        foreach ($values as $key => $value) {
157
-            $key = trim($key);
158
-            if (0 === strpos($key, $trim)) {
159
-                $key = substr($key, strlen($trim));
160
-            }
161
-            $prefixed[$prefix.$key] = $value;
162
-        }
163
-        return $prefixed;
164
-    }
165
-
166
-    /**
167
-     * @return array
168
-     */
169
-    public static function removeEmptyValues(array $array)
170
-    {
171
-        $result = [];
172
-        foreach ($array as $key => $value) {
173
-            if (!$value) {
174
-                continue;
175
-            }
176
-            $result[$key] = is_array($value)
177
-                ? static::removeEmptyValues($value)
178
-                : $value;
179
-        }
180
-        return $result;
181
-    }
182
-
183
-
184
-    /**
185
-     * Set a value to an array of values using a dot-notation path as reference.
186
-     * @param string $path
187
-     * @param mixed $value
188
-     * @return array
189
-     */
190
-    public static function set(array $data, $path, $value)
191
-    {
192
-        $token = strtok($path, '.');
193
-        $ref = &$data;
194
-        while (false !== $token) {
195
-            $ref = static::consolidate($ref);
196
-            $ref = &$ref[$token];
197
-            $token = strtok('.');
198
-        }
199
-        $ref = $value;
200
-        return $data;
201
-    }
202
-
203
-    /**
204
-     * @return array
205
-     */
206
-    public static function unique(array $values)
207
-    {
208
-        return array_filter(array_unique($values));
209
-    }
210
-
211
-    /**
212
-     * @return array
213
-     */
214
-    public static function unprefixKeys(array $values)
215
-    {
216
-        return static::prefixKeys($values, false);
217
-    }
7
+	/**
8
+	 * @return bool
9
+	 */
10
+	public static function compare(array $arr1, array $arr2)
11
+	{
12
+		sort($arr1);
13
+		sort($arr2);
14
+		return $arr1 == $arr2;
15
+	}
16
+
17
+	/**
18
+	 * @param mixed $array
19
+	 * @return array
20
+	 */
21
+	public static function consolidate($array)
22
+	{
23
+		return is_array($array) || is_object($array)
24
+			? (array) $array
25
+			: [];
26
+	}
27
+
28
+	/**
29
+	 * @return array
30
+	 */
31
+	public static function convertFromDotNotation(array $array)
32
+	{
33
+		$results = [];
34
+		foreach ($array as $path => $value) {
35
+			$results = static::set($results, $path, $value);
36
+		}
37
+		return $results;
38
+	}
39
+
40
+	/**
41
+	 * @param string $string
42
+	 * @param mixed $callback
43
+	 * @return array
44
+	 */
45
+	public static function convertFromString($string, $callback = null)
46
+	{
47
+		$array = array_map('trim', explode(',', $string));
48
+		return $callback
49
+			? array_filter($array, $callback)
50
+			: array_filter($array);
51
+	}
52
+
53
+	/**
54
+	 * @param bool $flattenValue
55
+	 * @param string $prefix
56
+	 * @return array
57
+	 */
58
+	public static function flatten(array $array, $flattenValue = false, $prefix = '')
59
+	{
60
+		$result = [];
61
+		foreach ($array as $key => $value) {
62
+			$newKey = ltrim($prefix.'.'.$key, '.');
63
+			if (static::isIndexedAndFlat($value)) {
64
+				if ($flattenValue) {
65
+					$value = '['.implode(', ', $value).']';
66
+				}
67
+			} elseif (is_array($value)) {
68
+				$result = array_merge($result, static::flatten($value, $flattenValue, $newKey));
69
+				continue;
70
+			}
71
+			$result[$newKey] = $value;
72
+		}
73
+		return $result;
74
+	}
75
+
76
+	/**
77
+	 * Get a value from an array of values using a dot-notation path as reference.
78
+	 * @param mixed $data
79
+	 * @param string $path
80
+	 * @param mixed $fallback
81
+	 * @return mixed
82
+	 */
83
+	public static function get($data, $path = '', $fallback = '')
84
+	{
85
+		$data = static::consolidate($data);
86
+		$keys = explode('.', $path);
87
+		foreach ($keys as $key) {
88
+			if (!isset($data[$key])) {
89
+				return $fallback;
90
+			}
91
+			$data = $data[$key];
92
+		}
93
+		return $data;
94
+	}
95
+
96
+	/**
97
+	 * @param string $key
98
+	 * @return array
99
+	 */
100
+	public static function insertAfter($key, array $array, array $insert)
101
+	{
102
+		return static::insert($array, $insert, $key, 'after');
103
+	}
104
+
105
+	/**
106
+	 * @param string $key
107
+	 * @return array
108
+	 */
109
+	public static function insertBefore($key, array $array, array $insert)
110
+	{
111
+		return static::insert($array, $insert, $key, 'before');
112
+	}
113
+
114
+	/**
115
+	 * @param string $key
116
+	 * @param string $position
117
+	 * @return array
118
+	 */
119
+	public static function insert(array $array, array $insert, $key, $position = 'before')
120
+	{
121
+		$keyPosition = intval(array_search($key, array_keys($array)));
122
+		if ('after' == $position) {
123
+			++$keyPosition;
124
+		}
125
+		if (false !== $keyPosition) {
126
+			$result = array_slice($array, 0, $keyPosition);
127
+			$result = array_merge($result, $insert);
128
+			return array_merge($result, array_slice($array, $keyPosition));
129
+		}
130
+		return array_merge($array, $insert);
131
+	}
132
+
133
+	/**
134
+	 * @param mixed $array
135
+	 * @return bool
136
+	 */
137
+	public static function isIndexedAndFlat($array)
138
+	{
139
+		if (!is_array($array) || array_filter($array, 'is_array')) {
140
+			return false;
141
+		}
142
+		return wp_is_numeric_array($array);
143
+	}
144
+
145
+	/**
146
+	 * @param bool $prefixed
147
+	 * @return array
148
+	 */
149
+	public static function prefixKeys(array $values, $prefixed = true)
150
+	{
151
+		$trim = '_';
152
+		$prefix = $prefixed
153
+			? $trim
154
+			: '';
155
+		$prefixed = [];
156
+		foreach ($values as $key => $value) {
157
+			$key = trim($key);
158
+			if (0 === strpos($key, $trim)) {
159
+				$key = substr($key, strlen($trim));
160
+			}
161
+			$prefixed[$prefix.$key] = $value;
162
+		}
163
+		return $prefixed;
164
+	}
165
+
166
+	/**
167
+	 * @return array
168
+	 */
169
+	public static function removeEmptyValues(array $array)
170
+	{
171
+		$result = [];
172
+		foreach ($array as $key => $value) {
173
+			if (!$value) {
174
+				continue;
175
+			}
176
+			$result[$key] = is_array($value)
177
+				? static::removeEmptyValues($value)
178
+				: $value;
179
+		}
180
+		return $result;
181
+	}
182
+
183
+
184
+	/**
185
+	 * Set a value to an array of values using a dot-notation path as reference.
186
+	 * @param string $path
187
+	 * @param mixed $value
188
+	 * @return array
189
+	 */
190
+	public static function set(array $data, $path, $value)
191
+	{
192
+		$token = strtok($path, '.');
193
+		$ref = &$data;
194
+		while (false !== $token) {
195
+			$ref = static::consolidate($ref);
196
+			$ref = &$ref[$token];
197
+			$token = strtok('.');
198
+		}
199
+		$ref = $value;
200
+		return $data;
201
+	}
202
+
203
+	/**
204
+	 * @return array
205
+	 */
206
+	public static function unique(array $values)
207
+	{
208
+		return array_filter(array_unique($values));
209
+	}
210
+
211
+	/**
212
+	 * @return array
213
+	 */
214
+	public static function unprefixKeys(array $values)
215
+	{
216
+		return static::prefixKeys($values, false);
217
+	}
218 218
 }
Please login to merge, or discard this patch.
plugin/Widgets/SiteReviewsSummaryWidget.php 1 patch
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -7,58 +7,58 @@
 block discarded – undo
7 7
 
8 8
 class SiteReviewsSummaryWidget extends Widget
9 9
 {
10
-    /**
11
-     * @param array $instance
12
-     * @return void
13
-     */
14
-    public function form($instance)
15
-    {
16
-        $this->widgetArgs = $this->shortcode()->normalizeAtts($instance);
17
-        $terms = glsr(Database::class)->getTerms();
18
-        $this->renderField('text', [
19
-            'class' => 'widefat',
20
-            'label' => __('Title', 'site-reviews'),
21
-            'name' => 'title',
22
-        ]);
23
-        if (count(glsr()->reviewTypes) > 1) {
24
-            $this->renderField('select', [
25
-                'class' => 'widefat',
26
-                'label' => __('Which type of review would you like to use?', 'site-reviews'),
27
-                'name' => 'type',
28
-                'options' => ['' => __('All review types', 'site-reviews')] + glsr()->reviewTypes,
29
-            ]);
30
-        }
31
-        if (!empty($terms)) {
32
-            $this->renderField('select', [
33
-                'class' => 'widefat',
34
-                'label' => __('Limit summary to this category', 'site-reviews'),
35
-                'name' => 'category',
36
-                'options' => ['' => __('All Categories', 'site-reviews')] + $terms,
37
-            ]);
38
-        }
39
-        $this->renderField('text', [
40
-            'class' => 'widefat',
41
-            'default' => '',
42
-            'description' => sprintf(__("Separate multiple ID's with a comma. You may also enter %s to automatically represent the current page/post ID.", 'site-reviews'), '<code>post_id</code>'),
43
-            'label' => __('Limit summary to reviews assigned to a page/post ID', 'site-reviews'),
44
-            'name' => 'assigned_to',
45
-        ]);
46
-        $this->renderField('text', [
47
-            'class' => 'widefat',
48
-            'label' => __('Enter any custom CSS classes here', 'site-reviews'),
49
-            'name' => 'class',
50
-        ]);
51
-        $this->renderField('checkbox', [
52
-            'name' => 'hide',
53
-            'options' => $this->shortcode()->getHideOptions(),
54
-        ]);
55
-    }
10
+	/**
11
+	 * @param array $instance
12
+	 * @return void
13
+	 */
14
+	public function form($instance)
15
+	{
16
+		$this->widgetArgs = $this->shortcode()->normalizeAtts($instance);
17
+		$terms = glsr(Database::class)->getTerms();
18
+		$this->renderField('text', [
19
+			'class' => 'widefat',
20
+			'label' => __('Title', 'site-reviews'),
21
+			'name' => 'title',
22
+		]);
23
+		if (count(glsr()->reviewTypes) > 1) {
24
+			$this->renderField('select', [
25
+				'class' => 'widefat',
26
+				'label' => __('Which type of review would you like to use?', 'site-reviews'),
27
+				'name' => 'type',
28
+				'options' => ['' => __('All review types', 'site-reviews')] + glsr()->reviewTypes,
29
+			]);
30
+		}
31
+		if (!empty($terms)) {
32
+			$this->renderField('select', [
33
+				'class' => 'widefat',
34
+				'label' => __('Limit summary to this category', 'site-reviews'),
35
+				'name' => 'category',
36
+				'options' => ['' => __('All Categories', 'site-reviews')] + $terms,
37
+			]);
38
+		}
39
+		$this->renderField('text', [
40
+			'class' => 'widefat',
41
+			'default' => '',
42
+			'description' => sprintf(__("Separate multiple ID's with a comma. You may also enter %s to automatically represent the current page/post ID.", 'site-reviews'), '<code>post_id</code>'),
43
+			'label' => __('Limit summary to reviews assigned to a page/post ID', 'site-reviews'),
44
+			'name' => 'assigned_to',
45
+		]);
46
+		$this->renderField('text', [
47
+			'class' => 'widefat',
48
+			'label' => __('Enter any custom CSS classes here', 'site-reviews'),
49
+			'name' => 'class',
50
+		]);
51
+		$this->renderField('checkbox', [
52
+			'name' => 'hide',
53
+			'options' => $this->shortcode()->getHideOptions(),
54
+		]);
55
+	}
56 56
 
57
-    /**
58
-     * {@inheritdoc}
59
-     */
60
-    protected function shortcode()
61
-    {
62
-        return glsr(SiteReviewsSummaryShortcode::class);
63
-    }
57
+	/**
58
+	 * {@inheritdoc}
59
+	 */
60
+	protected function shortcode()
61
+	{
62
+		return glsr(SiteReviewsSummaryShortcode::class);
63
+	}
64 64
 }
Please login to merge, or discard this patch.
plugin/Widgets/SiteReviewsWidget.php 1 patch
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -7,91 +7,91 @@
 block discarded – undo
7 7
 
8 8
 class SiteReviewsWidget extends Widget
9 9
 {
10
-    /**
11
-     * @param array $instance
12
-     * @return void
13
-     */
14
-    public function form($instance)
15
-    {
16
-        $this->widgetArgs = $this->shortcode()->normalizeAtts($instance);
17
-        $terms = glsr(Database::class)->getTerms();
18
-        $this->renderField('text', [
19
-            'class' => 'widefat',
20
-            'label' => __('Title', 'site-reviews'),
21
-            'name' => 'title',
22
-        ]);
23
-        $this->renderField('number', [
24
-            'class' => 'small-text',
25
-            'default' => 10,
26
-            'label' => __('How many reviews would you like to display?', 'site-reviews'),
27
-            'max' => 100,
28
-            'name' => 'display',
29
-        ]);
30
-        $this->renderField('select', [
31
-            'label' => __('What is the minimum rating to display?', 'site-reviews'),
32
-            'name' => 'rating',
33
-            'options' => [
34
-                '0' => sprintf(_n('%s star', '%s stars', 0, 'site-reviews'), 0),
35
-                '1' => sprintf(_n('%s star', '%s stars', 1, 'site-reviews'), 1),
36
-                '2' => sprintf(_n('%s star', '%s stars', 2, 'site-reviews'), 2),
37
-                '3' => sprintf(_n('%s star', '%s stars', 3, 'site-reviews'), 3),
38
-                '4' => sprintf(_n('%s star', '%s stars', 4, 'site-reviews'), 4),
39
-                '5' => sprintf(_n('%s star', '%s stars', 5, 'site-reviews'), 5),
40
-            ],
41
-        ]);
42
-        if (count(glsr()->reviewTypes) > 1) {
43
-            $this->renderField('select', [
44
-                'class' => 'widefat',
45
-                'label' => __('Which type of review would you like to display?', 'site-reviews'),
46
-                'name' => 'type',
47
-                'options' => ['' => __('All Reviews', 'site-reviews')] + glsr()->reviewTypes,
48
-            ]);
49
-        }
50
-        if (!empty($terms)) {
51
-            $this->renderField('select', [
52
-                'class' => 'widefat',
53
-                'label' => __('Limit reviews to this category', 'site-reviews'),
54
-                'name' => 'category',
55
-                'options' => ['' => __('All Categories', 'site-reviews')] + $terms,
56
-            ]);
57
-        }
58
-        $this->renderField('text', [
59
-            'class' => 'widefat',
60
-            'default' => '',
61
-            'description' => sprintf(__("Separate multiple ID's with a comma. You may also enter %s to automatically represent the current page/post ID.", 'site-reviews'), '<code>post_id</code>'),
62
-            'label' => __('Limit reviews to those assigned to this page/post ID', 'site-reviews'),
63
-            'name' => 'assigned_to',
64
-        ]);
65
-        $this->renderField('text', [
66
-            'class' => 'widefat',
67
-            'label' => __('Enter any custom CSS classes here', 'site-reviews'),
68
-            'name' => 'class',
69
-        ]);
70
-        $this->renderField('checkbox', [
71
-            'name' => 'hide',
72
-            'options' => $this->shortcode()->getHideOptions(),
73
-        ]);
74
-    }
10
+	/**
11
+	 * @param array $instance
12
+	 * @return void
13
+	 */
14
+	public function form($instance)
15
+	{
16
+		$this->widgetArgs = $this->shortcode()->normalizeAtts($instance);
17
+		$terms = glsr(Database::class)->getTerms();
18
+		$this->renderField('text', [
19
+			'class' => 'widefat',
20
+			'label' => __('Title', 'site-reviews'),
21
+			'name' => 'title',
22
+		]);
23
+		$this->renderField('number', [
24
+			'class' => 'small-text',
25
+			'default' => 10,
26
+			'label' => __('How many reviews would you like to display?', 'site-reviews'),
27
+			'max' => 100,
28
+			'name' => 'display',
29
+		]);
30
+		$this->renderField('select', [
31
+			'label' => __('What is the minimum rating to display?', 'site-reviews'),
32
+			'name' => 'rating',
33
+			'options' => [
34
+				'0' => sprintf(_n('%s star', '%s stars', 0, 'site-reviews'), 0),
35
+				'1' => sprintf(_n('%s star', '%s stars', 1, 'site-reviews'), 1),
36
+				'2' => sprintf(_n('%s star', '%s stars', 2, 'site-reviews'), 2),
37
+				'3' => sprintf(_n('%s star', '%s stars', 3, 'site-reviews'), 3),
38
+				'4' => sprintf(_n('%s star', '%s stars', 4, 'site-reviews'), 4),
39
+				'5' => sprintf(_n('%s star', '%s stars', 5, 'site-reviews'), 5),
40
+			],
41
+		]);
42
+		if (count(glsr()->reviewTypes) > 1) {
43
+			$this->renderField('select', [
44
+				'class' => 'widefat',
45
+				'label' => __('Which type of review would you like to display?', 'site-reviews'),
46
+				'name' => 'type',
47
+				'options' => ['' => __('All Reviews', 'site-reviews')] + glsr()->reviewTypes,
48
+			]);
49
+		}
50
+		if (!empty($terms)) {
51
+			$this->renderField('select', [
52
+				'class' => 'widefat',
53
+				'label' => __('Limit reviews to this category', 'site-reviews'),
54
+				'name' => 'category',
55
+				'options' => ['' => __('All Categories', 'site-reviews')] + $terms,
56
+			]);
57
+		}
58
+		$this->renderField('text', [
59
+			'class' => 'widefat',
60
+			'default' => '',
61
+			'description' => sprintf(__("Separate multiple ID's with a comma. You may also enter %s to automatically represent the current page/post ID.", 'site-reviews'), '<code>post_id</code>'),
62
+			'label' => __('Limit reviews to those assigned to this page/post ID', 'site-reviews'),
63
+			'name' => 'assigned_to',
64
+		]);
65
+		$this->renderField('text', [
66
+			'class' => 'widefat',
67
+			'label' => __('Enter any custom CSS classes here', 'site-reviews'),
68
+			'name' => 'class',
69
+		]);
70
+		$this->renderField('checkbox', [
71
+			'name' => 'hide',
72
+			'options' => $this->shortcode()->getHideOptions(),
73
+		]);
74
+	}
75 75
 
76
-    /**
77
-     * @param array $newInstance
78
-     * @param array $oldInstance
79
-     * @return array
80
-     */
81
-    public function update($newInstance, $oldInstance)
82
-    {
83
-        if (!is_numeric($newInstance['display'])) {
84
-            $newInstance['display'] = 10;
85
-        }
86
-        $newInstance['display'] = min(50, max(0, intval($newInstance['display'])));
87
-        return parent::update($newInstance, $oldInstance);
88
-    }
76
+	/**
77
+	 * @param array $newInstance
78
+	 * @param array $oldInstance
79
+	 * @return array
80
+	 */
81
+	public function update($newInstance, $oldInstance)
82
+	{
83
+		if (!is_numeric($newInstance['display'])) {
84
+			$newInstance['display'] = 10;
85
+		}
86
+		$newInstance['display'] = min(50, max(0, intval($newInstance['display'])));
87
+		return parent::update($newInstance, $oldInstance);
88
+	}
89 89
 
90
-    /**
91
-     * {@inheritdoc}
92
-     */
93
-    protected function shortcode()
94
-    {
95
-        return glsr(SiteReviewsShortcode::class);
96
-    }
90
+	/**
91
+	 * {@inheritdoc}
92
+	 */
93
+	protected function shortcode()
94
+	{
95
+		return glsr(SiteReviewsShortcode::class);
96
+	}
97 97
 }
Please login to merge, or discard this patch.
plugin/Widgets/SiteReviewsFormWidget.php 1 patch
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -7,53 +7,53 @@
 block discarded – undo
7 7
 
8 8
 class SiteReviewsFormWidget extends Widget
9 9
 {
10
-    /**
11
-     * @param array $instance
12
-     * @return void
13
-     */
14
-    public function form($instance)
15
-    {
16
-        $this->widgetArgs = $this->shortcode()->normalizeAtts($instance);
17
-        $terms = glsr(Database::class)->getTerms();
18
-        $this->renderField('text', [
19
-            'class' => 'widefat',
20
-            'label' => __('Title', 'site-reviews'),
21
-            'name' => 'title',
22
-        ]);
23
-        $this->renderField('textarea', [
24
-            'class' => 'widefat',
25
-            'label' => __('Description', 'site-reviews'),
26
-            'name' => 'description',
27
-        ]);
28
-        $this->renderField('select', [
29
-            'class' => 'widefat',
30
-            'label' => __('Automatically assign a category', 'site-reviews'),
31
-            'name' => 'category',
32
-            'options' => ['' => __('Do not assign a category', 'site-reviews')] + $terms,
33
-        ]);
34
-        $this->renderField('text', [
35
-            'class' => 'widefat',
36
-            'default' => '',
37
-            'description' => sprintf(__('You may also enter %s to assign to the current post.', 'site-reviews'), '<code>post_id</code>'),
38
-            'label' => __('Assign reviews to a custom page/post ID', 'site-reviews'),
39
-            'name' => 'assign_to',
40
-        ]);
41
-        $this->renderField('text', [
42
-            'class' => 'widefat',
43
-            'label' => __('Enter any custom CSS classes here', 'site-reviews'),
44
-            'name' => 'class',
45
-        ]);
46
-        $this->renderField('checkbox', [
47
-            'name' => 'hide',
48
-            'options' => $this->shortcode()->getHideOptions(),
49
-        ]);
50
-    }
10
+	/**
11
+	 * @param array $instance
12
+	 * @return void
13
+	 */
14
+	public function form($instance)
15
+	{
16
+		$this->widgetArgs = $this->shortcode()->normalizeAtts($instance);
17
+		$terms = glsr(Database::class)->getTerms();
18
+		$this->renderField('text', [
19
+			'class' => 'widefat',
20
+			'label' => __('Title', 'site-reviews'),
21
+			'name' => 'title',
22
+		]);
23
+		$this->renderField('textarea', [
24
+			'class' => 'widefat',
25
+			'label' => __('Description', 'site-reviews'),
26
+			'name' => 'description',
27
+		]);
28
+		$this->renderField('select', [
29
+			'class' => 'widefat',
30
+			'label' => __('Automatically assign a category', 'site-reviews'),
31
+			'name' => 'category',
32
+			'options' => ['' => __('Do not assign a category', 'site-reviews')] + $terms,
33
+		]);
34
+		$this->renderField('text', [
35
+			'class' => 'widefat',
36
+			'default' => '',
37
+			'description' => sprintf(__('You may also enter %s to assign to the current post.', 'site-reviews'), '<code>post_id</code>'),
38
+			'label' => __('Assign reviews to a custom page/post ID', 'site-reviews'),
39
+			'name' => 'assign_to',
40
+		]);
41
+		$this->renderField('text', [
42
+			'class' => 'widefat',
43
+			'label' => __('Enter any custom CSS classes here', 'site-reviews'),
44
+			'name' => 'class',
45
+		]);
46
+		$this->renderField('checkbox', [
47
+			'name' => 'hide',
48
+			'options' => $this->shortcode()->getHideOptions(),
49
+		]);
50
+	}
51 51
 
52
-    /**
53
-     * {@inheritdoc}
54
-     */
55
-    protected function shortcode()
56
-    {
57
-        return glsr(SiteReviewsFormShortcode::class);
58
-    }
52
+	/**
53
+	 * {@inheritdoc}
54
+	 */
55
+	protected function shortcode()
56
+	{
57
+		return glsr(SiteReviewsFormShortcode::class);
58
+	}
59 59
 }
Please login to merge, or discard this patch.
plugin/Widgets/Widget.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -7,54 +7,54 @@
 block discarded – undo
7 7
 
8 8
 abstract class Widget extends WP_Widget
9 9
 {
10
-    /**
11
-     * @var array
12
-     */
13
-    protected $widgetArgs;
10
+	/**
11
+	 * @var array
12
+	 */
13
+	protected $widgetArgs;
14 14
 
15
-    /**
16
-     * @param array $args
17
-     * @param array $instance
18
-     * @return void
19
-     */
20
-    public function widget($args, $instance)
21
-    {
22
-        echo $this->shortcode()->build($instance, $args, 'widget');
23
-    }
15
+	/**
16
+	 * @param array $args
17
+	 * @param array $instance
18
+	 * @return void
19
+	 */
20
+	public function widget($args, $instance)
21
+	{
22
+		echo $this->shortcode()->build($instance, $args, 'widget');
23
+	}
24 24
 
25
-    /**
26
-     * @param string $tag
27
-     * @return array
28
-     */
29
-    protected function normalizeFieldAttributes($tag, array $args)
30
-    {
31
-        if (empty($args['value'])) {
32
-            $args['value'] = $this->widgetArgs[$args['name']];
33
-        }
34
-        if (empty($this->widgetArgs['options']) && in_array($tag, ['checkbox', 'radio'])) {
35
-            $args['checked'] = in_array($args['value'], (array) $this->widgetArgs[$args['name']]);
36
-        }
37
-        $args['id'] = $this->get_field_id($args['name']);
38
-        $args['name'] = $this->get_field_name($args['name']);
39
-        $args['is_widget'] = true;
40
-        return $args;
41
-    }
25
+	/**
26
+	 * @param string $tag
27
+	 * @return array
28
+	 */
29
+	protected function normalizeFieldAttributes($tag, array $args)
30
+	{
31
+		if (empty($args['value'])) {
32
+			$args['value'] = $this->widgetArgs[$args['name']];
33
+		}
34
+		if (empty($this->widgetArgs['options']) && in_array($tag, ['checkbox', 'radio'])) {
35
+			$args['checked'] = in_array($args['value'], (array) $this->widgetArgs[$args['name']]);
36
+		}
37
+		$args['id'] = $this->get_field_id($args['name']);
38
+		$args['name'] = $this->get_field_name($args['name']);
39
+		$args['is_widget'] = true;
40
+		return $args;
41
+	}
42 42
 
43
-    /**
44
-     * @param string $tag
45
-     * @return void
46
-     */
47
-    protected function renderField($tag, array $args = [])
48
-    {
49
-        $args = $this->normalizeFieldAttributes($tag, $args);
50
-        $field = glsr(Builder::class)->$tag($args['name'], $args);
51
-        echo glsr(Builder::class)->div($field, [
52
-            'class' => 'glsr-field',
53
-        ]);
54
-    }
43
+	/**
44
+	 * @param string $tag
45
+	 * @return void
46
+	 */
47
+	protected function renderField($tag, array $args = [])
48
+	{
49
+		$args = $this->normalizeFieldAttributes($tag, $args);
50
+		$field = glsr(Builder::class)->$tag($args['name'], $args);
51
+		echo glsr(Builder::class)->div($field, [
52
+			'class' => 'glsr-field',
53
+		]);
54
+	}
55 55
 
56
-    /**
57
-     * @return \GeminiLabs\SiteReviews\Shortcodes\Shortcode
58
-     */
59
-    abstract protected function shortcode();
56
+	/**
57
+	 * @return \GeminiLabs\SiteReviews\Shortcodes\Shortcode
58
+	 */
59
+	abstract protected function shortcode();
60 60
 }
Please login to merge, or discard this patch.
plugin/Contracts/ShortcodeContract.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -4,15 +4,15 @@
 block discarded – undo
4 4
 
5 5
 interface ShortcodeContract
6 6
 {
7
-    /**
8
-     * @params string|array $atts
9
-     * @return string
10
-     */
11
-    public function buildBlock($atts = []);
7
+	/**
8
+	 * @params string|array $atts
9
+	 * @return string
10
+	 */
11
+	public function buildBlock($atts = []);
12 12
 
13
-    /**
14
-     * @param string|array $atts
15
-     * @return string
16
-     */
17
-    public function buildShortcode($atts = []);
13
+	/**
14
+	 * @param string|array $atts
15
+	 * @return string
16
+	 */
17
+	public function buildShortcode($atts = []);
18 18
 }
Please login to merge, or discard this patch.
plugin/Shortcodes/Shortcode.php 1 patch
Indentation   +222 added lines, -222 removed lines patch added patch discarded remove patch
@@ -14,248 +14,248 @@
 block discarded – undo
14 14
 
15 15
 abstract class Shortcode implements ShortcodeContract
16 16
 {
17
-    /**
18
-     * @var string
19
-     */
20
-    protected $partialName;
17
+	/**
18
+	 * @var string
19
+	 */
20
+	protected $partialName;
21 21
 
22
-    /**
23
-     * @var string
24
-     */
25
-    protected $shortcodeName;
22
+	/**
23
+	 * @var string
24
+	 */
25
+	protected $shortcodeName;
26 26
 
27
-    public function __construct()
28
-    {
29
-        $this->partialName = $this->getShortcodePartialName();
30
-        $this->shortcodeName = $this->getShortcodeName();
31
-    }
27
+	public function __construct()
28
+	{
29
+		$this->partialName = $this->getShortcodePartialName();
30
+		$this->shortcodeName = $this->getShortcodeName();
31
+	}
32 32
 
33
-    /**
34
-     * @param string|array $atts
35
-     * @param string $type
36
-     * @return string
37
-     */
38
-    public function build($atts, array $args = [], $type = 'shortcode')
39
-    {
40
-        $args = $this->normalizeArgs($args, $type);
41
-        $atts = $this->normalizeAtts($atts, $type);
42
-        $partial = glsr(Partial::class)->build($this->partialName, $atts);
43
-        if (!empty($atts['title'])) {
44
-            $atts = Arr::set($atts, 'title', $args['before_title'].$atts['title'].$args['after_title']);
45
-        }
46
-        $html = glsr(Builder::class)->div((string) $partial, [
47
-            'class' => 'glsr glsr-'.glsr(Style::class)->get(),
48
-            'data-shortcode' => Str::snakeCase($this->partialName),
49
-            'data-type' => $type,
50
-            'data-atts' => $atts['json'], // I prefer to have this attribute displayed last
51
-        ]);
52
-        return $args['before_widget'].$atts['title'].$html.$args['after_widget'];
53
-    }
33
+	/**
34
+	 * @param string|array $atts
35
+	 * @param string $type
36
+	 * @return string
37
+	 */
38
+	public function build($atts, array $args = [], $type = 'shortcode')
39
+	{
40
+		$args = $this->normalizeArgs($args, $type);
41
+		$atts = $this->normalizeAtts($atts, $type);
42
+		$partial = glsr(Partial::class)->build($this->partialName, $atts);
43
+		if (!empty($atts['title'])) {
44
+			$atts = Arr::set($atts, 'title', $args['before_title'].$atts['title'].$args['after_title']);
45
+		}
46
+		$html = glsr(Builder::class)->div((string) $partial, [
47
+			'class' => 'glsr glsr-'.glsr(Style::class)->get(),
48
+			'data-shortcode' => Str::snakeCase($this->partialName),
49
+			'data-type' => $type,
50
+			'data-atts' => $atts['json'], // I prefer to have this attribute displayed last
51
+		]);
52
+		return $args['before_widget'].$atts['title'].$html.$args['after_widget'];
53
+	}
54 54
 
55
-    /**
56
-     * {@inheritdoc}
57
-     */
58
-    public function buildBlock($atts = [])
59
-    {
60
-        return $this->build($atts, [], 'block');
61
-    }
55
+	/**
56
+	 * {@inheritdoc}
57
+	 */
58
+	public function buildBlock($atts = [])
59
+	{
60
+		return $this->build($atts, [], 'block');
61
+	}
62 62
 
63
-    /**
64
-     * {@inheritdoc}
65
-     */
66
-    public function buildShortcode($atts = [])
67
-    {
68
-        return $this->build($atts, [], 'shortcode');
69
-    }
63
+	/**
64
+	 * {@inheritdoc}
65
+	 */
66
+	public function buildShortcode($atts = [])
67
+	{
68
+		return $this->build($atts, [], 'shortcode');
69
+	}
70 70
 
71
-    /**
72
-     * @return array
73
-     */
74
-    public function getDefaults($atts)
75
-    {
76
-        return glsr($this->getShortcodeDefaultsClassName())->restrict(wp_parse_args($atts));
77
-    }
71
+	/**
72
+	 * @return array
73
+	 */
74
+	public function getDefaults($atts)
75
+	{
76
+		return glsr($this->getShortcodeDefaultsClassName())->restrict(wp_parse_args($atts));
77
+	}
78 78
 
79
-    /**
80
-     * @return array
81
-     */
82
-    public function getHideOptions()
83
-    {
84
-        $options = $this->hideOptions();
85
-        return apply_filters('site-reviews/shortcode/hide-options', $options, $this->shortcodeName);
86
-    }
79
+	/**
80
+	 * @return array
81
+	 */
82
+	public function getHideOptions()
83
+	{
84
+		$options = $this->hideOptions();
85
+		return apply_filters('site-reviews/shortcode/hide-options', $options, $this->shortcodeName);
86
+	}
87 87
 
88
-    /**
89
-     * @return string
90
-     */
91
-    public function getShortClassName($replace = '', $search = 'Shortcode')
92
-    {
93
-        return str_replace($search, $replace, (new ReflectionClass($this))->getShortName());
94
-    }
88
+	/**
89
+	 * @return string
90
+	 */
91
+	public function getShortClassName($replace = '', $search = 'Shortcode')
92
+	{
93
+		return str_replace($search, $replace, (new ReflectionClass($this))->getShortName());
94
+	}
95 95
 
96
-    /**
97
-     * @return string
98
-     */
99
-    public function getShortcodeDefaultsClassName()
100
-    {
101
-        $className = Str::replaceLast('Shortcode', 'Defaults', get_class($this));
102
-        return str_replace('Shortcodes', 'Defaults', $className);
103
-    }
96
+	/**
97
+	 * @return string
98
+	 */
99
+	public function getShortcodeDefaultsClassName()
100
+	{
101
+		$className = Str::replaceLast('Shortcode', 'Defaults', get_class($this));
102
+		return str_replace('Shortcodes', 'Defaults', $className);
103
+	}
104 104
 
105
-    /**
106
-     * @return string
107
-     */
108
-    public function getShortcodeName()
109
-    {
110
-        return Str::snakeCase($this->getShortClassName());
111
-    }
105
+	/**
106
+	 * @return string
107
+	 */
108
+	public function getShortcodeName()
109
+	{
110
+		return Str::snakeCase($this->getShortClassName());
111
+	}
112 112
 
113
-    /**
114
-     * @return string
115
-     */
116
-    public function getShortcodePartialName()
117
-    {
118
-        return Str::dashCase($this->getShortClassName());
119
-    }
113
+	/**
114
+	 * @return string
115
+	 */
116
+	public function getShortcodePartialName()
117
+	{
118
+		return Str::dashCase($this->getShortClassName());
119
+	}
120 120
 
121
-    /**
122
-     * @param array|string $args
123
-     * @param string $type
124
-     * @return array
125
-     */
126
-    public function normalizeArgs($args, $type = 'shortcode')
127
-    {
128
-        $args = wp_parse_args($args, [
129
-            'before_widget' => '',
130
-            'after_widget' => '',
131
-            'before_title' => '<h2 class="glsr-title">',
132
-            'after_title' => '</h2>',
133
-        ]);
134
-        return apply_filters('site-reviews/shortcode/args', $args, $type, $this->partialName);
135
-    }
121
+	/**
122
+	 * @param array|string $args
123
+	 * @param string $type
124
+	 * @return array
125
+	 */
126
+	public function normalizeArgs($args, $type = 'shortcode')
127
+	{
128
+		$args = wp_parse_args($args, [
129
+			'before_widget' => '',
130
+			'after_widget' => '',
131
+			'before_title' => '<h2 class="glsr-title">',
132
+			'after_title' => '</h2>',
133
+		]);
134
+		return apply_filters('site-reviews/shortcode/args', $args, $type, $this->partialName);
135
+	}
136 136
 
137
-    /**
138
-     * @param array|string $atts
139
-     * @param string $type
140
-     * @return array
141
-     */
142
-    public function normalizeAtts($atts, $type = 'shortcode')
143
-    {
144
-        $atts = apply_filters('site-reviews/shortcode/atts', $atts, $type, $this->partialName);
145
-        $atts = $this->getDefaults($atts);
146
-        array_walk($atts, function (&$value, $key) {
147
-            $methodName = Helper::buildMethodName($key, 'normalize');
148
-            if (!method_exists($this, $methodName)) {
149
-                return;
150
-            }
151
-            $value = $this->$methodName($value);
152
-        });
153
-        $this->setId($atts);
154
-        return $atts;
155
-    }
137
+	/**
138
+	 * @param array|string $atts
139
+	 * @param string $type
140
+	 * @return array
141
+	 */
142
+	public function normalizeAtts($atts, $type = 'shortcode')
143
+	{
144
+		$atts = apply_filters('site-reviews/shortcode/atts', $atts, $type, $this->partialName);
145
+		$atts = $this->getDefaults($atts);
146
+		array_walk($atts, function (&$value, $key) {
147
+			$methodName = Helper::buildMethodName($key, 'normalize');
148
+			if (!method_exists($this, $methodName)) {
149
+				return;
150
+			}
151
+			$value = $this->$methodName($value);
152
+		});
153
+		$this->setId($atts);
154
+		return $atts;
155
+	}
156 156
 
157
-    /**
158
-     * @return array
159
-     */
160
-    abstract protected function hideOptions();
157
+	/**
158
+	 * @return array
159
+	 */
160
+	abstract protected function hideOptions();
161 161
 
162
-    /**
163
-     * @param string $postId
164
-     * @return int|string
165
-     */
166
-    protected function normalizeAssignedTo($postId)
167
-    {
168
-        if ('parent_id' == $postId) {
169
-            $postId = intval(wp_get_post_parent_id(intval(get_the_ID())));
170
-        } elseif ('post_id' == $postId) {
171
-            $postId = intval(get_the_ID());
172
-        }
173
-        return $postId;
174
-    }
162
+	/**
163
+	 * @param string $postId
164
+	 * @return int|string
165
+	 */
166
+	protected function normalizeAssignedTo($postId)
167
+	{
168
+		if ('parent_id' == $postId) {
169
+			$postId = intval(wp_get_post_parent_id(intval(get_the_ID())));
170
+		} elseif ('post_id' == $postId) {
171
+			$postId = intval(get_the_ID());
172
+		}
173
+		return $postId;
174
+	}
175 175
 
176
-    /**
177
-     * @param string $postId
178
-     * @return int|string
179
-     */
180
-    protected function normalizeAssignTo($postId)
181
-    {
182
-        return $this->normalizeAssignedTo($postId);
183
-    }
176
+	/**
177
+	 * @param string $postId
178
+	 * @return int|string
179
+	 */
180
+	protected function normalizeAssignTo($postId)
181
+	{
182
+		return $this->normalizeAssignedTo($postId);
183
+	}
184 184
 
185
-    /**
186
-     * @param string|array $hide
187
-     * @return array
188
-     */
189
-    protected function normalizeHide($hide)
190
-    {
191
-        if (is_string($hide)) {
192
-            $hide = explode(',', $hide);
193
-        }
194
-        $hideKeys = array_keys($this->getHideOptions());
195
-        return array_filter(array_map('trim', $hide), function ($value) use ($hideKeys) {
196
-            return in_array($value, $hideKeys);
197
-        });
198
-    }
185
+	/**
186
+	 * @param string|array $hide
187
+	 * @return array
188
+	 */
189
+	protected function normalizeHide($hide)
190
+	{
191
+		if (is_string($hide)) {
192
+			$hide = explode(',', $hide);
193
+		}
194
+		$hideKeys = array_keys($this->getHideOptions());
195
+		return array_filter(array_map('trim', $hide), function ($value) use ($hideKeys) {
196
+			return in_array($value, $hideKeys);
197
+		});
198
+	}
199 199
 
200
-    /**
201
-     * @param string $id
202
-     * @return string
203
-     */
204
-    protected function normalizeId($id)
205
-    {
206
-        return sanitize_title($id);
207
-    }
200
+	/**
201
+	 * @param string $id
202
+	 * @return string
203
+	 */
204
+	protected function normalizeId($id)
205
+	{
206
+		return sanitize_title($id);
207
+	}
208 208
 
209
-    /**
210
-     * @param string $labels
211
-     * @return array
212
-     */
213
-    protected function normalizeLabels($labels)
214
-    {
215
-        $defaults = [
216
-            __('Excellent', 'site-reviews'),
217
-            __('Very good', 'site-reviews'),
218
-            __('Average', 'site-reviews'),
219
-            __('Poor', 'site-reviews'),
220
-            __('Terrible', 'site-reviews'),
221
-        ];
222
-        $maxRating = (int) glsr()->constant('MAX_RATING', Rating::class);
223
-        $defaults = array_pad(array_slice($defaults, 0, $maxRating), $maxRating, '');
224
-        $labels = array_map('trim', explode(',', $labels));
225
-        foreach ($defaults as $i => $label) {
226
-            if (empty($labels[$i])) {
227
-                continue;
228
-            }
229
-            $defaults[$i] = $labels[$i];
230
-        }
231
-        return array_combine(range($maxRating, 1), $defaults);
232
-    }
209
+	/**
210
+	 * @param string $labels
211
+	 * @return array
212
+	 */
213
+	protected function normalizeLabels($labels)
214
+	{
215
+		$defaults = [
216
+			__('Excellent', 'site-reviews'),
217
+			__('Very good', 'site-reviews'),
218
+			__('Average', 'site-reviews'),
219
+			__('Poor', 'site-reviews'),
220
+			__('Terrible', 'site-reviews'),
221
+		];
222
+		$maxRating = (int) glsr()->constant('MAX_RATING', Rating::class);
223
+		$defaults = array_pad(array_slice($defaults, 0, $maxRating), $maxRating, '');
224
+		$labels = array_map('trim', explode(',', $labels));
225
+		foreach ($defaults as $i => $label) {
226
+			if (empty($labels[$i])) {
227
+				continue;
228
+			}
229
+			$defaults[$i] = $labels[$i];
230
+		}
231
+		return array_combine(range($maxRating, 1), $defaults);
232
+	}
233 233
 
234
-    /**
235
-     * @param string $schema
236
-     * @return bool
237
-     */
238
-    protected function normalizeSchema($schema)
239
-    {
240
-        return wp_validate_boolean($schema);
241
-    }
234
+	/**
235
+	 * @param string $schema
236
+	 * @return bool
237
+	 */
238
+	protected function normalizeSchema($schema)
239
+	{
240
+		return wp_validate_boolean($schema);
241
+	}
242 242
 
243
-    /**
244
-     * @param string $text
245
-     * @return string
246
-     */
247
-    protected function normalizeText($text)
248
-    {
249
-        return trim($text);
250
-    }
243
+	/**
244
+	 * @param string $text
245
+	 * @return string
246
+	 */
247
+	protected function normalizeText($text)
248
+	{
249
+		return trim($text);
250
+	}
251 251
 
252
-    /**
253
-     * @return void
254
-     */
255
-    protected function setId(array &$atts)
256
-    {
257
-        if (empty($atts['id'])) {
258
-            $atts['id'] = Application::PREFIX.substr(md5(serialize($atts)), 0, 8);
259
-        }
260
-    }
252
+	/**
253
+	 * @return void
254
+	 */
255
+	protected function setId(array &$atts)
256
+	{
257
+		if (empty($atts['id'])) {
258
+			$atts['id'] = Application::PREFIX.substr(md5(serialize($atts)), 0, 8);
259
+		}
260
+	}
261 261
 }
Please login to merge, or discard this patch.
plugin/Commands/RegisterWidgets.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -4,16 +4,16 @@
 block discarded – undo
4 4
 
5 5
 class RegisterWidgets
6 6
 {
7
-    public $widgets;
7
+	public $widgets;
8 8
 
9
-    public function __construct(array $input)
10
-    {
11
-        array_walk($input, function (&$args, $id) {
12
-            $args = wp_parse_args($args, [
13
-                'description' => '',
14
-                'name' => '',
15
-            ]);
16
-        });
17
-        $this->widgets = $input;
18
-    }
9
+	public function __construct(array $input)
10
+	{
11
+		array_walk($input, function (&$args, $id) {
12
+			$args = wp_parse_args($args, [
13
+				'description' => '',
14
+				'name' => '',
15
+			]);
16
+		});
17
+		$this->widgets = $input;
18
+	}
19 19
 }
Please login to merge, or discard this patch.
plugin/Commands/CreateReview.php 1 patch
Indentation   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -6,145 +6,145 @@
 block discarded – undo
6 6
 
7 7
 class CreateReview
8 8
 {
9
-    public $ajax_request;
10
-    public $assigned_to;
11
-    public $author;
12
-    public $avatar;
13
-    public $blacklisted;
14
-    public $category;
15
-    public $content;
16
-    public $custom;
17
-    public $date;
18
-    public $email;
19
-    public $form_id;
20
-    public $ip_address;
21
-    public $post_id;
22
-    public $rating;
23
-    public $referer;
24
-    public $request;
25
-    public $response;
26
-    public $terms;
27
-    public $title;
28
-    public $url;
9
+	public $ajax_request;
10
+	public $assigned_to;
11
+	public $author;
12
+	public $avatar;
13
+	public $blacklisted;
14
+	public $category;
15
+	public $content;
16
+	public $custom;
17
+	public $date;
18
+	public $email;
19
+	public $form_id;
20
+	public $ip_address;
21
+	public $post_id;
22
+	public $rating;
23
+	public $referer;
24
+	public $request;
25
+	public $response;
26
+	public $terms;
27
+	public $title;
28
+	public $url;
29 29
 
30
-    public function __construct($input)
31
-    {
32
-        $this->request = $input;
33
-        $this->ajax_request = isset($input['_ajax_request']);
34
-        $this->assigned_to = $this->getNumeric('assign_to');
35
-        $this->author = sanitize_text_field($this->getUser('name'));
36
-        $this->avatar = $this->getAvatar();
37
-        $this->blacklisted = isset($input['blacklisted']);
38
-        $this->category = $this->getCategory();
39
-        $this->content = sanitize_textarea_field($this->get('content'));
40
-        $this->custom = $this->getCustom();
41
-        $this->date = $this->getDate('date');
42
-        $this->email = sanitize_email($this->getUser('email'));
43
-        $this->form_id = sanitize_key($this->get('form_id'));
44
-        $this->ip_address = $this->get('ip_address');
45
-        $this->post_id = intval($this->get('_post_id'));
46
-        $this->rating = intval($this->get('rating'));
47
-        $this->referer = sanitize_text_field($this->get('_referer'));
48
-        $this->response = sanitize_textarea_field($this->get('response'));
49
-        $this->terms = !empty($input['terms']);
50
-        $this->title = sanitize_text_field($this->get('title'));
51
-        $this->url = esc_url_raw(sanitize_text_field($this->get('url')));
52
-    }
30
+	public function __construct($input)
31
+	{
32
+		$this->request = $input;
33
+		$this->ajax_request = isset($input['_ajax_request']);
34
+		$this->assigned_to = $this->getNumeric('assign_to');
35
+		$this->author = sanitize_text_field($this->getUser('name'));
36
+		$this->avatar = $this->getAvatar();
37
+		$this->blacklisted = isset($input['blacklisted']);
38
+		$this->category = $this->getCategory();
39
+		$this->content = sanitize_textarea_field($this->get('content'));
40
+		$this->custom = $this->getCustom();
41
+		$this->date = $this->getDate('date');
42
+		$this->email = sanitize_email($this->getUser('email'));
43
+		$this->form_id = sanitize_key($this->get('form_id'));
44
+		$this->ip_address = $this->get('ip_address');
45
+		$this->post_id = intval($this->get('_post_id'));
46
+		$this->rating = intval($this->get('rating'));
47
+		$this->referer = sanitize_text_field($this->get('_referer'));
48
+		$this->response = sanitize_textarea_field($this->get('response'));
49
+		$this->terms = !empty($input['terms']);
50
+		$this->title = sanitize_text_field($this->get('title'));
51
+		$this->url = esc_url_raw(sanitize_text_field($this->get('url')));
52
+	}
53 53
 
54
-    /**
55
-     * @param string $key
56
-     * @return string
57
-     */
58
-    protected function get($key)
59
-    {
60
-        return (string) Arr::get($this->request, $key);
61
-    }
54
+	/**
55
+	 * @param string $key
56
+	 * @return string
57
+	 */
58
+	protected function get($key)
59
+	{
60
+		return (string) Arr::get($this->request, $key);
61
+	}
62 62
 
63
-    /**
64
-     * @return string
65
-     */
66
-    protected function getAvatar()
67
-    {
68
-        $avatar = $this->get('avatar');
69
-        return !filter_var($avatar, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED)
70
-            ? (string) get_avatar_url($this->get('email'))
71
-            : $avatar;
72
-    }
63
+	/**
64
+	 * @return string
65
+	 */
66
+	protected function getAvatar()
67
+	{
68
+		$avatar = $this->get('avatar');
69
+		return !filter_var($avatar, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED)
70
+			? (string) get_avatar_url($this->get('email'))
71
+			: $avatar;
72
+	}
73 73
 
74
-    /**
75
-     * @return string
76
-     */
77
-    protected function getCategory()
78
-    {
79
-        $categories = Arr::convertFromString($this->get('category'));
80
-        return sanitize_key(Arr::get($categories, 0));
81
-    }
74
+	/**
75
+	 * @return string
76
+	 */
77
+	protected function getCategory()
78
+	{
79
+		$categories = Arr::convertFromString($this->get('category'));
80
+		return sanitize_key(Arr::get($categories, 0));
81
+	}
82 82
 
83
-    /**
84
-     * @return array
85
-     */
86
-    protected function getCustom()
87
-    {
88
-        $unset = [
89
-            '_action', '_ajax_request', '_counter', '_nonce', '_post_id', '_recaptcha-token',
90
-            '_referer', 'assign_to', 'category', 'content', 'date', 'email', 'excluded', 'form_id',
91
-            'gotcha', 'ip_address', 'name', 'rating', 'response', 'terms', 'title', 'url',
92
-        ];
93
-        $unset = apply_filters('site-reviews/create/unset-keys-from-custom', $unset);
94
-        $custom = $this->request;
95
-        foreach ($unset as $key) {
96
-            unset($custom[$key]);
97
-        }
98
-        foreach ($custom as $key => $value) {
99
-            if (is_string($value)) {
100
-                $custom[$key] = sanitize_text_field($value);
101
-            }
102
-        }
103
-        return $custom;
104
-    }
83
+	/**
84
+	 * @return array
85
+	 */
86
+	protected function getCustom()
87
+	{
88
+		$unset = [
89
+			'_action', '_ajax_request', '_counter', '_nonce', '_post_id', '_recaptcha-token',
90
+			'_referer', 'assign_to', 'category', 'content', 'date', 'email', 'excluded', 'form_id',
91
+			'gotcha', 'ip_address', 'name', 'rating', 'response', 'terms', 'title', 'url',
92
+		];
93
+		$unset = apply_filters('site-reviews/create/unset-keys-from-custom', $unset);
94
+		$custom = $this->request;
95
+		foreach ($unset as $key) {
96
+			unset($custom[$key]);
97
+		}
98
+		foreach ($custom as $key => $value) {
99
+			if (is_string($value)) {
100
+				$custom[$key] = sanitize_text_field($value);
101
+			}
102
+		}
103
+		return $custom;
104
+	}
105 105
 
106
-    /**
107
-     * @param string $key
108
-     * @return string
109
-     */
110
-    protected function getDate($key)
111
-    {
112
-        $date = strtotime($this->get($key));
113
-        if (false === $date) {
114
-            $date = time();
115
-        }
116
-        return get_date_from_gmt(gmdate('Y-m-d H:i:s', $date));
117
-    }
106
+	/**
107
+	 * @param string $key
108
+	 * @return string
109
+	 */
110
+	protected function getDate($key)
111
+	{
112
+		$date = strtotime($this->get($key));
113
+		if (false === $date) {
114
+			$date = time();
115
+		}
116
+		return get_date_from_gmt(gmdate('Y-m-d H:i:s', $date));
117
+	}
118 118
 
119
-    /**
120
-     * @param string $key
121
-     * @return string
122
-     */
123
-    protected function getUser($key)
124
-    {
125
-        $value = $this->get($key);
126
-        if (empty($value)) {
127
-            $user = wp_get_current_user();
128
-            $userValues = [
129
-                'email' => 'user_email',
130
-                'name' => 'display_name',
131
-            ];
132
-            if ($user->exists() && array_key_exists($key, $userValues)) {
133
-                return $user->{$userValues[$key]};
134
-            }
135
-        }
136
-        return $value;
137
-    }
119
+	/**
120
+	 * @param string $key
121
+	 * @return string
122
+	 */
123
+	protected function getUser($key)
124
+	{
125
+		$value = $this->get($key);
126
+		if (empty($value)) {
127
+			$user = wp_get_current_user();
128
+			$userValues = [
129
+				'email' => 'user_email',
130
+				'name' => 'display_name',
131
+			];
132
+			if ($user->exists() && array_key_exists($key, $userValues)) {
133
+				return $user->{$userValues[$key]};
134
+			}
135
+		}
136
+		return $value;
137
+	}
138 138
 
139
-    /**
140
-     * @param string $key
141
-     * @return string
142
-     */
143
-    protected function getNumeric($key)
144
-    {
145
-        $value = $this->get($key);
146
-        return is_numeric($value)
147
-            ? $value
148
-            : '';
149
-    }
139
+	/**
140
+	 * @param string $key
141
+	 * @return string
142
+	 */
143
+	protected function getNumeric($key)
144
+	{
145
+		$value = $this->get($key);
146
+		return is_numeric($value)
147
+			? $value
148
+			: '';
149
+	}
150 150
 }
Please login to merge, or discard this patch.