Test Failed
Push — master ( e3c39f...fe570d )
by Mihail
07:20
created

Apps/Controller/Front/Profile/ActionIgnore.php (2 issues)

Labels
1
<?php
2
3
namespace Apps\Controller\Front\Profile;
4
5
use Apps\ActiveRecord\Blacklist;
6
use Apps\Model\Front\Profile\FormIgnoreAdd;
7
use Ffcms\Core\App;
8
use Ffcms\Core\Arch\View;
9
use Ffcms\Core\Exception\ForbiddenException;
10
use Ffcms\Core\Network\Request;
11
use Ffcms\Core\Network\Response;
12
13
/**
14
 * Trait ActionIgnore
15
 * @package Apps\Controller\Front\Profile
16
 * @property View $view
17
 * @property Request $request
18
 * @property Response $response
19
 */
20
trait ActionIgnore
21
{
22
    /**
23
     * Show users in blacklist and allow add new users
24
     * @return string
25
     * @throws \Ffcms\Core\Exception\SyntaxException
26
     * @throws ForbiddenException
27
     */
28
    public function ignore(): ?string
29
    {
30
        // check if not auth
31
        if (!App::$User->isAuth()) {
32
            throw new ForbiddenException();
33
        }
34
35
        // get user object and init model of it
36
        $user = App::$User->identity();
37
        $model = new FormIgnoreAdd($user);
0 ignored issues
show
It seems like $user can also be of type null; however, parameter $user of Apps\Model\Front\Profile...gnoreAdd::__construct() does only seem to accept Ffcms\Core\Interfaces\iUser, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

37
        $model = new FormIgnoreAdd(/** @scrutinizer ignore-type */ $user);
Loading history...
38
39
        // set user id from ?id= get param if form not sended
40
        if (!$model->send()) {
41
            $uid = (int)$this->request->query->get('id');
42
            if ($uid > 0) {
43
                $model->id = $uid;
44
            }
45
        }
46
47
        // sended new block add?
48
        if ($model->send() && $model->validate()) {
49
            if ($model->save()) {
50
                App::$Session->getFlashBag()->add('success', __('User was successful blocked!'));
51
            } else {
52
                App::$Session->getFlashBag()->add('error', __('This user is always in ignore list'));
53
            }
54
        }
55
56
        // get blocked users
57
        $query = Blacklist::where('user_id', '=', $user->getId());
58
59
        // prepare pagination data
60
        $page = (int)$this->request->query->get('page');
61
        $offset = $page * static::BLOCK_PER_PAGE;
0 ignored issues
show
The constant Apps\Controller\Front\Pr...nIgnore::BLOCK_PER_PAGE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
62
        $totalCount = $query->count();
63
64
        // get records as object
65
        $records = $query->with(['targetUser', 'targetUser.profile'])
66
            ->skip($offset)
67
            ->take(static::BLOCK_PER_PAGE)
68
            ->get();
69
70
        // render output view
71
        return $this->view->render('profile/ignore', [
72
            'records' => $records,
73
            'model' => $model,
74
            'pagination' => [
75
                'total' => $totalCount,
76
                'page' => $page,
77
                'step' => static::BLOCK_PER_PAGE
78
            ]
79
        ]);
80
    }
81
}
82