Passed
Push — master ( 8a0962...507d84 )
by Paul
03:52
created

SiteReviewsButton::fields()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 114
Code Lines 91

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 84
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 91
nc 1
nop 0
dl 0
loc 114
ccs 84
cts 84
cp 1
crap 1
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 1
	public function fields()
14
	{
15
		return [[
16 1
			'html' => sprintf( '<p class="strong">%s</p>', esc_html__( 'All settings are optional.', 'site-reviews' )),
17 1
			'minWidth' => 320,
18 1
			'type' => 'container',
19
		],[
20 1
			'label' => esc_html__( 'Title', 'site-reviews' ),
21 1
			'name' => 'title',
22 1
			'tooltip' => esc_attr__( 'Enter a custom shortcode heading.', 'site-reviews' ),
23 1
			'type' => 'textbox',
24
		],[
25 1
			'label' => esc_html__( 'Count', 'site-reviews' ),
26 1
			'maxLength' => 5,
27 1
			'name' => 'count',
28 1
			'size' => 3,
29 1
			'text' => '10',
30 1
			'tooltip' => esc_attr__( 'How many reviews would you like to display (default: 10)?', 'site-reviews' ),
31 1
			'type' => 'textbox',
32
		],[
33 1
			'label' => esc_html__( 'Rating', 'site-reviews' ),
34 1
			'name' => 'rating',
35
			'options' => [
36 1
				'5' => esc_html( sprintf( _n( '%s star', '%s stars', 5, 'site-reviews' ), 5 )),
37 1
				'4' => esc_html( sprintf( _n( '%s star', '%s stars', 4, 'site-reviews' ), 4 )),
38 1
				'3' => esc_html( sprintf( _n( '%s star', '%s stars', 3, 'site-reviews' ), 3 )),
39 1
				'2' => esc_html( sprintf( _n( '%s star', '%s stars', 2, 'site-reviews' ), 2 )),
40 1
				'1' => esc_html( sprintf( _n( '%s star', '%s stars', 1, 'site-reviews' ), 1 )),
41
			],
42 1
			'tooltip' => esc_attr__( 'What is the minimum rating to display (default: 1 star)?', 'site-reviews' ),
43 1
			'type' => 'listbox',
44
		],[
45 1
			'label' => esc_html__( 'Pagination', 'site-reviews' ),
46 1
			'name' => 'pagination',
47
			'options' => [
48 1
				'true' => esc_html__( 'Enable', 'site-reviews' ),
49 1
				'ajax' => esc_html__( 'Enable (using ajax)', 'site-reviews' ),
50 1
				'false' => esc_html__( 'Disable', 'site-reviews' ),
51
			],
52 1
			'tooltip' => esc_attr__( 'When using pagination this shortcode can only be used once on a page. (default: disable)', 'site-reviews' ),
53 1
			'type' => 'listbox',
54
		],
55 1
		$this->getTypes(),
56 1
		$this->getTerms(),
57
		[
58 1
			'label' => esc_html__( 'Post ID', 'site-reviews' ),
59 1
			'name' => 'assigned_to',
60 1
			'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 1
			'type' => 'textbox',
62
		],[
63 1
			'label' => esc_html__( 'Schema', 'site-reviews' ),
64 1
			'name' => 'schema',
65
			'options' => [
66 1
				'true' => esc_html__( 'Enable rich snippets', 'site-reviews' ),
67 1
				'false' => esc_html__( 'Disable rich snippets', 'site-reviews' ),
68
			],
69 1
			'tooltip' => esc_attr__( 'Rich snippets are disabled by default.', 'site-reviews' ),
70 1
			'type' => 'listbox',
71
		],[
72 1
			'label' => esc_html__( 'Classes', 'site-reviews' ),
73 1
			'name' => 'class',
74 1
			'tooltip' => esc_attr__( 'Add custom CSS classes to the shortcode.', 'site-reviews' ),
75 1
			'type' => 'textbox',
76
		],[
77 1
			'columns' => 2,
78
			'items' => [[
79 1
				'name' => 'hide_assigned_to',
80 1
				'text' => esc_html__( 'Assigned To', 'site-reviews' ),
81 1
				'tooltip' => esc_attr__( 'Hide the assigned to link?', 'site-reviews' ),
82 1
				'type' => 'checkbox',
83
			],[
84 1
				'name' => 'hide_author',
85 1
				'text' => esc_html__( 'Author', 'site-reviews' ),
86 1
				'tooltip' => esc_attr__( 'Hide the review author?', 'site-reviews' ),
87 1
				'type' => 'checkbox',
88
			],[
89 1
				'name' => 'hide_avatar',
90 1
				'text' => esc_html__( 'Avatar', 'site-reviews' ),
91 1
				'tooltip' => esc_attr__( 'Hide the reviewer avatar if shown?', 'site-reviews' ),
92 1
				'type' => 'checkbox',
93
			],[
94 1
				'name' => 'hide_content',
95 1
				'text' => esc_html__( 'Content', 'site-reviews' ),
96 1
				'tooltip' => esc_attr__( 'Hide the review content?', 'site-reviews' ),
97 1
				'type' => 'checkbox',
98
			],[
99 1
				'name' => 'hide_date',
100 1
				'text' => esc_html__( 'Date', 'site-reviews' ),
101 1
				'tooltip' => esc_attr__( 'Hide the review date?', 'site-reviews' ),
102 1
				'type' => 'checkbox',
103
			],[
104 1
				'name' => 'hide_rating',
105 1
				'text' => esc_html__( 'Rating', 'site-reviews' ),
106 1
				'tooltip' => esc_attr__( 'Hide the review rating?', 'site-reviews' ),
107 1
				'type' => 'checkbox',
108
			],[
109 1
				'name' => 'hide_response',
110 1
				'text' => esc_html__( 'Response', 'site-reviews' ),
111 1
				'tooltip' => esc_attr__( 'Hide the review response?', 'site-reviews' ),
112 1
				'type' => 'checkbox',
113
			],[
114 1
				'name' => 'hide_title',
115 1
				'text' => esc_html__( 'Title', 'site-reviews' ),
116 1
				'tooltip' => esc_attr__( 'Hide the review title?', 'site-reviews' ),
117 1
				'type' => 'checkbox',
118
			]],
119 1
			'layout' => 'grid',
120 1
			'label' => esc_html__( 'Hide', 'site-reviews' ),
121 1
			'spacing' => 5,
122 1
			'type' => 'container',
123
		],[
124
			'hidden' => true,
125
			'name' => 'id',
126
			'type' => 'textbox',
127
		]];
128
	}
129
130
	/**
131
	 * @return array
132
	 */
133 1
	public function getTerms()
134
	{
135 1
		$terms = glsr( Database::class )->getTerms();
136 1
		if( empty( $terms )) {
137 1
			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 1
	public function getTypes()
152
	{
153 1
		if( count( glsr()->reviewTypes ) < 2 ) {
154 1
			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