Passed
Push — master ( b534e3...17b30a )
by Mihail
19:51
created

ActionUnblock::unblock()   C

Complexity

Conditions 8
Paths 5

Size

Total Lines 29
Code Lines 14

Duplication

Lines 3
Ratio 10.34 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 8
eloc 14
c 1
b 1
f 0
nc 5
nop 1
dl 3
loc 29
rs 5.3846
1
<?php
2
3
namespace Apps\Controller\Front\Profile;
4
5
use Apps\ActiveRecord\Blacklist;
6
use Apps\Model\Front\Profile\FormIgnoreDelete;
7
use Ffcms\Core\App;
8
use Ffcms\Core\Arch\View;
9
use Ffcms\Core\Exception\ForbiddenException;
10
use Ffcms\Core\Exception\NotFoundException;
11
use Ffcms\Core\Helper\Type\Any;
12
use Ffcms\Core\Helper\Url;
13
use Ffcms\Core\Network\Response;
14
15
/**
16
 * Class ActionUnblock
17
 * @package Apps\Controller\Front\Profile
18
 * @property Response $response
19
 * @property View $view
20
 */
21
trait ActionUnblock
22
{
23
    /**
24
     * Unblock always blocked user
25
     * @param string $targetId
26
     * @return string
27
     * @throws \Ffcms\Core\Exception\SyntaxException
28
     * @throws ForbiddenException
29
     * @throws NotFoundException
30
     * @throws \Exception
31
     */
32
    public function unblock($targetId)
33
    {
34
        // check if user is auth
35
        if (!App::$User->isAuth()) {
36
            throw new ForbiddenException();
37
        }
38
39
        // check if target is defined
40 View Code Duplication
        if (!Any::isInt($targetId) || $targetId < 1 || !App::$User->isExist($targetId)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
            throw new NotFoundException();
42
        }
43
44
        $user = App::$User->identity();
45
46
        // check if target user in blacklist of current user
47
        if (!Blacklist::have($user->getId(), $targetId)) {
48
            throw new NotFoundException();
49
        }
50
51
        $model = new FormIgnoreDelete($user, $targetId);
52
        if ($model->send() && $model->validate()) {
53
            $model->make();
54
            $this->response->redirect(Url::to('profile/ignore'));
55
        }
56
57
        return $this->view->render('unblock', [
58
            'model' => $model
59
        ]);
60
    }
61
}
62