ForumController::indexActionGet()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 55

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 55
c 0
b 0
f 0
rs 8.9818
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Forum\Forum;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
use Forum\Tag\Tag;
8
use Forum\User\User;
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 ForumController 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
        $page = $this->di->get("page");
54
        $question = new Question();
55
        $user = new User();
56
        $tag = new Tag();
57
        $user_id = $this->di->get("session")->get("user_id");
58
        $db = $this->di->get("dbqb");
59
        $question->setDb($db);
60
        $user->setDb($db);
61
        $tag->setDb($db);
62
        $mostActiveUsers = $user->findAllWhere("id in (
63
        select user_id
64
        from (select sum(count) as count, user_id
65
              from (
66
                       select count(id) as count, user_id
67
                       from Question
68
                       group by user_id
69
                       union
70
                       select count(id) as count, user_id
71
                       from Comment
72
                       group by user_id
73
                       union
74
                       select count(id) as count, user_id
75
                       from Answer
76
                       group by user_id
77
                   )
78
              group by user_id
79
             ) order by count limit 10
80
        )", []);
81
        $mostPopularTags = $tag->findAllWhere("id in (
82
            select tag_id
83
            from (
84
                select count(question_id) as count, tag_id
85
                from TagQuestion
86
                group by tag_id
87
            ) order by count desc limit 10
88
        )", []);
89
        $mostRecentQuestions = $db->connect()
90
            ->execute(
91
                "select * from Question order by created desc limit 5"
92
                , [])
93
            ->fetchAllClass(Question::class);
94
        $data = [
95
            "questions" => $question->findAll(),
96
            "mostActiveUsers" => $mostActiveUsers,
97
            "mostPopularTags" => $mostPopularTags,
98
            "mostRecentQuestions" => $mostRecentQuestions,
99
            "user" => $user->findById($user_id),
100
            "title" => "Index page"
101
        ];
102
103
        $page->add("forum/index", $data);
104
        return $page->render($data);
105
    }
106
107
}
108