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

FusionSiteReviewsSummary::elementParameters()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 110
Code Lines 89

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 89
dl 0
loc 110
rs 8.24
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\SiteReviewsSummaryShortcode;
8
9
class FusionSiteReviewsSummary 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
            'rating' => [
81
                'default' => 0,
82
                'heading' => esc_html_x('Minimum Rating', 'admin-text', 'site-reviews'),
83
                'max' => Cast::toInt(glsr()->constant('MAX_RATING', Rating::class)),
84
                'min' => Cast::toInt(glsr()->constant('MIN_RATING', Rating::class)),
85
                'param_name' => 'rating',
86
                'type' => 'range',
87
                'value' => 0,
88
            ],
89
            'schema' => [
90
                'default' => 0,
91
                'description' => _x('The schema should only be enabled once per page.', 'admin-text', 'site-reviews'),
92
                'heading' => esc_html_x('Enable the schema?', 'admin-text', 'site-reviews'),
93
                'param_name' => 'schema',
94
                'type' => 'radio_button_set',
95
                'value' => [
96
                    0 => esc_html_x('No', 'admin-text', 'site-reviews'),
97
                    1 => esc_html_x('Yes', 'admin-text', 'site-reviews'),
98
                ],
99
            ],
100
            'hide' => [
101
                'default' => '',
102
                'heading' => esc_html_x('Hide Fields', 'admin-text', 'site-reviews'),
103
                'param_name' => 'hide',
104
                'placeholder_text' => esc_attr_x('Select Fields to Hide', 'admin-text', 'site-reviews'),
105
                'type' => 'multiple_select',
106
                'value' => glsr(SiteReviewsSummaryShortcode::class)->getHideOptions(),
107
            ],
108
            'class' => [
109
                'heading' => esc_attr_x('CSS Class', 'admin-text', 'site-reviews'),
110
                'description' => esc_attr_x('Add a class to the wrapping HTML element.', 'admin-text', 'site-reviews'),
111
                'param_name' => 'class',
112
                'type' => 'textfield',
113
                'value' => '',
114
            ],
115
            'id' => [
116
                'heading' => esc_attr_x('CSS ID', 'admin-text', 'site-reviews'),
117
                'description' => esc_attr_x('Add an ID to the wrapping HTML element.', 'admin-text', 'site-reviews'),
118
                'param_name' => 'id',
119
                'type' => 'textfield',
120
                'value' => '',
121
            ],
122
        ];
123
    }
124
125
    public static function registerElement(): void
126
    {
127
        if (!function_exists('fusion_builder_map')) {
128
            return;
129
        }
130
        if (!function_exists('fusion_builder_frontend_data')) {
131
            return;
132
        }
133
        $parameters = static::elementParameters();
134
        $parameters = glsr()->filterArray('fusion-builder/controls/site_reviews_summary', $parameters);
135
        fusion_builder_map(fusion_builder_frontend_data(static::class, [
136
            'name' => esc_attr_x('Rating Summary', 'admin-text', 'site-reviews'),
137
            'shortcode' => 'site_reviews_summary',
138
            'icon' => 'fusion-glsr-summary',
139
            'params' => $parameters,
140
        ]));
141
    }
142
}
143