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

PostListAction   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 71
Duplicated Lines 11.27 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 1
dl 8
loc 71
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getTemplateName() 0 4 1
C getTemplateData() 8 53 10

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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