FieldsetsController   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 192
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 106
dl 0
loc 192
c 2
b 0
f 0
rs 10
wmc 15

9 Methods

Rating   Name   Duplication   Size   Complexity  
A addProcess() 0 41 3
A deleteProcess() 0 9 2
A duplicateProcess() 0 9 2
A add() 0 17 1
A editProcess() 0 12 2
A index() 0 19 1
A renameProcess() 0 9 2
A edit() 0 25 1
A rename() 0 17 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Flextype;
6
7
use Flextype\Component\Arr\Arr;
0 ignored issues
show
Bug introduced by
The type Flextype\Component\Arr\Arr was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use function date;
9
use function Flextype\Component\I18n\__;
0 ignored issues
show
introduced by
The function Flextype\Component\I18n\__ was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
10
11
/**
12
 * @property twig $twig
13
 * @property Fieldsets $fieldsets
14
 * @property Router $router
15
 * @property Slugify $slugify
16
 * @property Flash $flash
17
 */
18
class FieldsetsController extends Container
0 ignored issues
show
Bug introduced by
The type Flextype\Container was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
{
20
    public function index($request, $response)
21
    {
22
        return $this->twig->render(
23
            $response,
24
            'plugins/form-admin/templates/extends/fieldsets/index.html',
25
            [
26
                'menu_item' => 'fieldsets',
27
                'fieldsets_list' => $this->fieldsets->fetchAll(),
28
                'links' =>  [
29
                    'fieldsets' => [
30
                        'link' => $this->router->pathFor('admin.fieldsets.index'),
31
                        'title' => __('form_admin_fieldsets'),
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

31
                        'title' => /** @scrutinizer ignore-call */ __('form_admin_fieldsets'),
Loading history...
32
                        'active' => true
33
                    ],
34
                ],
35
                'buttons' => [
36
                    'fieldsets_add' => [
37
                        'link' => $this->router->pathFor('admin.fieldsets.add'),
38
                        'title' => __('form_admin_create_new_fieldset')
39
                    ]
40
                ],
41
            ]
42
        );
43
    }
44
45
    public function add($request, $response)
46
    {
47
        return $this->twig->render(
48
            $response,
49
            'plugins/form-admin/templates/extends/fieldsets/add.html',
50
            [
51
                'menu_item' => 'fieldsets',
52
                'fieldsets_list' => $this->fieldsets->fetchAll(),
53
                'links' =>  [
54
                    'fieldsets' => [
55
                        'link' => $this->router->pathFor('admin.fieldsets.index'),
56
                        'title' => __('form_admin_fieldsets'),
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
                        'title' => /** @scrutinizer ignore-call */ __('form_admin_fieldsets'),
Loading history...
57
                    ],
58
                    'fieldsets_add' => [
59
                        'link' => $this->router->pathFor('admin.fieldsets.add'),
60
                        'title' => __('form_admin_create_new_fieldset'),
61
                        'active' => true
62
                    ],
63
                ],
64
            ]
65
        );
66
    }
67
68
    public function addProcess($request, $response)
69
    {
70
        // Get data from POST
71
        $post_data = $request->getParsedBody();
72
73
        Arr::delete($post_data, 'csrf_name');
74
        Arr::delete($post_data, 'csrf_value');
75
76
        $id   = $this->slugify->slugify($post_data['id']);
77
        $data = [
78
            'title' => $post_data['title'],
79
            'default_field' => 'title',
80
            'icon' => $post_data['icon'],
81
            'hide' => (bool) $post_data['hide'],
82
            'sections' => [
83
                'main' => [
84
                    'title' => 'admin_main',
85
                    'form' => [
86
                        'fields' => [
87
                            'title' => [
88
                                'title' => 'admin_title',
89
                                'type' => 'text',
90
                                'size' => '12',
91
                            ],
92
                        ],
93
                    ],
94
                ],
95
            ],
96
        ];
97
98
        if ($this->fieldsets->create($id, $data)) {
99
            $this->flash->addMessage('success', __('form_admin_message_fieldset_created'));
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

99
            $this->flash->addMessage('success', /** @scrutinizer ignore-call */ __('form_admin_message_fieldset_created'));
Loading history...
100
        } else {
101
            $this->flash->addMessage('error', __('form_admin_message_fieldset_was_not_created'));
102
        }
103
104
        if (isset($post_data['create-and-edit'])) {
105
            return $response->withRedirect($this->router->pathFor('admin.fieldsets.edit') . '?id=' . $id);
106
        }
107
108
        return $response->withRedirect($this->router->pathFor('admin.fieldsets.index'));
109
    }
110
111
    public function edit($request, $response)
112
    {
113
        return $this->twig->render(
114
            $response,
115
            'plugins/form-admin/templates/extends/fieldsets/edit.html',
116
            [
117
                'menu_item' => 'fieldsets',
118
                'id' => $request->getQueryParams()['id'],
119
                'data' => $this->parser->encode($this->fieldsets->fetch($request->getQueryParams()['id']), 'yaml'),
120
                'links' =>  [
121
                    'fieldsets' => [
122
                        'link' => $this->router->pathFor('admin.fieldsets.index'),
123
                        'title' => __('form_admin_fieldsets'),
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

123
                        'title' => /** @scrutinizer ignore-call */ __('form_admin_fieldsets'),
Loading history...
124
                    ],
125
                    'fieldsets_editor' => [
126
                        'link' => $this->router->pathFor('admin.fieldsets.edit') . '?id=' . $request->getQueryParams()['id'],
127
                        'title' => __('form_admin_editor'),
128
                        'active' => true
129
                    ],
130
                ],
131
                'buttons' => [
132
                    'save_entry' => [
133
                        'type' => 'action',
134
                        'link' => 'javascript:;',
135
                        'title' => __('form_admin_save')
136
                    ],
137
                ],
138
            ]
139
        );
140
    }
141
142
    public function editProcess($request, $response)
143
    {
144
        $id   = $request->getParsedBody()['id'];
145
        $data = $request->getParsedBody()['data'];
146
147
        if ($this->fieldsets->update($request->getParsedBody()['id'], $this->parser->decode($data, 'yaml'))) {
148
            $this->flash->addMessage('success', __('form_admin_message_fieldset_saved'));
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

148
            $this->flash->addMessage('success', /** @scrutinizer ignore-call */ __('form_admin_message_fieldset_saved'));
Loading history...
149
        } else {
150
            $this->flash->addMessage('error', __('form_admin_message_fieldset_was_not_saved'));
151
        }
152
153
        return $response->withRedirect($this->router->pathFor('admin.fieldsets.edit') . '?id=' . $id);
154
    }
155
156
    public function rename($request, $response)
157
    {
158
        return $this->twig->render(
159
            $response,
160
            'plugins/form-admin/templates/extends/fieldsets/rename.html',
161
            [
162
                'menu_item' => 'fieldsets',
163
                'id' => $request->getQueryParams()['id'],
164
                'links' =>  [
165
                    'fieldsets' => [
166
                        'link' => $this->router->pathFor('admin.fieldsets.index'),
167
                        'title' => __('form_admin_fieldsets'),
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

167
                        'title' => /** @scrutinizer ignore-call */ __('form_admin_fieldsets'),
Loading history...
168
                    ],
169
                    'fieldsets_rename' => [
170
                        'link' => $this->router->pathFor('admin.fieldsets.rename') . '?id=' . $request->getQueryParams()['id'],
171
                        'title' => __('form_admin_rename'),
172
                        'active' => true
173
                    ],
174
                ],
175
            ]
176
        );
177
    }
178
179
    public function renameProcess($request, $response)
180
    {
181
        if ($this->fieldsets->rename($request->getParsedBody()['fieldset-id-current'], $request->getParsedBody()['id'])) {
182
            $this->flash->addMessage('success', __('form_admin_message_fieldset_renamed'));
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

182
            $this->flash->addMessage('success', /** @scrutinizer ignore-call */ __('form_admin_message_fieldset_renamed'));
Loading history...
183
        } else {
184
            $this->flash->addMessage('error', __('form_admin_message_fieldset_was_not_renamed'));
185
        }
186
187
        return $response->withRedirect($this->router->pathFor('admin.fieldsets.index'));
188
    }
189
190
    public function deleteProcess($request, $response)
191
    {
192
        if ($this->fieldsets->delete($request->getParsedBody()['fieldset-id'])) {
193
            $this->flash->addMessage('success', __('form_admin_message_fieldset_deleted'));
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

193
            $this->flash->addMessage('success', /** @scrutinizer ignore-call */ __('form_admin_message_fieldset_deleted'));
Loading history...
194
        } else {
195
            $this->flash->addMessage('error', __('form_admin_message_fieldset_was_not_deleted'));
196
        }
197
198
        return $response->withRedirect($this->router->pathFor('admin.fieldsets.index'));
199
    }
200
201
    public function duplicateProcess($request, $response)
202
    {
203
        if ($this->fieldsets->copy($request->getParsedBody()['fieldset-id'], $request->getParsedBody()['fieldset-id'] . '-duplicate-' . date('Ymd_His'))) {
204
            $this->flash->addMessage('success', __('form_admin_message_fieldset_duplicated'));
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

204
            $this->flash->addMessage('success', /** @scrutinizer ignore-call */ __('form_admin_message_fieldset_duplicated'));
Loading history...
205
        } else {
206
            $this->flash->addMessage('error', __('form_admin_message_fieldset_was_not_duplicated'));
207
        }
208
209
        return $response->withRedirect($this->router->pathFor('admin.fieldsets.index'));
210
    }
211
}
212