Passed
Push — master ( 9b46a7...ed8579 )
by Paul
03:56
created

SiteReviewsPopup::fields()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 115
Code Lines 92

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 85
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 92
nc 1
nop 0
dl 0
loc 115
ccs 85
cts 85
cp 1
crap 1
rs 8.1745
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\TinymcePopupGenerator;
7
8
class SiteReviewsPopup extends TinymcePopupGenerator
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' => __( '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' => __( '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 1
				'0' => esc_html( __( 'Unrated', 'site-reviews' )),
42
			],
43 1
			'tooltip' => __( 'What is the minimum rating to display (default: 1 star)?', 'site-reviews' ),
44 1
			'type' => 'listbox',
45
		],[
46 1
			'label' => esc_html__( 'Pagination', 'site-reviews' ),
47 1
			'name' => 'pagination',
48
			'options' => [
49 1
				'true' => esc_html__( 'Enable', 'site-reviews' ),
50 1
				'ajax' => esc_html__( 'Enable (using ajax)', 'site-reviews' ),
51 1
				'false' => esc_html__( 'Disable', 'site-reviews' ),
52
			],
53 1
			'tooltip' => __( 'When using pagination this shortcode can only be used once on a page. (default: disable)', 'site-reviews' ),
54 1
			'type' => 'listbox',
55
		],
56 1
		$this->getTypes(),
57 1
		$this->getTerms(),
58
		[
59 1
			'label' => esc_html__( 'Assigned To', 'site-reviews' ),
60 1
			'name' => 'assigned_to',
61 1
			'tooltip' => __( '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' ),
62 1
			'type' => 'textbox',
63
		],[
64 1
			'label' => esc_html__( 'Schema', 'site-reviews' ),
65 1
			'name' => 'schema',
66
			'options' => [
67 1
				'true' => esc_html__( 'Enable rich snippets', 'site-reviews' ),
68 1
				'false' => esc_html__( 'Disable rich snippets', 'site-reviews' ),
69
			],
70 1
			'tooltip' => __( 'Rich snippets are disabled by default.', 'site-reviews' ),
71 1
			'type' => 'listbox',
72
		],[
73 1
			'label' => esc_html__( 'Classes', 'site-reviews' ),
74 1
			'name' => 'class',
75 1
			'tooltip' => __( 'Add custom CSS classes to the shortcode.', 'site-reviews' ),
76 1
			'type' => 'textbox',
77
		],[
78 1
			'columns' => 2,
79
			'items' => [[
80 1
				'name' => 'hide_assigned_to',
81 1
				'text' => esc_html__( 'Assigned To', 'site-reviews' ),
82 1
				'tooltip' => __( 'Hide the assigned to link?', 'site-reviews' ),
83 1
				'type' => 'checkbox',
84
			],[
85 1
				'name' => 'hide_author',
86 1
				'text' => esc_html__( 'Author', 'site-reviews' ),
87 1
				'tooltip' => __( 'Hide the review author?', 'site-reviews' ),
88 1
				'type' => 'checkbox',
89
			],[
90 1
				'name' => 'hide_avatar',
91 1
				'text' => esc_html__( 'Avatar', 'site-reviews' ),
92 1
				'tooltip' => __( 'Hide the reviewer avatar if shown?', 'site-reviews' ),
93 1
				'type' => 'checkbox',
94
			],[
95 1
				'name' => 'hide_content',
96 1
				'text' => esc_html__( 'Content', 'site-reviews' ),
97 1
				'tooltip' => __( 'Hide the review content?', 'site-reviews' ),
98 1
				'type' => 'checkbox',
99
			],[
100 1
				'name' => 'hide_date',
101 1
				'text' => esc_html__( 'Date', 'site-reviews' ),
102 1
				'tooltip' => __( 'Hide the review date?', 'site-reviews' ),
103 1
				'type' => 'checkbox',
104
			],[
105 1
				'name' => 'hide_rating',
106 1
				'text' => esc_html__( 'Rating', 'site-reviews' ),
107 1
				'tooltip' => __( 'Hide the review rating?', 'site-reviews' ),
108 1
				'type' => 'checkbox',
109
			],[
110 1
				'name' => 'hide_response',
111 1
				'text' => esc_html__( 'Response', 'site-reviews' ),
112 1
				'tooltip' => __( 'Hide the review response?', 'site-reviews' ),
113 1
				'type' => 'checkbox',
114
			],[
115 1
				'name' => 'hide_title',
116 1
				'text' => esc_html__( 'Title', 'site-reviews' ),
117 1
				'tooltip' => __( 'Hide the review title?', 'site-reviews' ),
118 1
				'type' => 'checkbox',
119
			]],
120 1
			'layout' => 'grid',
121 1
			'label' => esc_html__( 'Hide', 'site-reviews' ),
122 1
			'spacing' => 5,
123 1
			'type' => 'container',
124
		],[
125
			'hidden' => true,
126
			'name' => 'id',
127
			'type' => 'textbox',
128
		]];
129
	}
130
131
	/**
132
	 * @return array
133
	 */
134 1
	public function getTerms()
135
	{
136 1
		$terms = glsr( Database::class )->getTerms();
137 1
		if( empty( $terms )) {
138 1
			return [];
139
		}
140
		return [
141
			'label' => esc_html__( 'Category', 'site-reviews' ),
142
			'name' => 'category',
143
			'options' => $terms,
144
			'tooltip' => __( 'Limit reviews to this category.', 'site-reviews' ),
145
			'type' => 'listbox',
146
		];
147
	}
148
149
	/**
150
	 * @return array
151
	 */
152 1
	public function getTypes()
153
	{
154 1
		if( count( glsr()->reviewTypes ) < 2 ) {
155 1
			return [];
156
		}
157
		return [
158
			'label' => esc_html__( 'Display', 'site-reviews' ),
159
			'name' => 'display',
160
			'options' => glsr()->reviewTypes,
161
			'tooltip' => __( 'Which reviews would you like to display?', 'site-reviews' ),
162
			'type' => 'listbox',
163
		];
164
	}
165
}
166