Completed
Push — master ( ec1a89...79f0f5 )
by Nicklas
02:22
created

FrontController   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 3
dl 0
loc 50
ccs 0
cts 23
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A postComment() 0 15 3
B postVote() 0 19 7
1
<?php
2
3
namespace Nicklas\Comment;
4
5
use \Nicklas\Comment\Modules\Comment;
6
use \Nicklas\Comment\Modules\Vote;
7
8
/**
9
 * Extends the UserController, for comments
10
 */
11
class FrontController extends QuestionController
12
{
13
14
15
    /**
16
     * View specific question and create answer form
17
     *
18
     * @return void
19
     */
20
    public function postComment($id)
21
    {
22
        $text = isset($_POST["text"]) ? $_POST["text"] : "nothingfound";
23
24
        if ($text == "nothingfound") {
25
            return false;
26
        }
27
        $user = $this->di->get("session")->get("user");
28
        $comment = new Comment($this->di->get("db"));
29
        $comment->text = $text;
30
        $comment->parentId = $id;
31
        $comment->user = $user;
32
        $comment->save();
33
        return true;
34
    }
35
36
    /**
37
     * View specific question and create answer form
38
     *
39
     * @return void
40
     */
41
    public function postVote()
42
    {
43
        $vote = new Vote();
44
45
        $user = $this->di->get("session")->get("user");
46
47
        $parentType = isset($_POST["parentType"]) ? $_POST["parentType"] : "";
48
        $downVote   = isset($_POST["downVote"])   ? $_POST["downVote"]   : null;
49
        $parentId   = isset($_POST["parentId"])   ? $_POST["parentId"]   : "";
50
        $upVote     = isset($_POST["upVote"])     ? $_POST["upVote"]     : null;
51
52
        if ($upVote != null) {
53
            return $vote->like($user, $parentId, $parentType);
54
        }
55
        if ($downVote != null) {
56
            return $vote->dislike($user, $parentId, $parentType);
57
        }
58
        return false;
59
    }
60
}
61