Passed
Push — master ( ccb079...7906b4 )
by Paul
04:39
created
plugin/Blocks/SiteReviewsBlock.php 1 patch
Indentation   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -6,114 +6,114 @@
 block discarded – undo
6 6
 
7 7
 class SiteReviewsBlock extends BlockGenerator
8 8
 {
9
-    /**
10
-     * @return array
11
-     */
12
-    public function attributes()
13
-    {
14
-        return [
15
-            'assigned_to' => [
16
-                'default' => '',
17
-                'type' => 'string',
18
-            ],
19
-            'category' => [
20
-                'default' => '',
21
-                'type' => 'string',
22
-            ],
23
-            'className' => [
24
-                'default' => '',
25
-                'type' => 'string',
26
-            ],
27
-            'display' => [
28
-                'default' => 5,
29
-                'type' => 'number',
30
-            ],
31
-            'hide' => [
32
-                'default' => '',
33
-                'type' => 'string',
34
-            ],
35
-            'id' => [
36
-                'default' => '',
37
-                'type' => 'string',
38
-            ],
39
-            'pagination' => [
40
-                'default' => '',
41
-                'type' => 'string',
42
-            ],
43
-            'post_id' => [
44
-                'default' => '',
45
-                'type' => 'string',
46
-            ],
47
-            'rating' => [
48
-                'default' => 0,
49
-                'type' => 'number',
50
-            ],
51
-            'schema' => [
52
-                'default' => false,
53
-                'type' => 'boolean',
54
-            ],
55
-            'type' => [
56
-                'default' => 'local',
57
-                'type' => 'string',
58
-            ],
59
-        ];
60
-    }
9
+	/**
10
+	 * @return array
11
+	 */
12
+	public function attributes()
13
+	{
14
+		return [
15
+			'assigned_to' => [
16
+				'default' => '',
17
+				'type' => 'string',
18
+			],
19
+			'category' => [
20
+				'default' => '',
21
+				'type' => 'string',
22
+			],
23
+			'className' => [
24
+				'default' => '',
25
+				'type' => 'string',
26
+			],
27
+			'display' => [
28
+				'default' => 5,
29
+				'type' => 'number',
30
+			],
31
+			'hide' => [
32
+				'default' => '',
33
+				'type' => 'string',
34
+			],
35
+			'id' => [
36
+				'default' => '',
37
+				'type' => 'string',
38
+			],
39
+			'pagination' => [
40
+				'default' => '',
41
+				'type' => 'string',
42
+			],
43
+			'post_id' => [
44
+				'default' => '',
45
+				'type' => 'string',
46
+			],
47
+			'rating' => [
48
+				'default' => 0,
49
+				'type' => 'number',
50
+			],
51
+			'schema' => [
52
+				'default' => false,
53
+				'type' => 'boolean',
54
+			],
55
+			'type' => [
56
+				'default' => 'local',
57
+				'type' => 'string',
58
+			],
59
+		];
60
+	}
61 61
 
62
-    /**
63
-     * @return string
64
-     */
65
-    public function render(array $attributes)
66
-    {
67
-        $attributes['class'] = $attributes['className'];
68
-        $shortcode = glsr(Shortcode::class);
69
-        if ('edit' == filter_input(INPUT_GET, 'context')) {
70
-            $attributes = $this->normalize($attributes);
71
-            $this->filterBlockClass();
72
-            $this->filterReviewLinks();
73
-            $this->filterShowMoreLinks('content');
74
-            $this->filterShowMoreLinks('response');
75
-            if (!$this->hasVisibleFields($shortcode, $attributes)) {
76
-                $this->filterInterpolation();
77
-            }
78
-        }
79
-        return $shortcode->buildBlock($attributes);
80
-    }
62
+	/**
63
+	 * @return string
64
+	 */
65
+	public function render(array $attributes)
66
+	{
67
+		$attributes['class'] = $attributes['className'];
68
+		$shortcode = glsr(Shortcode::class);
69
+		if ('edit' == filter_input(INPUT_GET, 'context')) {
70
+			$attributes = $this->normalize($attributes);
71
+			$this->filterBlockClass();
72
+			$this->filterReviewLinks();
73
+			$this->filterShowMoreLinks('content');
74
+			$this->filterShowMoreLinks('response');
75
+			if (!$this->hasVisibleFields($shortcode, $attributes)) {
76
+				$this->filterInterpolation();
77
+			}
78
+		}
79
+		return $shortcode->buildBlock($attributes);
80
+	}
81 81
 
82
-    /**
83
-     * @return void
84
-     */
85
-    protected function filterInterpolation()
86
-    {
87
-        add_filter('site-reviews/interpolate/reviews', function ($context) {
88
-            $context['class'] = 'glsr-default glsr-block-disabled';
89
-            $context['reviews'] = __('You have hidden all of the fields for this block.', 'site-reviews');
90
-            return $context;
91
-        });
92
-    }
82
+	/**
83
+	 * @return void
84
+	 */
85
+	protected function filterInterpolation()
86
+	{
87
+		add_filter('site-reviews/interpolate/reviews', function ($context) {
88
+			$context['class'] = 'glsr-default glsr-block-disabled';
89
+			$context['reviews'] = __('You have hidden all of the fields for this block.', 'site-reviews');
90
+			return $context;
91
+		});
92
+	}
93 93
 
94
-    /**
95
-     * @return void
96
-     */
97
-    protected function filterReviewLinks()
98
-    {
99
-        add_filter('site-reviews/rendered/template/reviews', function ($template) {
100
-            return str_replace('<a', '<a tabindex="-1"', $template);
101
-        });
102
-    }
94
+	/**
95
+	 * @return void
96
+	 */
97
+	protected function filterReviewLinks()
98
+	{
99
+		add_filter('site-reviews/rendered/template/reviews', function ($template) {
100
+			return str_replace('<a', '<a tabindex="-1"', $template);
101
+		});
102
+	}
103 103
 
104
-    /**
105
-     * @param string $field
106
-     * @return void
107
-     */
108
-    protected function filterShowMoreLinks($field)
109
-    {
110
-        add_filter('site-reviews/review/wrap/'.$field, function ($value) {
111
-            $value = preg_replace(
112
-                '/(.*)(<span class="glsr-hidden)(.*)(<\/span>)(.*)/s',
113
-                '$1... <a href="#" class="glsr-read-more" tabindex="-1">'.__('Show more', 'site-reviews').'</a>$5',
114
-                $value
115
-            );
116
-            return $value;
117
-        });
118
-    }
104
+	/**
105
+	 * @param string $field
106
+	 * @return void
107
+	 */
108
+	protected function filterShowMoreLinks($field)
109
+	{
110
+		add_filter('site-reviews/review/wrap/'.$field, function ($value) {
111
+			$value = preg_replace(
112
+				'/(.*)(<span class="glsr-hidden)(.*)(<\/span>)(.*)/s',
113
+				'$1... <a href="#" class="glsr-read-more" tabindex="-1">'.__('Show more', 'site-reviews').'</a>$5',
114
+				$value
115
+			);
116
+			return $value;
117
+		});
118
+	}
119 119
 }
