Code Duplication    Length = 24-28 lines in 3 locations

Apps/Controller/Admin/Content.php 3 locations

@@ 111-134 (lines=24) @@
108
     * @throws \Ffcms\Core\Exception\SyntaxException
109
     * @throws \Ffcms\Core\Exception\NativeException
110
     */
111
    public function actionDelete($id)
112
    {
113
        if (!Obj::isLikeInt($id) || $id < 1) {
114
            throw new NotFoundException();
115
        }
116
117
        // get content record and check availability
118
        $record = ContentEntity::find($id);
119
        if ($record === null || $record === false) {
120
            throw new NotFoundException();
121
        }
122
123
        // init delete model
124
        $model = new FormContentDelete($record);
125
        if ($model->send() && $model->validate()) {
126
            $model->make();
127
            App::$Session->getFlashBag()->add('success', __('Content is successful moved to trash'));
128
            App::$Response->redirect('content/index');
129
        }
130
131
        $this->response = App::$View->render('content_delete', [
132
            'model' => $model->export()
133
        ]);
134
    }
135
136
    /**
137
     * Restore deleted content
@@ 143-168 (lines=26) @@
140
     * @throws \Ffcms\Core\Exception\SyntaxException
141
     * @throws \Ffcms\Core\Exception\NativeException
142
     */
143
    public function actionRestore($id)
144
    {
145
        if (!Obj::isLikeInt($id) || $id < 1) {
146
            throw new NotFoundException();
147
        }
148
149
        // get removed object
150
        $record = ContentEntity::onlyTrashed()->find($id);
151
        if ($record === null || $record === false) {
152
            throw new NotFoundException();
153
        }
154
155
        // init model
156
        $model = new FormContentRestore($record);
157
        // check if action is send
158
        if ($model->send() && $model->validate()) {
159
            $model->make();
160
            App::$Session->getFlashBag()->add('success', __('Content are successful recovered'));
161
            App::$Response->redirect('content/index');
162
        }
163
164
        // draw response
165
        $this->response = App::$View->render('content_restore', [
166
            'model' => $model->export()
167
        ]);
168
    }
169
170
    /**
171
     * Clear the trashed items
@@ 218-245 (lines=28) @@
215
     * @throws \Ffcms\Core\Exception\SyntaxException
216
     * @throws \Ffcms\Core\Exception\NativeException
217
     */
218
    public function actionCategorydelete($id)
219
    {
220
        // check id
221
        if (!Obj::isLikeInt($id) || $id < 2) {
222
            throw new ForbiddenException();
223
        }
224
225
        // get object relation
226
        $record = ContentCategory::find($id);
227
        if ($record === null || $record === false) {
228
            throw new ForbiddenException();
229
        }
230
231
        // init model with object relation
232
        $model = new FormCategoryDelete($record);
233
234
        // check if delete is submited
235
        if ($model->send() && $model->validate()) {
236
            $model->make();
237
            App::$Session->getFlashBag()->add('success', __('Category is successful removed'));
238
            App::$Response->redirect('content/categories');
239
        }
240
241
        // draw view
242
        $this->response = App::$View->render('category_delete', [
243
            'model' => $model->export()
244
        ]);
245
    }
246
247
    /**
248
     * Show category edit and create