Test Failed
Push — develop ( 872656...e23a48 )
by Paul
07:41
created

FusionSiteReviews::elementParameters()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 131
Code Lines 107

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 107
dl 0
loc 131
rs 8
c 0
b 0
f 0
cc 1
nc 1
nop 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\Integrations\FusionBuilder;
4
5
use GeminiLabs\SiteReviews\Helpers\Cast;
6
use GeminiLabs\SiteReviews\Modules\Rating;
7
use GeminiLabs\SiteReviews\Shortcodes\SiteReviewsShortcode;
8
9
class FusionSiteReviews extends FusionElement
10
{
11
    public static function elementParameters(): array
12
    {
13
        return [
14
            'assigned_posts' => [
15
                'default' => '',
16
                'heading' => esc_attr_x('Limit Reviews to an Assigned Page', 'admin-text', 'site-reviews'),
17
                'param_name' => 'assigned_posts',
18
                'type' => 'multiple_select',
19
                'placeholder_text' => esc_attr_x('Select or Leave Blank', 'admin-text', 'site-reviews'),
20
                'value' => [
21
                    'custom' => esc_attr_x('Specific Post ID', 'admin-text', 'site-reviews'),
22
                    'post_id' => esc_attr_x('The Current Page', 'admin-text', 'site-reviews'),
23
                    'parent_id' => esc_attr_x('The Parent Page', 'admin-text', 'site-reviews'),
24
                ],
25
            ],
26
            'assigned_posts_custom' => [
27
                'heading' => esc_attr_x('Assigned Post IDs', 'admin-text', 'site-reviews'),
28
                'description' => esc_attr_x('Separate values with a comma.', 'admin-text', 'site-reviews'),
29
                'param_name' => 'assigned_posts_custom',
30
                'type' => 'textfield',
31
                'value' => '',
32
                'dependency' => [
33
                    [
34
                        'element' => 'assigned_posts',
35
                        'value' => 'custom',
36
                        'operator' => 'contains',
37
                    ],
38
                ],
39
            ],
40
            'assigned_terms' => static::optionAssignedTerms(esc_attr_x('Limit Reviews to an Assigned Category', 'admin-text', 'site-reviews')),
41
            'assigned_users' => [
42
                'default' => '',
43
                'heading' => esc_attr_x('Limit Reviews to an Assigned User', 'admin-text', 'site-reviews'),
44
                'param_name' => 'assigned_users',
45
                'placeholder_text' => esc_attr_x('Select or Leave Blank', 'admin-text', 'site-reviews'),
46
                'type' => 'multiple_select',
47
                'value' => [
48
                    'custom' => esc_attr_x('Specific User ID', 'admin-text', 'site-reviews'),
49
                    'user_id' => esc_attr_x('The Logged-in user', 'admin-text', 'site-reviews'),
50
                    'author_id' => esc_attr_x('The Page author', 'admin-text', 'site-reviews'),
51
                    'profile_id' => esc_attr_x('The Profile user (BuddyPress/Ultimate Member)', 'admin-text', 'site-reviews'),
52
                ],
53
            ],
54
            'assigned_users_custom' => [
55
                'heading' => esc_attr_x('Assigned User IDs', 'admin-text', 'site-reviews'),
56
                'description' => esc_attr_x('Separate values with a comma.', 'admin-text', 'site-reviews'),
57
                'param_name' => 'assigned_users_custom',
58
                'type' => 'textfield',
59
                'value' => '',
60
                'dependency' => [
61
                    [
62
                        'element' => 'assigned_users',
63
                        'value' => 'custom',
64
                        'operator' => 'contains',
65
                    ],
66
                ],
67
            ],
68
            'terms' => [
69
                'default' => '',
70
                'heading' => esc_attr_x('Limit Reviews to Terms?', 'admin-text', 'site-reviews'),
71
                'param_name' => 'terms',
72
                'type' => 'select',
73
                'value' => [
74
                    '' => esc_attr_x('No', 'admin-text', 'site-reviews'),
75
                    'true' => esc_attr_x('Terms were accepted', 'admin-text', 'site-reviews'),
76
                    'false' => esc_attr_x('Terms were not accepted', 'admin-text', 'site-reviews'),
77
                ],
78
            ],
79
            'type' => static::optionReviewTypes(),
80
            'pagination' => [
81
                'default' => '',
82
                'heading' => esc_attr_x('Pagination Type ', 'admin-text', 'site-reviews'),
83
                'param_name' => 'pagination',
84
                'type' => 'select',
85
                'value' => [
86
                    '' => esc_attr_x('No Pagination', 'admin-text', 'site-reviews'),
87
                    'loadmore' => esc_attr_x('Load More Button', 'admin-text', 'site-reviews'),
88
                    'ajax' => esc_attr_x('Pagination (AJAX)', 'admin-text', 'site-reviews'),
89
                    'true' => esc_attr_x('Pagination (with page reload)', 'admin-text', 'site-reviews'),
90
                ],
91
            ],
92
            'display' => [
93
                'default' => 10,
94
                'heading' => esc_html_x('Reviews Per Page', 'admin-text', 'site-reviews'),
95
                'max' => 50,
96
                'min' => 1,
97
                'param_name' => 'display',
98
                'type' => 'range',
99
                'value' => 10,
100
            ],
101
            'rating' => [
102
                'default' => 0,
103
                'heading' => esc_html_x('Minimum Rating', 'admin-text', 'site-reviews'),
104
                'max' => Cast::toInt(glsr()->constant('MAX_RATING', Rating::class)),
105
                'min' => Cast::toInt(glsr()->constant('MIN_RATING', Rating::class)),
106
                'param_name' => 'rating',
107
                'type' => 'range',
108
                'value' => 0,
109
            ],
110
            'schema' => [
111
                'default' => 0,
112
                'description' => _x('The schema should only be enabled once per page.', 'admin-text', 'site-reviews'),
113
                'heading' => esc_html_x('Enable the schema?', 'admin-text', 'site-reviews'),
114
                'param_name' => 'schema',
115
                'type' => 'radio_button_set',
116
                'value' => [
117
                    0 => esc_html_x('No', 'admin-text', 'site-reviews'),
118
                    1 => esc_html_x('Yes', 'admin-text', 'site-reviews'),
119
                ],
120
            ],
121
            'hide' => [
122
                'default' => '',
123
                'heading' => esc_html_x('Hide Fields', 'admin-text', 'site-reviews'),
124
                'param_name' => 'hide',
125
                'placeholder_text' => esc_attr_x('Select Fields to Hide', 'admin-text', 'site-reviews'),
126
                'type' => 'multiple_select',
127
                'value' => glsr(SiteReviewsShortcode::class)->getHideOptions(),
128
            ],
129
            'class' => [
130
                'heading' => esc_attr_x('CSS Class', 'admin-text', 'site-reviews'),
131
                'description' => esc_attr_x('Add a class to the wrapping HTML element.', 'admin-text', 'site-reviews'),
132
                'param_name' => 'class',
133
                'type' => 'textfield',
134
                'value' => '',
135
            ],
136
            'id' => [
137
                'heading' => esc_attr_x('CSS ID', 'admin-text', 'site-reviews'),
138
                'description' => esc_attr_x('Add an ID to the wrapping HTML element.', 'admin-text', 'site-reviews'),
139
                'param_name' => 'id',
140
                'type' => 'textfield',
141
                'value' => '',
142
            ],
143
        ];
144
    }
145
146
    public static function registerElement(): void
147
    {
148
        if (!function_exists('fusion_builder_map')) {
149
            return;
150
        }
151
        if (!function_exists('fusion_builder_frontend_data')) {
152
            return;
153
        }
154
        $parameters = static::elementParameters();
155
        $parameters = glsr()->filterArray('fusion-builder/controls/site_reviews', $parameters);
156
        fusion_builder_map(fusion_builder_frontend_data(static::class, [
157
            'name' => esc_attr_x('Latest Reviews', 'admin-text', 'site-reviews'),
158
            'shortcode' => 'site_reviews',
159
            'icon' => 'fusion-glsr-reviews',
160
            'params' => $parameters,
161
        ]));
162
    }
163
}
164