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

ActionMy   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 46
rs 10
wmc 3
lcom 1
cbo 6

1 Method

Rating   Name   Duplication   Size   Complexity  
B my() 0 35 3
1
<?php
2
3
namespace Apps\Controller\Front\Content;
4
5
use Ffcms\Core\App;
6
use Ffcms\Core\Arch\View;
7
use Ffcms\Core\Exception\ForbiddenException;
8
use Ffcms\Core\Exception\NotFoundException;
9
use Ffcms\Core\Helper\HTML\SimplePagination;
10
use Ffcms\Core\Network\Request;
11
use Ffcms\Core\Network\Response;
12
use Apps\ActiveRecord\Content as ContentRecord;
13
14
/**
15
 * Trait ActionMy
16
 * @package Apps\Controller\Front\Content
17
 * @property View $view
18
 * @property Request $request
19
 * @property Response $response
20
 * @method array getConfigs
21
 */
22
trait ActionMy
23
{
24
25
    /**
26
     * Show user added content list
27
     * @return string
28
     * @throws ForbiddenException
29
     * @throws NotFoundException
30
     * @throws \Ffcms\Core\Exception\SyntaxException
31
     */
32
    public function my()
33
    {
34
        // check if user is auth
35
        if (!App::$User->isAuth()) {
36
            throw new ForbiddenException(__('Only authorized users can manage content'));
37
        }
38
39
        // check if user add enabled
40
        $configs = $this->getConfigs();
0 ignored issues
show
Bug introduced by
It seems like getConfigs() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

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