Test Failed
Push — master ( e52611...5d5118 )
by Paul
04:30
created

SiteReviewsButton::fields()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 114
Code Lines 91

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 91
nc 1
nop 0
dl 0
loc 114
ccs 0
cts 84
cp 0
crap 2
rs 8.1963
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace GeminiLabs\SiteReviews\Shortcodes;
4
5
use GeminiLabs\SiteReviews\Database;
6
use GeminiLabs\SiteReviews\Shortcodes\ButtonGenerator;
7
8
class SiteReviewsButton extends ButtonGenerator
9
{
10
	/**
11
	 * @return array
12
	 */
13
	public function fields()
14
	{
15
		return [[
16
			'html' => sprintf( '<p class="strong">%s</p>', esc_html__( 'All settings are optional.', 'site-reviews' )),
17
			'minWidth' => 320,
18
			'type' => 'container',
19
		],[
20
			'label' => esc_html__( 'Title', 'site-reviews' ),
21
			'name' => 'title',
22
			'tooltip' => esc_attr__( 'Enter a custom shortcode heading.', 'site-reviews' ),
23
			'type' => 'textbox',
24
		],[
25
			'label' => esc_html__( 'Count', 'site-reviews' ),
26
			'maxLength' => 5,
27
			'name' => 'count',
28
			'size' => 3,
29
			'text' => '10',
30
			'tooltip' => esc_attr__( 'How many reviews would you like to display (default: 10)?', 'site-reviews' ),
31
			'type' => 'textbox',
32
		],[
33
			'label' => esc_html__( 'Rating', 'site-reviews' ),
34
			'name' => 'rating',
35
			'options' => [
36
				'5' => esc_html( sprintf( _n( '%s star', '%s stars', 5, 'site-reviews' ), 5 )),
37
				'4' => esc_html( sprintf( _n( '%s star', '%s stars', 4, 'site-reviews' ), 4 )),
38
				'3' => esc_html( sprintf( _n( '%s star', '%s stars', 3, 'site-reviews' ), 3 )),
39
				'2' => esc_html( sprintf( _n( '%s star', '%s stars', 2, 'site-reviews' ), 2 )),
40
				'1' => esc_html( sprintf( _n( '%s star', '%s stars', 1, 'site-reviews' ), 1 )),
41
			],
42
			'tooltip' => esc_attr__( 'What is the minimum rating to display (default: 1 star)?', 'site-reviews' ),
43
			'type' => 'listbox',
44
		],[
45
			'label' => esc_html__( 'Pagination', 'site-reviews' ),
46
			'name' => 'pagination',
47
			'options' => [
48
				'true' => esc_html__( 'Enable', 'site-reviews' ),
49
				'ajax' => esc_html__( 'Enable (using ajax)', 'site-reviews' ),
50
				'false' => esc_html__( 'Disable', 'site-reviews' ),
51
			],
52
			'tooltip' => esc_attr__( 'When using pagination this shortcode can only be used once on a page. (default: disable)', 'site-reviews' ),
53
			'type' => 'listbox',
54
		],
55
		$this->getTypes(),
56
		$this->getTerms(),
57
		[
58
			'label' => esc_html__( 'Post ID', 'site-reviews' ),
59
			'name' => 'assigned_to',
60
			'tooltip' => esc_attr__( 'Limit reviews to those assigned to this post ID (separate multiple IDs with a comma). You can also enter "post_id" to use the ID of the current page.', 'site-reviews' ),
61
			'type' => 'textbox',
62
		],[
63
			'label' => esc_html__( 'Schema', 'site-reviews' ),
64
			'name' => 'schema',
65
			'options' => [
66
				'true' => esc_html__( 'Enable rich snippets', 'site-reviews' ),
67
				'false' => esc_html__( 'Disable rich snippets', 'site-reviews' ),
68
			],
69
			'tooltip' => esc_attr__( 'Rich snippets are disabled by default.', 'site-reviews' ),
70
			'type' => 'listbox',
71
		],[
72
			'label' => esc_html__( 'Classes', 'site-reviews' ),
73
			'name' => 'class',
74
			'tooltip' => esc_attr__( 'Add custom CSS classes to the shortcode.', 'site-reviews' ),
75
			'type' => 'textbox',
76
		],[
77
			'columns' => 2,
78
			'items' => [[
79
				'name' => 'hide_assigned_to',
80
				'text' => esc_html__( 'Assigned To', 'site-reviews' ),
81
				'tooltip' => esc_attr__( 'Hide the assigned to link?', 'site-reviews' ),
82
				'type' => 'checkbox',
83
			],[
84
				'name' => 'hide_author',
85
				'text' => esc_html__( 'Author', 'site-reviews' ),
86
				'tooltip' => esc_attr__( 'Hide the review author?', 'site-reviews' ),
87
				'type' => 'checkbox',
88
			],[
89
				'name' => 'hide_avatar',
90
				'text' => esc_html__( 'Avatar', 'site-reviews' ),
91
				'tooltip' => esc_attr__( 'Hide the reviewer avatar if shown?', 'site-reviews' ),
92
				'type' => 'checkbox',
93
			],[
94
				'name' => 'hide_content',
95
				'text' => esc_html__( 'Content', 'site-reviews' ),
96
				'tooltip' => esc_attr__( 'Hide the review content?', 'site-reviews' ),
97
				'type' => 'checkbox',
98
			],[
99
				'name' => 'hide_date',
100
				'text' => esc_html__( 'Date', 'site-reviews' ),
101
				'tooltip' => esc_attr__( 'Hide the review date?', 'site-reviews' ),
102
				'type' => 'checkbox',
103
			],[
104
				'name' => 'hide_rating',
105
				'text' => esc_html__( 'Rating', 'site-reviews' ),
106
				'tooltip' => esc_attr__( 'Hide the review rating?', 'site-reviews' ),
107
				'type' => 'checkbox',
108
			],[
109
				'name' => 'hide_response',
110
				'text' => esc_html__( 'Response', 'site-reviews' ),
111
				'tooltip' => esc_attr__( 'Hide the review response?', 'site-reviews' ),
112
				'type' => 'checkbox',
113
			],[
114
				'name' => 'hide_title',
115
				'text' => esc_html__( 'Title', 'site-reviews' ),
116
				'tooltip' => esc_attr__( 'Hide the review title?', 'site-reviews' ),
117
				'type' => 'checkbox',
118
			]],
119
			'layout' => 'grid',
120
			'label' => esc_html__( 'Hide', 'site-reviews' ),
121
			'spacing' => 5,
122
			'type' => 'container',
123
		],[
124
			'hidden' => true,
125
			'name' => 'id',
126
			'type' => 'textbox',
127
		]];
128
	}
129
130
	/**
131
	 * @return array
132
	 */
133
	public function getTerms()
134
	{
135
		$terms = glsr( Database::class )->getTerms();
136
		if( empty( $terms )) {
137
			return [];
138
		}
139
		return [
140
			'label' => esc_html__( 'Category', 'site-reviews' ),
141
			'name' => 'category',
142
			'options' => $terms,
143
			'tooltip' => esc_attr__( 'Limit reviews to this category.', 'site-reviews' ),
144
			'type' => 'listbox',
145
		];
146
	}
147
148
	/**
149
	 * @return array
150
	 */
151
	public function getTypes()
152
	{
153
		if( count( glsr()->reviewTypes ) < 2 ) {
154
			return [];
155
		}
156
		return [
157
			'label' => esc_html__( 'Display', 'site-reviews' ),
158
			'name' => 'display',
159
			'options' => glsr()->reviewTypes,
160
			'tooltip' => esc_attr__( 'Which reviews would you like to display?', 'site-reviews' ),
161
			'type' => 'listbox',
162
		];
163
	}
164
}
165