Passed
Push — master ( fd5047...a08399 )
by André
01:35
created

CommentsController   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 72
Duplicated Lines 20.83 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 48.84%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 1
dl 15
loc 72
ccs 21
cts 43
cp 0.4884
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 4 1
A inject() 0 5 1
A add() 8 8 2
A delete() 7 7 2
A edit() 0 7 2
A get() 0 4 1
A addCommentSection() 0 7 1
A renderMain() 0 7 1
A renderEdit() 0 7 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 Anax\Comments;
4
5
use \Anax\DI\InjectionAwareInterface;
6
use \Anax\DI\InjectionAwareTrait;
7
8
class CommentsController implements InjectionAwareInterface
9
{
10
    use InjectionAwareTrait;
11
12
    private $db;
13
    private $session;
14
15
    public function init($database)
16
    {
17
        $this->db = $database;
18
    }
19
20
    public function inject($session)
21
    {
22
        $this->session = $session;
23
        return $this;
24
    }
25
26 1 View Code Duplication
    public function add()
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...
27
    {
28 1
        $user = $this->session->get("user");
29 1
        $this->di->get("comments")->addComment($_POST, $this->db, $user);
30 1
        if (!headers_sent()) {
31
            $this->di->get("response")->redirect("comments");
32
        }
33 1
    }
34
35 1 View Code Duplication
    public function delete()
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...
36
    {
37 1
        $this->di->get("comments")->deleteComment($_GET['id'], $this->db);
38 1
        if (!headers_sent()) {
39
            $this->di->get("response")->redirect("comments");
40
        }
41 1
    }
42
43 1
    public function edit()
44
    {
45 1
        $this->di->get("comments")->editComment($_POST['id'], $_POST['comment'], $this->db);
46 1
        if (!headers_sent()) {
47
            $this->di->get("response")->redirect("comments");
48
        }
49 1
    }
50
51 1
    public function get($id)
52
    {
53 1
        return $this->di->get("comments")->getComment($id, $this->db);
54
    }
55
56 1
    public function addCommentSection()
57
    {
58 1
        $url = $this->di->get("url")->create('post_comment');
59 1
        $del = $this->di->get("url")->create('delete_comment');
60 1
        $edit = $this->di->get("url")->create('preview');
61 1
        $this->di->get("comments")->commentSection($url, $del, $edit, $this->di->get("session"));
62 1
    }
63
64
    public function renderMain()
65
    {
66
        $this->di->get("view")->add("comments/comments");
67
        $this->di->get("pageRender")->renderPage([
68
            "title" => "Comments"
69
        ]);
70
    }
71
72
    public function renderEdit()
73
    {
74
        $this->di->get("view")->add("comments/edit_comment");
75
        $this->di->get("pageRender")->renderPage([
76
            "title" => "Edit Comment"
77
        ]);
78
    }
79
}
80