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

Apps/Controller/Front/Content/ActionMy.php (2 issues)

1
<?php
2
3
namespace Apps\Controller\Front\Content;
4
5
use Apps\ActiveRecord\Content as ContentRecord;
6
use Ffcms\Core\App;
7
use Ffcms\Core\Arch\View;
8
use Ffcms\Core\Exception\ForbiddenException;
9
use Ffcms\Core\Exception\NotFoundException;
10
use Ffcms\Core\Network\Request;
11
use Ffcms\Core\Network\Response;
12
13
/**
14
 * Trait ActionMy
15
 * @package Apps\Controller\Front\Content
16
 * @property View $view
17
 * @property Request $request
18
 * @property Response $response
19
 * @method array getConfigs
20
 */
21
trait ActionMy
22
{
23
24
    /**
25
     * Show user added content list
26
     * @return string
27
     * @throws ForbiddenException
28
     * @throws NotFoundException
29
     */
30
    public function my(): ?string
31
    {
32
        // check if user is auth
33
        if (!App::$User->isAuth()) {
34
            throw new ForbiddenException(__('Only authorized users can manage content'));
35
        }
36
37
        // check if user add enabled
38
        $configs = $this->getConfigs();
0 ignored issues
show
The assignment to $configs is dead and can be removed.
Loading history...
39
        /**if (!(bool)$configs['userAdd']) {
0 ignored issues
show
Unused Code Comprehensibility introduced by zenn1989
71% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
40
            throw new NotFoundException(__('User add is disabled'));
41
        }*/
42
43
        // prepare query
44
        $page = (int)$this->request->query->get('page', 0);
45
        $offset = $page * 10;
46
        $query = ContentRecord::where('author_id', App::$User->identity()->getId());
47
48
        // calc total count before limit applied
49
        $totalCount = $query->count();
50
51
        // build records object
52
        $records = $query->skip($offset)->take(10)->orderBy('id', 'DESC')->get();
53
54
        // render output view
55
        return $this->view->render('content/my', [
56
            'records' => $records,
57
            'pagination' => [
58
                'step' => 10,
59
                'total' => $totalCount,
60
                'page' => $page
61
            ]
62
        ]);
63
    }
64
}
65