Please login to merge, or discard this patch.
plugin/Blocks/SiteReviewsSummaryBlock.php 1 patch
Indentation   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -6,73 +6,73 @@
 block discarded – undo
6 6
 
7 7
 class SiteReviewsSummaryBlock extends BlockGenerator
8 8
 {
9
-    /**
10
-     * @return array
11
-     */
12
-    public function attributes()
13
-    {
14
-        return [
15
-            'assigned_to' => [
16
-                'default' => '',
17
-                'type' => 'string',
18
-            ],
19
-            'category' => [
20
-                'default' => '',
21
-                'type' => 'string',
22
-            ],
23
-            'className' => [
24
-                'default' => '',
25
-                'type' => 'string',
26
-            ],
27
-            'hide' => [
28
-                'default' => '',
29
-                'type' => 'string',
30
-            ],
31
-            'post_id' => [
32
-                'default' => '',
33
-                'type' => 'string',
34
-            ],
35
-            'rating' => [
36
-                'default' => '1',
37
-                'type' => 'number',
38
-            ],
39
-            'schema' => [
40
-                'default' => false,
41
-                'type' => 'boolean',
42
-            ],
43
-            'type' => [
44
-                'default' => 'local',
45
-                'type' => 'string',
46
-            ],
47
-        ];
48
-    }
9
+	/**
10
+	 * @return array
11
+	 */
12
+	public function attributes()
13
+	{
14
+		return [
15
+			'assigned_to' => [
16
+				'default' => '',
17
+				'type' => 'string',
18
+			],
19
+			'category' => [
20
+				'default' => '',
21
+				'type' => 'string',
22
+			],
23
+			'className' => [
24
+				'default' => '',
25
+				'type' => 'string',
26
+			],
27
+			'hide' => [
28
+				'default' => '',
29
+				'type' => 'string',
30
+			],
31
+			'post_id' => [
32
+				'default' => '',
33
+				'type' => 'string',
34
+			],
35
+			'rating' => [
36
+				'default' => '1',
37
+				'type' => 'number',
38
+			],
39
+			'schema' => [
40
+				'default' => false,
41
+				'type' => 'boolean',
42
+			],
43
+			'type' => [
44
+				'default' => 'local',
45
+				'type' => 'string',
46
+			],
47
+		];
48
+	}
49 49
 
50
-    /**
51
-     * @return string
52
-     */
53
-    public function render(array $attributes)
54
-    {
55
-        $attributes['class'] = $attributes['className'];
56
-        $shortcode = glsr(Shortcode::class);
57
-        if ('edit' == filter_input(INPUT_GET, 'context')) {
58
-            $attributes = $this->normalize($attributes);
59
-            $this->filterBlockClass();
60
-            if (!$this->hasVisibleFields($shortcode, $attributes)) {
61
-                $this->filterInterpolation();
62
-            }
63
-        }
64
-        return $shortcode->buildBlock($attributes);
65
-    }
50
+	/**
51
+	 * @return string
52
+	 */
53
+	public function render(array $attributes)
54
+	{
55
+		$attributes['class'] = $attributes['className'];
56
+		$shortcode = glsr(Shortcode::class);
57
+		if ('edit' == filter_input(INPUT_GET, 'context')) {
58
+			$attributes = $this->normalize($attributes);
59
+			$this->filterBlockClass();
60
+			if (!$this->hasVisibleFields($shortcode, $attributes)) {
61
+				$this->filterInterpolation();
62
+			}
63
+		}
64
+		return $shortcode->buildBlock($attributes);
65
+	}
66 66
 
67
-    /**
68
-     * @return void
69
-     */
70
-    protected function filterInterpolation()
71
-    {
72
-        add_filter('site-reviews/interpolate/reviews-summary', function ($context) {
73
-            $context['class'] = 'glsr-default glsr-block-disabled';
74
-            $context['text'] = __('You have hidden all of the fields for this block.', 'site-reviews');
75
-            return $context;
76
-        });
77
-    }
67
+	/**
68
+	 * @return void
69
+	 */
70
+	protected function filterInterpolation()
71
+	{
72
+		add_filter('site-reviews/interpolate/reviews-summary', function ($context) {
73
+			$context['class'] = 'glsr-default glsr-block-disabled';
74
+			$context['text'] = __('You have hidden all of the fields for this block.', 'site-reviews');
75
+			return $context;
76
+		});
77
+	}
78 78
 }
