Passed
Push — master ( 0d9957...3a195a )
by Mihail
04:49
created

Apps/Controller/Admin/User/ActionApprove.php (1 issue)

Severity
1
<?php
2
3
namespace Apps\Controller\Admin\User;
4
5
6
use Apps\ActiveRecord\User;
7
use Ffcms\Core\Arch\View;
8
use Ffcms\Core\Exception\NotFoundException;
9
use Ffcms\Core\Network\Request;
10
use Ffcms\Core\Network\Response;
11
12
/**
13
 * Trait ActionApprove
14
 * @package Apps\Controller\Admin\User
15
 * @property Request $request
16
 * @property Response $response
17
 * @property View $view
18
 */
19
trait ActionApprove
20
{
21
    /**
22
     * Approve user and redirect to user list
23
     * @param string $id
24
     * @return void
25
     * @throws NotFoundException
26
     */
27
    public function approve($id)
28
    {
29
        /** @var User $record */
30
        $record = User::where('id', $id)
31
            ->whereNotNull('approve_token')
32
            ->first();
33
34
        if (!$record) {
0 ignored issues
show
$record is of type Apps\ActiveRecord\User, thus it always evaluated to true.
Loading history...
35
            throw new NotFoundException(__('User not found'));
36
        }
37
38
        $record->approve_token = null;
39
        $record->save();
40
        $this->response->redirect('user/index');
41
    }
42
}