Passed
Push — master ( 819cbf...086d7c )
by Nicklas
02:29
created

CommentController::getIndex()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 15
cts 15
cp 1
rs 9.0856
c 0
b 0
f 0
cc 2
eloc 13
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Nicklas\Comment;
4
5
use \Nicklas\Comment\HTMLForm\CreateCommentForm;
6
use \Nicklas\Comment\HTMLForm\EditCommentForm;
7
8
/**
9
 * Extends the UserController, for comments
10
 */
11
class CommentController extends AdminController
12
{
13
14
15
    /**
16
     * Show all items.
17
     *
18
     * @return void
19
     */
20 1
    public function getIndex()
21
    {
22 1
        $comment = new Comment($this->di);
23 1
        $comment->setDb($this->di->get("db"));
24
25 1
        $form       = new CreateCommentForm($this->di);
26 1
        $form->check();
27
28
        $views = [
29 1
            ["comment/view-all", ["comments" => $comment->getAll()], "main"],
30 1
            ["comment/makeComment", ["form" => $form->getHTML()], "main"]
31 1
        ];
32
33
        // If not logged in, render other views
34 1
        if (!$this->di->get("session")->has("user")) {
35
            $views = [
36 1
                ["comment/view-all", ["comments" => $comment->getAll()], "main"],
37 1
                ["comment/loginComment", [], "main"]
38 1
            ];
39 1
        }
40
41 1
        $this->renderPage($views, "A collection of comments");
42 1
    }
43
44
    /**
45
     * @param integer $id.
0 ignored issues
show
Bug introduced by
There is no parameter named $id.. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
46
     *
47
     * @return void
48
     */
49 1
    public function getPostEditComment($id)
50
    {
51
52 1
        $comment = new Comment($this->di);
53 1
        $comment->setDb($this->di->get("db"));
54 1
        $comment = $comment->get($id);
55
56 1
        $form       = new EditCommentForm($this->di, $id);
57 1
        $form->check();
58
59
60
        $views = [
61 1
            ["comment/editComment", ["form" => $form->getHTML(), "comment" => $comment], "main"],
62 1
        ];
63
64
        // if it belongs to user, or user is admin ignore
65 1
        $userName = $this->di->get("session")->get("user");
66 1
        if (!$comment->controlAuthority($userName)) {
0 ignored issues
show
Bug introduced by
The method controlAuthority cannot be called on $comment (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
67
            $views = [
68 1
                ["comment/fail", [], "main"],
69 1
            ];
70 1
        }
71
72
73 1
        $this->renderPage($views, "A collection of comments");
74 1
    }
75
}
76