HomeController   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 56
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 5 1
A indexActionGet() 0 21 1
1
<?php
2
3
namespace Pan\Home;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
8
9
// use Anax\Route\Exception\ForbiddenException;
10
// use Anax\Route\Exception\NotFoundException;
11
// use Anax\Route\Exception\InternalErrorException;
12
13
/**
14
 * A sample controller to show how a controller class can be implemented.
15
 */
16
class HomeController implements ContainerInjectableInterface
17
{
18
    use ContainerInjectableTrait;
19
20
21
22
    /**
23
     * @var $data description
0 ignored issues
show
Documentation Bug introduced by
The doc comment $data at position 0 could not be parsed: Unknown type name '$data' at position 0 in $data.
Loading history...
24
     */
25
    private $currentUser;
0 ignored issues
show
introduced by
The private property $currentUser is not used, and could be removed.
Loading history...
26
    private $db;
27
28
29
30
    // /**
31
    //  * The initialize method is optional and will always be called before the
32
    //  * target method/action. This is a convienient method where you could
33
    //  * setup internal properties that are commonly used by several methods.
34
    //  *
35
    //  * @return void
36
    //  */
37
    public function initialize() : void
38
    {
39
        // Connect the database
40
        $this->db = $this->di->get("db");
41
        $this->db->connect();
42
    }
43
44
45
46
    /**
47
     * Show all items.
48
     *
49
     * @return object as a response object
50
     */
51
    public function indexActionGet() : object
52
    {
53
        $page = $this->di->get("page");
54
55
        $sql = "SELECT * FROM posts order by created desc;";
56
        $posts = $this->db->executeFetchAll($sql);
57
58
        $sql = "SELECT * FROM tags ORDER BY tagname asc limit 5;";
59
        $tags = $this->db->executeFetchAll($sql);
60
        //var_dump($tags);
61
        $sql = "SELECT * FROM users;";
62
        $users = $this->db->executeFetchAll($sql);
63
64
        $page->add("home/index", [
65
            "tags" => $tags,
66
            "posts" => $posts,
67
            "users" => $users,
68
        ]);
69
70
        return $page->render([
71
            "title" => "The home page ",
72
        ]);
73
    }
74
}
75