Please login to merge, or discard this patch.
plugin/Blocks/BlockGenerator.php 1 patch
Indentation   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -7,72 +7,72 @@
 block discarded – undo
7 7
 
8 8
 abstract class BlockGenerator
9 9
 {
10
-    /**
11
-     * @return array
12
-     */
13
-    public function attributes()
14
-    {
15
-        return [];
16
-    }
10
+	/**
11
+	 * @return array
12
+	 */
13
+	public function attributes()
14
+	{
15
+		return [];
16
+	}
17 17
 
18
-    /**
19
-     * @return array
20
-     */
21
-    public function normalize(array $attributes)
22
-    {
23
-        $hide = array_flip(explode(',', $attributes['hide']));
24
-        unset($hide['if_empty']);
25
-        $attributes['hide'] = implode(',', array_keys($hide));
26
-        if ('post_id' === Arr::get($attributes, 'assigned_to')) {
27
-            $attributes['assigned_to'] = $attributes['post_id'];
28
-        } elseif ('parent_id' === Arr::get($attributes, 'assigned_to')) {
29
-            $attributes['assigned_to'] = wp_get_post_parent_id($attributes['post_id']);
30
-        }
31
-        return $attributes;
32
-    }
18
+	/**
19
+	 * @return array
20
+	 */
21
+	public function normalize(array $attributes)
22
+	{
23
+		$hide = array_flip(explode(',', $attributes['hide']));
24
+		unset($hide['if_empty']);
25
+		$attributes['hide'] = implode(',', array_keys($hide));
26
+		if ('post_id' === Arr::get($attributes, 'assigned_to')) {
27
+			$attributes['assigned_to'] = $attributes['post_id'];
28
+		} elseif ('parent_id' === Arr::get($attributes, 'assigned_to')) {
29
+			$attributes['assigned_to'] = wp_get_post_parent_id($attributes['post_id']);
30
+		}
31
+		return $attributes;
32
+	}
33 33
 
34
-    /**
35
-     * @return void
36
-     */
37
-    public function register($block)
38
-    {
39
-        if (!function_exists('register_block_type')) {
40
-            return;
41
-        }
42
-        register_block_type(Application::ID.'/'.$block, [
43
-            'attributes' => $this->attributes(),
44
-            'editor_script' => Application::ID.'/blocks',
45
-            'editor_style' => Application::ID.'/blocks',
46
-            'render_callback' => [$this, 'render'],
47
-            'style' => Application::ID,
48
-        ]);
49
-    }
34
+	/**
35
+	 * @return void
36
+	 */
37
+	public function register($block)
38
+	{
39
+		if (!function_exists('register_block_type')) {
40
+			return;
41
+		}
42
+		register_block_type(Application::ID.'/'.$block, [
43
+			'attributes' => $this->attributes(),
44
+			'editor_script' => Application::ID.'/blocks',
45
+			'editor_style' => Application::ID.'/blocks',
46
+			'render_callback' => [$this, 'render'],
47
+			'style' => Application::ID,
48
+		]);
49
+	}
50 50
 
51
-    /**
52
-     * @return void
53
-     */
54
-    abstract public function render(array $attributes);
51
+	/**
52
+	 * @return void
53
+	 */
54
+	abstract public function render(array $attributes);
55 55
 
56
-    /**
57
-     * @return void
58
-     */
59
-    protected function filterBlockClass()
60
-    {
61
-        add_filter('site-reviews/style', function () {
62
-            return 'default';
63
-        });
64
-    }
56
+	/**
57
+	 * @return void
58
+	 */
59
+	protected function filterBlockClass()
60
+	{
61
+		add_filter('site-reviews/style', function () {
62
+			return 'default';
63
+		});
64
+	}
65 65
 
66
-    /**
67
-     * @param mixed $shortcode
68
-     * @return bool
69
-     */
70
-    protected function hasVisibleFields($shortcode, array $attributes)
71
-    {
72
-        $args = $shortcode->normalizeAtts($attributes);
73
-        $defaults = $shortcode->getHideOptions();
74
-        $hide = array_flip($args['hide']);
75
-        unset($defaults['if_empty'], $hide['if_empty']);
76
-        return !empty(array_diff_key($defaults, $hide));
77
-    }
66
+	/**
67
+	 * @param mixed $shortcode
68
+	 * @return bool
69
+	 */
70
+	protected function hasVisibleFields($shortcode, array $attributes)
71
+	{
72
+		$args = $shortcode->normalizeAtts($attributes);
73
+		$defaults = $shortcode->getHideOptions();
74
+		$hide = array_flip($args['hide']);
75
+		unset($defaults['if_empty'], $hide['if_empty']);
76
+		return !empty(array_diff_key($defaults, $hide));
77
+	}
78 78
 }
