Passed
Push — develop ( 355f63...51016a )
by Mathieu
02:23
created

Admin::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 34
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 34
rs 9.7
c 0
b 0
f 0
cc 2
nc 2
nop 14

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Neimheadh\SonataAnnotationBundle\Annotation\Sonata;
6
7
use Attribute;
8
use Neimheadh\SonataAnnotationBundle\Admin\AnnotationAdmin;
9
use Neimheadh\SonataAnnotationBundle\Annotation\AbstractAnnotation;
10
use ReflectionException;
11
12
/**
13
 * Admin annotation.
14
 *
15
 * Auto-build the admin service of your model class.
16
 *
17
 * @Annotation
18
 * @Target("CLASS")
19
 *
20
 * @author Marko Kunic <[email protected]>
21
 * @author Mathieu Wambre <[email protected]>
22
 */
23
#[Attribute(Attribute::TARGET_CLASS)]
24
final class Admin extends AbstractAnnotation
25
{
26
27
    /**
28
     * Admin label.
29
     *
30
     * @var string|null
31
     */
32
    public ?string $label = null;
33
34
    /**
35
     * Admin model manager type.
36
     *
37
     * @var string
38
     */
39
    public string $managerType = 'orm';
40
41
    /**
42
     * Admin group.
43
     *
44
     * @var string|null
45
     */
46
    public ?string $group = null;
47
48
    /**
49
     * Is admin shown in dashboard?
50
     *
51
     * @var bool
52
     */
53
    public bool $showInDashboard = true;
54
55
    /**
56
     * Is admin is kept open.
57
     *
58
     * @var bool
59
     */
60
    public bool $keepOpen = false;
61
62
    /**
63
     * Is admin a top menu?
64
     *
65
     * This option put your admin link directly in the menu and not as a
66
     * sub-menu.
67
     *
68
     * @var bool
69
     */
70
    public bool $onTop = false;
71
72
    /**
73
     * Admin link icon.
74
     *
75
     * @var string|null
76
     */
77
    public ?string $icon = null;
78
79
    /**
80
     * Admin label translator strategy.
81
     *
82
     * @var string|null
83
     */
84
    public ?string $labelTranslatorStrategy = null;
85
86
    /**
87
     * Admin label translation catalogue.
88
     *
89
     * @var string|null
90
     */
91
    public ?string $labelCatalogue = null;
92
93
    /**
94
     * Admin pager type.
95
     *
96
     * @var string|null
97
     */
98
    public ?string $pagerType = null;
99
100
    /**
101
     * Admin controller.
102
     *
103
     * @var string|null
104
     */
105
    public ?string $controller = null;
106
107
    /**
108
     * Admin service id.
109
     *
110
     * @var string|null
111
     */
112
    public ?string $serviceId = null;
113
114
    /**
115
     * Admin service class.
116
     *
117
     * @var string
118
     */
119
    public string $admin = AnnotationAdmin::class;
120
121
    /**
122
     * Admin code.
123
     *
124
     * @var string|null
125
     */
126
    public ?string $code = null;
127
128
    /**
129
     * @param string|array|null $label                    Label or annotation
130
     *                                                    parameters.
131
     * @param string            $managerType              Model manager type.
132
     * @param string|null       $group                    Admin group.
133
     * @param bool              $showInDashboard          Show in dashboard?
134
     * @param bool              $keepOpen                 Keep open.
135
     * @param bool              $onTop                    Is admin a top menu?
136
     * @param string|null       $icon                     Admin link icon.
137
     * @param string|null       $labelTranslatorStrategy  Label translator
138
     *                                                    strategy.
139
     * @param string|null       $labelCatalogue           Admin label
140
     *                                                    translation
141
     *                                                    catalogue.
142
     * @param string|null       $pagerType                Pager type.
143
     * @param string|null       $controller               Controller.
144
     * @param string|null       $serviceId                Service id.
145
     * @param string            $admin                    Service class.
146
     * @param string|null       $code                     Code.
147
     *
148
     * @throws ReflectionException
149
     */
150
    public function __construct(
151
        $label = null,
152
        string $managerType = 'orm',
153
        ?string $group = null,
154
        bool $showInDashboard = true,
155
        bool $keepOpen = true,
156
        bool $onTop = false,
157
        ?string $icon = null,
158
        ?string $labelTranslatorStrategy = null,
159
        ?string $labelCatalogue = null,
160
        ?string $pagerType = null,
161
        ?string $controller = null,
162
        ?string $serviceId = null,
163
        string $admin = AnnotationAdmin::class,
164
        ?string $code = null
165
    ) {
166
        $this->managerType = $managerType;
167
        $this->group = $group;
168
        $this->showInDashboard = $showInDashboard;
169
        $this->keepOpen = $keepOpen;
170
        $this->onTop = $onTop;
171
        $this->icon = $icon;
172
        $this->labelTranslatorStrategy = $labelTranslatorStrategy;
173
        $this->labelCatalogue = $labelCatalogue;
174
        $this->pagerType = $pagerType;
175
        $this->controller = $controller;
176
        $this->serviceId = $serviceId;
177
        $this->admin = $admin;
178
        $this->code = $code;
179
180
        if (is_array($label)) {
181
            $this->initAnnotation($label);
182
        } else {
183
            $this->label = $label;
184
        }
185
    }
186
187
    /**
188
     * Get service "sonata.admin" tag options.
189
     *
190
     * @return array<string|bool>
191
     */
192
    public function getTagOptions(): array
193
    {
194
        return [
195
            'code' => $this->code,
196
            'controller' => $this->controller,
197
            'manager_type' => $this->managerType,
198
            'group' => $this->group,
199
            'label' => $this->label,
200
            'show_in_dashboard' => $this->showInDashboard,
201
            'keep_open' => $this->keepOpen,
202
            'on_top' => $this->onTop,
203
            'icon' => $this->icon,
204
            'label_translator_strategy' => $this->labelTranslatorStrategy,
205
            'label_catalogue' => $this->labelCatalogue,
206
            'pager_type' => $this->pagerType,
207
        ];
208
    }
209
210
}
211