Passed
Push — master ( ef80b0...df5b6f )
by Mihail
04:52
created

ActionClear   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A clear() 0 19 4
1
<?php
2
3
namespace Apps\Controller\Admin\User;
4
5
6
use Apps\ActiveRecord\User;
7
use Apps\Model\Admin\User\FormUserClear;
8
use Ffcms\Core\App;
9
use Ffcms\Core\Arch\View;
10
use Ffcms\Core\Exception\NotFoundException;
11
use Ffcms\Core\Network\Request;
12
use Ffcms\Core\Network\Response;
13
14
/**
15
 * Trait ActionClear
16
 * @package Apps\Controller\Admin\User
17
 * @property Request $request
18
 * @property Response $response
19
 * @property View $view
20
 */
21
trait ActionClear
22
{
23
24
    /** Cleanup user added data - content, comments, feedback
25
     * @param string $id
26
     * @return string|null
27
     * @throws NotFoundException
28
     * @throws \Ffcms\Core\Exception\SyntaxException
29
     */
30
    public function clear($id): ?string
31
    {
32
        // find user object by passed id
33
        $user = User::with('profile')->find($id);
34
        if (!$user) {
35
            throw new NotFoundException(__('User not found'));
36
        }
37
38
        // initialize and process form model
39
        $model = new FormUserClear($user);
40
        if ($model->send() && $model->validate()) {
41
            $model->make();
42
            App::$Session->getFlashBag()->add('success', __('User input data clear successful'));
43
            $this->response->redirect('user/index');
44
        }
45
46
        // render output view
47
        return $this->view->render('user/user_clear', [
48
            'model' => $model
49
        ]);
50
    }
51
}