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

ActionList   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 45
rs 10
wmc 2
lcom 1
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
B listing() 0 37 2
1
<?php
2
3
namespace Apps\Controller\Front\Content;
4
5
use Apps\Model\Front\Content\EntityCategoryList;
6
use Ffcms\Core\App;
7
use Ffcms\Core\Arch\View;
8
use Ffcms\Core\Helper\HTML\SimplePagination;
9
use Ffcms\Core\Helper\Type\Arr;
10
use Ffcms\Core\Network\Request;
11
use Ffcms\Core\Network\Response;
12
13
/**
14
 * Trait ActionList
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 ActionList
22
{
23
    /**
24
     * List category content
25
     * @throws \Ffcms\Core\Exception\SyntaxException
26
     * @return string
27
     */
28
    public function listing()
29
    {
30
        $path = $this->request->getPathWithoutControllerAction();
31
        $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...
32
        $page = (int)$this->request->query->get('page', 0);
33
        $sort = (string)$this->request->query->get('sort', 'newest');
34
        $itemCount = (int)$configs['itemPerCategory'];
35
36
        // build special model with content list and category list information
37
        $model = new EntityCategoryList($path, $configs, $page, $sort);
38
39
        // prepare query string (?a=b) for pagination if sort is defined
40
        $sortQuery = null;
41
        if (Arr::in($sort, ['rating', 'views'])) {
42
            $sortQuery = ['sort' => $sort];
43
        }
44
45
        // build pagination
46
        $pagination = new SimplePagination([
47
            'url' => ['content/list', $path, null, $sortQuery],
48
            'page' => $page,
49
            'step' => $itemCount,
50
            'total' => $model->getContentCount()
51
        ]);
52
53
        // define list event
54
        App::$Event->run(static::EVENT_CONTENT_LIST, [
55
            'model' => $model
56
        ]);
57
58
        // draw response view
59
        return $this->view->render('list', [
60
            'model' => $model,
61
            'pagination' => $pagination,
62
            'configs' => $configs,
63
        ]);
64
    }
65
}
66