Check for code that has been commented out.
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(); |
||
39 | /**if (!(bool)$configs['userAdd']) { |
||
0 ignored issues
–
show
|
|||
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 |
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.