TagController   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 107
c 0
b 0
f 0
ccs 31
cts 31
cp 1
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 7 1
A infoAction() 0 20 3
A indexActionGet() 0 9 1
A catchAll() 0 5 1
A dumpDiActionGet() 0 5 1
1
<?php
2
3
namespace Pamo\Tag;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
use Pamo\Tag\HTMLForm\SearchForm;
8
9
/**
10
 * Tag controller.
11
 */
12
class TagController implements ContainerInjectableInterface
13
{
14
    use ContainerInjectableTrait;
15
16
17
18
    /**
19
     * The initialize method is optional and will always be called before the
20
     * target method/action. This is a convienient method where you could
21
     * setup internal properties that are commonly used by several methods.
22
     *
23
     * @return void
24
     */
25 4
    public function initialize() : void
26
    {
27 4
        $this->base = "tag";
0 ignored issues
show
Bug Best Practice introduced by
The property base does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
28 4
        $this->title = "Tags";
0 ignored issues
show
Bug Best Practice introduced by
The property title does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
29 4
        $this->game = $this->di->get("game");
0 ignored issues
show
Bug Best Practice introduced by
The property game does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
30 4
        $this->page = $this->di->get("page");
0 ignored issues
show
Bug Best Practice introduced by
The property page does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
31 4
        $this->page->add("block/nav-admin", $this->game->getNav());
32 4
    }
33
34
35
36
    /**
37
     * Show all questions.
38
     *
39
     * @return object as a response object
40
     */
41 1
    public function indexActionGet() : object
42
    {
43 1
        $this->page->add($this->base . "/crud/view-all", [
44 1
            "tags" => $this->game->tag->findAll(),
45 1
            "game" => $this->game
46
        ]);
47
48 1
        return $this->page->render([
49 1
            "title" => $this->title,
50
        ]);
51
    }
52
53
54
55
    /**
56
     * Show all questions.
57
     *
58
     * @return object as a response object
59
     */
60 1
    public function infoAction($search = null) : object
61
    {
62 1
        $search = str_replace("-", " ", $search);
63
64 1
        if ($search) {
65 1
            $gameTag = $this->di->get("game-tag");
66 1
            $result = $gameTag->getAllData("/api/games?search=" . urlencode("$search"));
67
        }
68
69 1
        $form = new SearchForm($this->di, $search);
70 1
        $form->check();
71
72 1
        $this->page->add($this->base . "/game-tag", [
73 1
            "result" => isset($result) ? $result : null,
74 1
            "search" => $search,
75 1
            "form" => $form->getHTML($this->game->getFormSettings())
76
        ]);
77
78 1
        return $this->page->render([
79 1
            "title" => $this->title,
80
        ]);
81
    }
82
83
84
85
    /**
86
     * This sample method dumps the content of $di.
87
     * GET mountpoint/dump-app
88
     *
89
     * @return string
90
     */
91 1
    public function dumpDiActionGet() : string
92
    {
93
        // Deal with the action and return a response.
94 1
        $services = implode(", ", $this->di->getServices());
95 1
        return __METHOD__ . "<p>\$di contains: $services";
96
    }
97
98
99
100
    /**
101
     * Adding an optional catchAll() method will catch all actions sent to the
102
     * router. You can then reply with an actual response or return void to
103
     * allow for the router to move on to next handler.
104
     * A catchAll() handles the following, if a specific action method is not
105
     * created:
106
     * ANY METHOD mountpoint/**
107
     *
108
     * @param array $args as a variadic parameter.
109
     *
110
     * @return mixed
111
     *
112
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
113
     */
114 1
    public function catchAll(...$args)
0 ignored issues
show
Unused Code introduced by
The parameter $args is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

114
    public function catchAll(/** @scrutinizer ignore-unused */ ...$args)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
115
    {
116
        // Deal with the request and send an actual response, or not.
117
        //return __METHOD__ . ", \$db is {$this->db}, got '" . count($args) . "' arguments: " . implode(", ", $args);
118 1
        return;
119
    }
120
}
121