Passed
Push — master ( e34aef...380f9e )
by Gabor
09:54
created

PostListAction::getTemplateData()   C

Complexity

Conditions 10
Paths 10

Size

Total Lines 53
Code Lines 43

Duplication

Lines 8
Ratio 15.09 %

Importance

Changes 0
Metric Value
dl 8
loc 53
rs 6.5333
c 0
b 0
f 0
cc 10
eloc 43
nc 10
nop 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * WebHemi.
4
 *
5
 * PHP version 7.1
6
 *
7
 * @copyright 2012 - 2017 Gixx-web (http://www.gixx-web.com)
8
 * @license   https://opensource.org/licenses/MIT The MIT License (MIT)
9
 *
10
 * @link      http://www.gixx-web.com
11
 */
12
declare(strict_types = 1);
13
14
namespace WebHemi\Middleware\Action\Website;
15
16
/**
17
 * Class PostListAction.
18
 */
19
class PostListAction extends IndexAction
20
{
21
    /**
22
     * Gets template map name or template file path.
23
     *
24
     * @return string
25
     */
26
    public function getTemplateName() : string
27
    {
28
        return 'website-post-list';
29
    }
30
31
    /**
32
     * Gets template data.
33
     *
34
     * @return array
35
     */
36
    public function getTemplateData() : array
37
    {
38
        $blogPosts = [];
39
        $currentMenu = '';
40
        $title = '';
41
        $params = $this->getRoutingParameters();
42
43
        if (isset($params['category'])) {
44
            $currentMenu = $params['category'];
45
            if ($params['category'] == 'posts') {
46
                $title = 'Posts';
47
                $blogPosts = [$this->database[1]];
48 View Code Duplication
            } elseif ($params['category'] == 'useful') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
                $title = 'Useful infos';
50
                $blogPosts = [$this->database[0]];
51
            } elseif ($params['category'] == 'events') {
52
                $title = 'Events';
53
                $blogPosts = [$this->database[2]];
54 View Code Duplication
            } elseif ($params['category'] == 'something') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
                $title = 'Something';
56
                $blogPosts = [$this->database[3]];
57
            }
58
        } elseif (isset($params['tag'])) {
59
            $currentMenu = $params['tag'];
60
            if ($params['tag'] == 'php') {
61
                $title = '#PHP';
62
                $blogPosts = [$this->database[0], $this->database[1]];
63
            } elseif ($params['tag'] == 'coding') {
64
                $title = '#Coding';
65
                $blogPosts = [$this->database[0], $this->database[1]];
66
            } elseif ($params['tag'] == 'munich') {
67
                $title = '#München';
68
                $blogPosts = [$this->database[2], $this->database[3]];
69
            }
70
        }
71
72
        return [
73
            'title' => $title,
74
            'activeMenu' => $currentMenu,
75
            'categories' => [
76
                ['url' => 'posts',      'title' => 'Posts',        'icon' => 'chrome_reader_mode',      'new' => 1],
77
                ['url' => 'useful',     'title' => 'Useful infos', 'icon' => 'perm_device_information', 'new' => 0],
78
                ['url' => 'events',     'title' => 'Events',       'icon' => 'event_note',              'new' => 0],
79
                ['url' => 'something',  'title' => 'Something',    'icon' => null,                      'new' => 8],
80
            ],
81
            'tags' => [
82
                ['url' => 'php',    'title' => 'PHP',    'total' => 132, 'new' =>  1],
83
                ['url' => 'coding', 'title' => 'Coding', 'total' => 132, 'new' =>  0],
84
                ['url' => 'munich', 'title' => 'Munich', 'total' => 132, 'new' => 85]
85
            ],
86
            'blogPosts' => $blogPosts,
87
        ];
88
    }
89
}
90