Please login to merge, or discard this patch.
plugin/Helpers/Str.php 1 patch
Indentation   +228 added lines, -228 removed lines patch added patch discarded remove patch
@@ -4,232 +4,232 @@
 block discarded – undo
4 4
 
5 5
 class Str
6 6
 {
7
-    /**
8
-     * @param string $subject
9
-     * @param string $search
10
-     * @return string
11
-     */
12
-    public static function afterLast($subject, $search)
13
-    {
14
-        return '' === $search
15
-            ? $subject
16
-            : array_reverse(explode($search, $subject))[0];
17
-    }
18
-
19
-    /**
20
-     * @param string $subject
21
-     * @param string $search
22
-     * @return string
23
-     */
24
-    public static function before($subject, $search)
25
-    {
26
-        return $search === '' ? $subject : explode($search, $subject)[0];
27
-    }
28
-
29
-    /**
30
-     * @param string $string
31
-     * @return string
32
-     */
33
-    public static function camelCase($string)
34
-    {
35
-        $string = ucwords(str_replace(['-', '_'], ' ', trim($string)));
36
-        return str_replace(' ', '', $string);
37
-    }
38
-
39
-    /**
40
-     * @param string $haystack
41
-     * @param string $needle
42
-     * @return bool
43
-     */
44
-    public static function contains($haystack, $needle)
45
-    {
46
-        return false !== strpos($haystack, $needle);
47
-    }
48
-
49
-    /**
50
-     * @param string $name
51
-     * @param string $nameType first|first_initial|initials|last|last_initial
52
-     * @param string $initialType period|period_space|space
53
-     * @return string
54
-     */
55
-    public static function convertName($name, $nameType = '', $initialType = '')
56
-    {
57
-        $names = preg_split('/\W/', $name, 0, PREG_SPLIT_NO_EMPTY);
58
-        $firstName = array_shift($names);
59
-        $lastName = array_pop($names);
60
-        $initialTypes = [
61
-            'period' => '.',
62
-            'period_space' => '. ',
63
-            'space' => ' ',
64
-        ];
65
-        $initialPunctuation = (string) Arr::get($initialTypes, $initialType, ' ');
66
-        if ('initials' == $nameType) {
67
-            return static::convertToInitials($name, $initialPunctuation);
68
-        }
69
-        $nameTypes = [
70
-            'first' => $firstName,
71
-            'first_initial' => substr($firstName, 0, 1).$initialPunctuation.$lastName,
72
-            'last' => $lastName,
73
-            'last_initial' => $firstName.' '.substr($lastName, 0, 1).$initialPunctuation,
74
-        ];
75
-        return trim((string) Arr::get($nameTypes, $nameType, $name));
76
-    }
77
-
78
-    /**
79
-     * @param string $path
80
-     * @param string $prefix
81
-     * @return string
82
-     */
83
-    public static function convertPathToId($path, $prefix = '')
84
-    {
85
-        return str_replace(['[', ']'], ['-', ''], static::convertPathToName($path, $prefix));
86
-    }
87
-
88
-    /**
89
-     * @param string $path
90
-     * @param string $prefix
91
-     * @return string
92
-     */
93
-    public static function convertPathToName($path, $prefix = '')
94
-    {
95
-        $levels = explode('.', $path);
96
-        return array_reduce($levels, function ($result, $value) {
97
-            return $result .= '['.$value.']';
98
-        }, $prefix);
99
-    }
100
-
101
-    /**
102
-     * @param string $name
103
-     * @param string $initialPunctuation
104
-     * @return string
105
-     */
106
-    public static function convertToInitials($name, $initialPunctuation = '')
107
-    {
108
-        preg_match_all('/(?<=\s|\b)\pL/u', $name, $matches);
109
-        return array_reduce($matches[0], function ($carry, $word) use ($initialPunctuation) {
110
-            return $carry.strtoupper(substr($word, 0, 1)).$initialPunctuation;
111
-        });
112
-    }
113
-
114
-    /**
115
-     * @param string $string
116
-     * @return string
117
-     */
118
-    public static function dashCase($string)
119
-    {
120
-        return str_replace('_', '-', static::snakeCase($string));
121
-    }
122
-
123
-    /**
124
-     * @param string $needle
125
-     * @param string $haystack
126
-     * @return bool
127
-     */
128
-    public static function endsWith($needle, $haystack)
129
-    {
130
-        $length = strlen($needle);
131
-        return 0 != $length
132
-            ? substr($haystack, -$length) === $needle
133
-            : true;
134
-    }
135
-
136
-    /**
137
-     * @param string $prefix
138
-     * @param string $string
139
-     * @param string|null $trim
140
-     * @return string
141
-     */
142
-    public static function prefix($prefix, $string, $trim = null)
143
-    {
144
-        if (empty($string)) {
145
-            return $string;
146
-        }
147
-        if (null === $trim) {
148
-            $trim = $prefix;
149
-        }
150
-        return $prefix.trim(static::removePrefix($trim, $string));
151
-    }
152
-
153
-    /**
154
-     * @param string $prefix
155
-     * @param string $string
156
-     * @return string
157
-     */
158
-    public static function removePrefix($prefix, $string)
159
-    {
160
-        return static::startsWith($prefix, $string)
161
-            ? substr($string, strlen($prefix))
162
-            : $string;
163
-    }
164
-
165
-    /**
166
-     * @param string $search
167
-     * @param string $replace
168
-     * @param string $subject
169
-     * @return string
170
-     */
171
-    public static function replaceFirst($search, $replace, $subject)
172
-    {
173
-        if ($search == '') {
174
-            return $subject;
175
-        }
176
-        $position = strpos($subject, $search);
177
-        if ($position !== false) {
178
-            return substr_replace($subject, $replace, $position, strlen($search));
179
-        }
180
-        return $subject;
181
-    }
182
-
183
-    /**
184
-     * @param string $search
185
-     * @param string $replace
186
-     * @param string $subject
187
-     * @return string
188
-     */
189
-    public static function replaceLast($search, $replace, $subject)
190
-    {
191
-        $position = strrpos($subject, $search);
192
-        if ($position !== false) {
193
-            return substr_replace($subject, $replace, $position, strlen($search));
194
-        }
195
-        return $subject;
196
-    }
197
-
198
-    /**
199
-     * @param string $string
200
-     * @return string
201
-     */
202
-    public static function snakeCase($string)
203
-    {
204
-        if (!ctype_lower($string)) {
205
-            $string = preg_replace('/\s+/u', '', $string);
206
-            $string = preg_replace('/(.)(?=[A-Z])/u', '$1_', $string);
207
-            $string = function_exists('mb_strtolower')
208
-                ? mb_strtolower($string, 'UTF-8')
209
-                : strtolower($string);
210
-        }
211
-        return str_replace('-', '_', $string);
212
-    }
213
-
214
-    /**
215
-     * @param string $needle
216
-     * @param string $haystack
217
-     * @return bool
218
-     */
219
-    public static function startsWith($needle, $haystack)
220
-    {
221
-        return substr($haystack, 0, strlen($needle)) === $needle;
222
-    }
223
-
224
-    /**
225
-     * @param string $string
226
-     * @param int $length
227
-     * @return string
228
-     */
229
-    public static function truncate($string, $length)
230
-    {
231
-        return strlen($string) > $length
232
-            ? substr($string, 0, $length)
233
-            : $string;
234
-    }
7
+	/**
8
+	 * @param string $subject
9
+	 * @param string $search
10
+	 * @return string
11
+	 */
12
+	public static function afterLast($subject, $search)
13
+	{
14
+		return '' === $search
15
+			? $subject
16
+			: array_reverse(explode($search, $subject))[0];
17
+	}
18
+
19
+	/**
20
+	 * @param string $subject
21
+	 * @param string $search
22
+	 * @return string
23
+	 */
24
+	public static function before($subject, $search)
25
+	{
26
+		return $search === '' ? $subject : explode($search, $subject)[0];
27
+	}
28
+
29
+	/**
30
+	 * @param string $string
31
+	 * @return string
32
+	 */
33
+	public static function camelCase($string)
34
+	{
35
+		$string = ucwords(str_replace(['-', '_'], ' ', trim($string)));
36
+		return str_replace(' ', '', $string);
37
+	}
38
+
39
+	/**
40
+	 * @param string $haystack
41
+	 * @param string $needle
42
+	 * @return bool
43
+	 */
44
+	public static function contains($haystack, $needle)
45
+	{
46
+		return false !== strpos($haystack, $needle);
47
+	}
48
+
49
+	/**
50
+	 * @param string $name
51
+	 * @param string $nameType first|first_initial|initials|last|last_initial
52
+	 * @param string $initialType period|period_space|space
53
+	 * @return string
54
+	 */
55
+	public static function convertName($name, $nameType = '', $initialType = '')
56
+	{
57
+		$names = preg_split('/\W/', $name, 0, PREG_SPLIT_NO_EMPTY);
58
+		$firstName = array_shift($names);
59
+		$lastName = array_pop($names);
60
+		$initialTypes = [
61
+			'period' => '.',
62
+			'period_space' => '. ',
63
+			'space' => ' ',
64
+		];
65
+		$initialPunctuation = (string) Arr::get($initialTypes, $initialType, ' ');
66
+		if ('initials' == $nameType) {
67
+			return static::convertToInitials($name, $initialPunctuation);
68
+		}
69
+		$nameTypes = [
70
+			'first' => $firstName,
71
+			'first_initial' => substr($firstName, 0, 1).$initialPunctuation.$lastName,
72
+			'last' => $lastName,
73
+			'last_initial' => $firstName.' '.substr($lastName, 0, 1).$initialPunctuation,
74
+		];
75
+		return trim((string) Arr::get($nameTypes, $nameType, $name));
76
+	}
77
+
78
+	/**
79
+	 * @param string $path
80
+	 * @param string $prefix
81
+	 * @return string
82
+	 */
83
+	public static function convertPathToId($path, $prefix = '')
84
+	{
85
+		return str_replace(['[', ']'], ['-', ''], static::convertPathToName($path, $prefix));
86
+	}
87
+
88
+	/**
89
+	 * @param string $path
90
+	 * @param string $prefix
91
+	 * @return string
92
+	 */
93
+	public static function convertPathToName($path, $prefix = '')
94
+	{
95
+		$levels = explode('.', $path);
96
+		return array_reduce($levels, function ($result, $value) {
97
+			return $result .= '['.$value.']';
98
+		}, $prefix);
99
+	}
100
+
101
+	/**
102
+	 * @param string $name
103
+	 * @param string $initialPunctuation
104
+	 * @return string
105
+	 */
106
+	public static function convertToInitials($name, $initialPunctuation = '')
107
+	{
108
+		preg_match_all('/(?<=\s|\b)\pL/u', $name, $matches);
109
+		return array_reduce($matches[0], function ($carry, $word) use ($initialPunctuation) {
110
+			return $carry.strtoupper(substr($word, 0, 1)).$initialPunctuation;
111
+		});
112
+	}
113
+
114
+	/**
115
+	 * @param string $string
116
+	 * @return string
117
+	 */
118
+	public static function dashCase($string)
119
+	{
120
+		return str_replace('_', '-', static::snakeCase($string));
121
+	}
122
+
123
+	/**
124
+	 * @param string $needle
125
+	 * @param string $haystack
126
+	 * @return bool
127
+	 */
128
+	public static function endsWith($needle, $haystack)
129
+	{
130
+		$length = strlen($needle);
131
+		return 0 != $length
132
+			? substr($haystack, -$length) === $needle
133
+			: true;
134
+	}
135
+
136
+	/**
137
+	 * @param string $prefix
138
+	 * @param string $string
139
+	 * @param string|null $trim
140
+	 * @return string
141
+	 */
142
+	public static function prefix($prefix, $string, $trim = null)
143
+	{
144
+		if (empty($string)) {
145
+			return $string;
146
+		}
147
+		if (null === $trim) {
148
+			$trim = $prefix;
149
+		}
150
+		return $prefix.trim(static::removePrefix($trim, $string));
151
+	}
152
+
153
+	/**
154
+	 * @param string $prefix
155
+	 * @param string $string
156
+	 * @return string
157
+	 */
158
+	public static function removePrefix($prefix, $string)
159
+	{
160
+		return static::startsWith($prefix, $string)
161
+			? substr($string, strlen($prefix))
162
+			: $string;
163
+	}
164
+
165
+	/**
166
+	 * @param string $search
167
+	 * @param string $replace
168
+	 * @param string $subject
169
+	 * @return string
170
+	 */
171
+	public static function replaceFirst($search, $replace, $subject)
172
+	{
173
+		if ($search == '') {
174
+			return $subject;
175
+		}
176
+		$position = strpos($subject, $search);
177
+		if ($position !== false) {
178
+			return substr_replace($subject, $replace, $position, strlen($search));
179
+		}
180
+		return $subject;
181
+	}
182
+
183
+	/**
184
+	 * @param string $search
185
+	 * @param string $replace
186
+	 * @param string $subject
187
+	 * @return string
188
+	 */
189
+	public static function replaceLast($search, $replace, $subject)
190
+	{
191
+		$position = strrpos($subject, $search);
192
+		if ($position !== false) {
193
+			return substr_replace($subject, $replace, $position, strlen($search));
194
+		}
195
+		return $subject;
196
+	}
197
+
198
+	/**
199
+	 * @param string $string
200
+	 * @return string
201
+	 */
202
+	public static function snakeCase($string)
203
+	{
204
+		if (!ctype_lower($string)) {
205
+			$string = preg_replace('/\s+/u', '', $string);
206
+			$string = preg_replace('/(.)(?=[A-Z])/u', '$1_', $string);
207
+			$string = function_exists('mb_strtolower')
208
+				? mb_strtolower($string, 'UTF-8')
209
+				: strtolower($string);
210
+		}
211
+		return str_replace('-', '_', $string);
212
+	}
213
+
214
+	/**
215
+	 * @param string $needle
216
+	 * @param string $haystack
217
+	 * @return bool
218
+	 */
219
+	public static function startsWith($needle, $haystack)
220
+	{
221
+		return substr($haystack, 0, strlen($needle)) === $needle;
222
+	}
223
+
224
+	/**
225
+	 * @param string $string
226
+	 * @param int $length
227
+	 * @return string
228
+	 */
229
+	public static function truncate($string, $length)
230
+	{
231
+		return strlen($string) > $length
232
+			? substr($string, 0, $length)
233
+			: $string;
234
+	}
235 235
 }
Please login to merge, or discard this patch.
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.