ActionFieldDelete   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A profileFieldDelete() 0 21 5
1
<?php
2
3
namespace Apps\Controller\Admin\Profile;
4
5
use Apps\ActiveRecord\ProfileField;
6
use Apps\Model\Admin\Profile\FormFieldUpdate;
7
use Ffcms\Core\Arch\View;
8
use Ffcms\Core\Exception\ForbiddenException;
9
use Ffcms\Core\Helper\Type\Any;
10
use Ffcms\Core\Network\Request;
11
use Ffcms\Core\Network\Response;
12
13
/**
14
 * Trait ActionFieldDelete
15
 * @package Apps\Controller\Admin\Profile
16
 * @property Request $request
17
 * @property Response $response
18
 * @property View $view
19
 */
20
trait ActionFieldDelete
21
{
22
    /**
23
     * Delete custom profile field
24
     * @param string $id
25
     * @return string
26
     * @throws ForbiddenException
27
     */
28
    public function profileFieldDelete($id): ?string
29
    {
30
        if (!Any::isInt($id) || $id < 1) {
31
            throw new ForbiddenException();
32
        }
33
34
        // check if record with $id is exist
35
        $record = ProfileField::find($id);
36
        if (!$record) {
37
            throw new ForbiddenException();
38
        }
39
40
        $model = new FormFieldUpdate($record);
41
        // if delete is submited - lets remove this record
42
        if ($model->send()) {
43
            $model->delete();
44
            $this->response->redirect('profile/fieldlist');
45
        }
46
47
        return $this->view->render('profile/field_delete', [
48
            'model' => $model
49
        ]);
50
    }
51
}
52