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

ActionApprove::approve()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 1
dl 0
loc 14
rs 10
c 0
b 0
f 0
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
introduced by zenn
$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
}