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

Apps/Controller/Admin/Comments/ActionIndex.php (1 issue)

1
<?php
2
3
namespace Apps\Controller\Admin\Comments;
4
5
use Apps\ActiveRecord\CommentPost;
6
use Ffcms\Core\Arch\View;
7
use Ffcms\Core\Network\Request;
8
use Ffcms\Core\Network\Response;
9
10
/**
11
 * Trait ActionIndex
12
 * @package Apps\Controller\Admin\Comments
13
 * @property Request $request
14
 * @property Response $response
15
 * @property View $view
16
 */
17
trait ActionIndex
18
{
19
    /**
20
     * List user comments with pagination
21
     * @return string|null
22
     */
23
    public function index(): ?string
24
    {
25
        // set current page and offset
26
        $page = (int)$this->request->query->get('page');
27
        $offset = $page * self::ITEM_PER_PAGE;
28
29
        // get result as active records object with offset
30
        $records = CommentPost::orderBy('id', 'desc')
31
            ->skip($offset)
32
            ->take(self::ITEM_PER_PAGE)
33
            ->get();
34
35
        // render output view
36
        return $this->view->render('comments/index', [
37
            'records' => $records,
38
            'pagination' => [
39
                'url' => ['comments/index'],
40
                'page' => $page,
41
                'step' => self::ITEM_PER_PAGE,
42
                'total' => CommentPost::count()
0 ignored issues
show
Bug Best Practice introduced by zenn
The method Ffcms\Core\Arch\ActiveModel::count() is not static, but was called statically. ( Ignorable by Annotation )

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

42
                'total' => CommentPost::/** @scrutinizer ignore-call */ count()
Loading history...
43
            ]
44
        ]);
45
    }
46
}
47