Test Failed
Push — develop ( 8b2a32...47c531 )
by Paul
08:13
created

FlatsomeSiteReviewsSummary::options()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 120
Code Lines 93

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 93
c 1
b 0
f 1
dl 0
loc 120
rs 8.1527
cc 2
nc 2
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\Flatsome;
4
5
use GeminiLabs\SiteReviews\Contracts\ShortcodeContract;
6
use GeminiLabs\SiteReviews\Helpers\Cast;
7
use GeminiLabs\SiteReviews\Modules\Rating;
8
use GeminiLabs\SiteReviews\Shortcodes\SiteReviewsSummaryShortcode;
9
10
class FlatsomeSiteReviewsSummary extends FlatsomeShortcode
11
{
12
    public function options(): array
13
    {
14
        $options = [
15
            'limit_group' => [
16
                'type' => 'group',
17
                'heading' => esc_html_x('Limit Reviews By', 'admin-text', 'site-reviews'),
18
                'options' => [
19
                    'assigned_posts' => [
20
                        'type' => 'select',
21
                        'heading' => esc_html_x('Limit Reviews by Assigned Pages', 'admin-text', 'site-reviews'),
22
                        'full_width' => true,
23
                        'config' => [
24
                            'multiple' => true,
25
                            'placeholder' => esc_html_x('Select...', 'admin-text', 'site-reviews'),
26
                            'postSelect' => 'assigned_posts_query',
27
                        ],
28
                    ],
29
                    'assigned_terms' => [
30
                        'type' => 'select',
31
                        'heading' => esc_html_x('Limit Reviews by Categories', 'admin-text', 'site-reviews'),
32
                        'default' => '',
33
                        'full_width' => true,
34
                        'config' => [
35
                            'multiple' => true,
36
                            'placeholder' => esc_html_x('Select...', 'admin-text', 'site-reviews'),
37
                            'termSelect' => [
38
                                'taxonomies' => glsr()->taxonomy,
39
                            ],
40
                        ],
41
                    ],
42
                    'assigned_users' => [
43
                        'type' => 'select',
44
                        'heading' => esc_html_x('Limit Reviews by Assigned Users', 'admin-text', 'site-reviews'),
45
                        'default' => '',
46
                        'full_width' => true,
47
                        'config' => [
48
                            'multiple' => true,
49
                            'placeholder' => esc_html_x('Select...', 'admin-text', 'site-reviews'),
50
                            'postSelect' => 'assigned_users_query',
51
                        ],
52
                    ],
53
                    'terms' => [
54
                        'type' => 'select',
55
                        'heading' => esc_html_x('Limit Reviews by Accepted Terms', 'admin-text', 'site-reviews'),
56
                        'default' => '',
57
                        'full_width' => true,
58
                        'options' => [
59
                            '' => esc_html_x('Select...', 'admin-text', 'site-reviews'),
60
                            'true' => esc_html_x('Terms were accepted', 'admin-text', 'site-reviews'),
61
                            'false' => esc_html_x('Terms were not accepted', 'admin-text', 'site-reviews'),
62
                        ],
63
                    ],
64
                ],
65
            ],
66
            'display_group' => [
67
                'type' => 'group',
68
                'heading' => esc_html_x('Display Options', 'admin-text', 'site-reviews'),
69
                'options' => [
70
                    'rating' => [
71
                        'type' => 'slider',
72
                        'heading' => esc_html_x('Minimum Rating', 'admin-text', 'site-reviews'),
73
                        'default' => 0,
74
                        'max' => Cast::toInt(glsr()->constant('MAX_RATING', Rating::class)),
75
                        'min' => Cast::toInt(glsr()->constant('MIN_RATING', Rating::class)),
76
                    ],
77
                    'schema' => [
78
                        'type' => 'checkbox',
79
                        'heading' => esc_html_x('Enable the schema?', 'admin-text', 'site-reviews'),
80
                        'description' => esc_html_x('The schema should only be enabled once per page.', 'admin-text', 'site-reviews'),
81
                    ],
82
                ],
83
            ],
84
            'hide_group' => [
85
                'type' => 'group',
86
                'heading' => esc_html_x('Hide Options', 'admin-text', 'site-reviews'),
87
                'options' => $this->hideOptions(),
88
            ],
89
            'advanced_group' => [
90
                'type' => 'group',
91
                'heading' => esc_html_x('Advanced', 'admin-text', 'site-reviews'),
92
                'options' => [
93
                    'rating_field' => [
94
                        'type' => 'textfield',
95
                        'heading' => esc_html_x('Custom Rating Field Name', 'admin-text', 'site-reviews'),
96
                        'description' => esc_html_x('Use the Review Forms addon to add custom rating fields.', 'admin-text', 'site-reviews'),
97
                        'full_width' => true,
98
                    ],
99
                    'id' => [
100
                        'type' => 'textfield',
101
                        'heading' => esc_html_x('Custom ID', 'admin-text', 'site-reviews'),
102
                        'description' => esc_html_x('This should be a unique value.', 'admin-text', 'site-reviews'),
103
                        'full_width' => true,
104
                    ],
105
                    'class' => [
106
                        'type' => 'textfield',
107
                        'heading' => esc_html_x('Additional CSS classes', 'admin-text', 'site-reviews'),
108
                        'description' => esc_html_x('Separate multiple classes with spaces.', 'admin-text', 'site-reviews'),
109
                        'full_width' => true,
110
                    ],
111
                    'visibility' => [
112
                        'type' => 'select',
113
                        'heading' => esc_html_x('Visibility', 'admin-text', 'site-reviews'),
114
                        'default' => '',
115
                        'options' => [
116
                            '' => esc_html_x('Visible', 'admin-text', 'site-reviews'),
117
                            'hidden' => esc_html_x('Hidden', 'admin-text', 'site-reviews'),
118
                            'hide-for-medium' => esc_html_x('Only for Desktop', 'admin-text', 'site-reviews'),
119
                            'show-for-small' => esc_html_x('Only for Mobile', 'admin-text', 'site-reviews'),
120
                            'show-for-medium hide-for-small' => esc_html_x('Only for Tablet', 'admin-text', 'site-reviews'),
121
                            'show-for-medium' => esc_html_x('Hide for Desktop', 'admin-text', 'site-reviews'),
122
                            'hide-for-small' => esc_html_x('Hide for Mobile', 'admin-text', 'site-reviews'),
123
                        ],
124
                    ],
125
                ],
126
            ],
127
        ];
128
        if ($types = $this->typeOptions()) {
129
            $options['limit_group']['options']['type'] = $types;
130
        }
131
        return $options;
132
    }
133
134
    protected function icon(): string
135
    {
136
        return glsr()->url('assets/images/icons/flatsome/flatsome-summary.svg');
137
    }
138
139
    protected function name(): string
140
    {
141
        return esc_attr_x('Rating Summary', 'admin-text', 'site-reviews');
142
    }
143
144
    protected function shortcode(): ShortcodeContract
145
    {
146
        return glsr(SiteReviewsSummaryShortcode::class);
1 ignored issue
show
Bug Best Practice introduced by
The expression return glsr(GeminiLabs\S...ummaryShortcode::class) could return the type callable which is incompatible with the type-hinted return GeminiLabs\SiteReviews\Contracts\ShortcodeContract. Consider adding an additional type-check to rule them out.
Loading history...
147
    }
148
}
149