Test Failed
Push — master ( 2def23...999d23 )
by Paul
04:14
created

SiteReviewsFormButton::fields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 61
Code Lines 48

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 48
nc 1
nop 0
dl 0
loc 61
ccs 0
cts 43
cp 0
crap 2
rs 9.1344
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 SiteReviewsFormButton extends ButtonGenerator
9
{
10
	/**
11
	 * @return array
12
	 */
13
	public function fields()
14
	{
15
		return [[
16
			'type' => 'container',
17
			'html' => '<p class="strong">'.esc_html__( 'All settings are optional.', 'site-reviews' ).'</p>',
18
		],[
19
			'label' => esc_html__( 'Title', 'site-reviews' ),
20
			'name' => 'title',
21
			'tooltip' => esc_attr__( 'Enter a custom shortcode heading.', 'site-reviews' ),
22
			'type' => 'textbox',
23
		],[
24
			'label' => esc_html__( 'Description', 'site-reviews' ),
25
			'minHeight' => 60,
26
			'minWidth' => 240,
27
			'multiline' => true,
28
			'name' => 'description',
29
			'tooltip' => esc_attr__( 'Enter a custom shortcode description.', 'site-reviews' ),
30
			'type' => 'textbox',
31
		],
32
		$this->getTerms(),
33
		[
34
			'label' => esc_html__( 'Post ID', 'site-reviews' ),
35
			'name' => 'assign_to',
36
			'tooltip' => esc_attr__( 'Assign submitted reviews to a custom page/post ID. You can also enter "post_id" to assign reviews to the ID of the current page.', 'site-reviews' ),
37
			'type' => 'textbox',
38
		],[
39
			'label' => esc_html__( 'Classes', 'site-reviews' ),
40
			'name' => 'class',
41
			'tooltip' => esc_attr__( 'Add custom CSS classes to the shortcode.', 'site-reviews' ),
42
			'type' => 'textbox',
43
		],[
44
			'columns' => 2,
45
			'items' => [[
46
				'name' => 'hide_email',
47
				'text' => esc_html__( 'Email', 'site-reviews' ),
48
				'tooltip' => esc_attr__( 'Hide the email field?', 'site-reviews' ),
49
				'type' => 'checkbox',
50
			],[
51
				'name' => 'hide_name',
52
				'text' => esc_html__( 'Name', 'site-reviews' ),
53
				'tooltip' => esc_attr__( 'Hide the name field?', 'site-reviews' ),
54
				'type' => 'checkbox',
55
			],[
56
				'name' => 'hide_terms',
57
				'text' => esc_html__( 'Terms', 'site-reviews' ),
58
				'tooltip' => esc_attr__( 'Hide the terms field?', 'site-reviews' ),
59
				'type' => 'checkbox',
60
			],[
61
				'name' => 'hide_title',
62
				'text' => esc_html__( 'Title', 'site-reviews' ),
63
				'tooltip' => esc_attr__( 'Hide the title field?', 'site-reviews' ),
64
				'type' => 'checkbox',
65
			]],
66
			'label' => esc_html__( 'Hide', 'site-reviews' ),
67
			'layout' => 'grid',
68
			'spacing' => 5,
69
			'type' => 'container',
70
		],[
71
			'hidden' => true,
72
			'name' => 'id',
73
			'type' => 'textbox',
74
		]];
75
	}
76
77
	/**
78
	 * @return array
79
	 */
80
	public function getTerms()
81
	{
82
		$terms = glsr( Database::class )->getTerms();
83
		if( empty( $terms )) {
84
			return [];
85
		}
86
		return [
87
			'label' => esc_html__( 'Category', 'site-reviews' ),
88
			'name' => 'category',
89
			'options' => $terms,
90
			'tooltip' => esc_attr__( 'Automatically assign a category to reviews submitted with this shortcode.', 'site-reviews' ),
91
			'type' => 'listbox',
92
		];
93
	}
94
}
95