Completed
Push — master ( a08399...bacbcd )
by André
01:28
created

CommentsController   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 71.43%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 68
ccs 25
cts 35
cp 0.7143
rs 10
c 0
b 0
f 0

9 Methods

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