Passed
Push — main ( 372069...dd0b9e )
by Åsa
02:30
created

CommentController::deleteAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
c 0
b 0
f 0
rs 9.7998
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Forum\Comment;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
use Forum\Comment\HTMLForm\CreateForm;
8
use Forum\Answer\Answer;
9
use Forum\Question\Question;
10
11
// use Anax\Route\Exception\ForbiddenException;
12
// use Anax\Route\Exception\NotFoundException;
13
// use Anax\Route\Exception\InternalErrorException;
14
15
/**
16
 * A sample controller to show how a controller class can be implemented.
17
 */
18
class CommentController implements ContainerInjectableInterface
19
{
20
    use ContainerInjectableTrait;
21
22
23
    /**
24
     * @var $data description
25
     */
26
    //private $data;
27
28
29
    // /**
30
    //  * The initialize method is optional and will always be called before the
31
    //  * target method/action. This is a convienient method where you could
32
    //  * setup internal properties that are commonly used by several methods.
33
    //  *
34
    //  * @return void
35
    //  */
36
    // public function initialize() : void
37
    // {
38
    //     ;
39
    // }
40
41
42
    /**
43
     * Description.
44
     *
45
     * @param datatype $variable Description
0 ignored issues
show
Bug introduced by
There is no parameter named $variable. 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 object as a response object
48
     * @throws Exception
49
     *
50
     */
51
    public function indexActionGet(): object
52
    {
53
        $user_id = $this->di->get("session")->get("user_id");
54
        var_dump($user_id);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($user_id); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
55
        if (!$user_id) {
56
            $this->di->get("response")->redirect("user/login");
57
        }
58
    }
59
60 View Code Duplication
    public function questionAction(int $questionId): object
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...
61
    {
62
        $page = $this->di->get("page");
63
        $form = new CreateForm($this->di, $questionId, "");
64
        $question = new Question();
65
        $question->setDb($this->di->get("dbqb"));
66
        $form->check();
67
        $text = $question->findById($questionId)->question;
68
        $data = [
69
            "form" => $form->getHTML(),
70
            "text" => $text,
71
            "title" => "create comment",
72
        ];
73
        $page->add("forum/create_comment", $data);
74
        return $page->render($data);
75
    }
76
77
78 View Code Duplication
    public function answerAction(int $answerId): object
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...
79
    {
80
        $page = $this->di->get("page");
81
        $form = new CreateForm($this->di, "", $answerId);
82
        $answer = new Answer();
83
        $answer->setDb($this->di->get("dbqb"));
84
        $form->check();
85
        $text = $answer->findById($answerId)->answer;
86
        $data = [
87
            "form" => $form->getHTML(),
88
            "text" => $text,
89
            "title" => "create comment",
90
        ];
91
        $page->add("forum/create_comment", $data);
92
        return $page->render($data);
93
    }
94
}
95