OverviewController   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 82
Duplicated Lines 31.71 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 7
c 3
b 0
f 0
lcom 1
cbo 4
dl 26
loc 82
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getPosts() 0 8 1
A getTags() 8 8 1
A getPopularTags() 0 8 1
A getCatName() 7 7 1
B overview() 3 24 2
A getUsers() 8 8 1

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
namespace Radchasay\Overview;
4
5
use \Anax\Configure\ConfigureInterface;
6
use \Anax\Configure\ConfigureTrait;
7
use \Anax\DI\InjectionAwareInterface;
8
use \Anax\Di\InjectionAwareTrait;
9
use \Radchasay\Comment\Post;
10
use \Radchasay\Comment\Comment;
11
use \Radchasay\Comment\CommentComments;
12
use \Radchasay\Overview\Overview;
13
use \Radchasay\Comment\PostCategory;
14
15
/**
16
 * A controller class.
17
 */
18
class OverviewController implements
19
    ConfigureInterface,
20
    InjectionAwareInterface
21
{
22
    use ConfigureTrait,
23
        InjectionAwareTrait;
24
25
26
    /**
27
     * @var $data description
28
     */
29
    //private $data;
30
31
    public function overview()
32
    {
33
        $title = "Overview";
34
        $view = $this->di->get("view");
35
        $pageRender = $this->di->get("pageRender");
36
37
        $posts = $this->getPosts();
38
39
        $allPosts = [];
40
41 View Code Duplication
        foreach ($posts as $p) {
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...
42
            array_push($allPosts, [$p, $this->getTags([$p->postid])]);
43
        }
44
45
        $data = [
46
            "items" => $this->getUsers(),
47
            "posts" => $allPosts,
48
            "popularTags" => $this->getPopularTags()
49
        ];
50
51
        $view->add("overview/overview", $data);
52
53
        $pageRender->renderPage(["title" => $title]);
54
    }
55
56 View Code Duplication
    public function getUsers()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
57
    {
58
        $overview = new Overview();
59
60
        $data = $overview->returnLimitUsers($this->di->get("db"), "points desc", 5);
61
62
        return $data;
63
    }
64
65
    public function getPosts()
66
    {
67
        $overview = new Overview();
68
69
        $data = $overview->returnLimitPosts($this->di->get("db"));
70
71
        return $data;
72
    }
73
74 View Code Duplication
    public function getTags($id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
75
    {
76
        $overview = new Overview();
77
78
        $data = $overview->returnAllTagsFromPost($this->di->get("db"), [$id]);
79
80
        return $data;
81
    }
82
83
    public function getPopularTags()
84
    {
85
        $overview = new Overview();
86
87
        $data = $overview->returnPopularTags($this->di->get("db"));
88
89
        return $data;
90
    }
91
92 View Code Duplication
    public function getCatName($id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
93
    {
94
        $postcat = new PostCategory();
95
        $postcat->setDb($this->di->get("db"));
96
        $res = $postcat->getCatName($id);
97
        return $res;
98
    }
99
}
100