IpVerifyController::indexActionPost()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Anax\Controller;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
use Anax\IpVerify\IpVerify;
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
 * The controller will be injected with $di if implementing the interface
16
 * ContainerInjectableInterface, like this sample class does.
17
 * The controller is mounted on a particular route and can then handle all
18
 * requests for that mount point.
19
 *
20
 * @SuppressWarnings(PHPMD.TooManyPublicMethods)
21
 */
22
class IpVerifyController implements ContainerInjectableInterface
23
{
24
    use ContainerInjectableTrait;
25
    protected $ipVerify;
26
    protected $request;
27
    protected $session;
28
    protected $response;
29
30
31
    /**
32
     * @var string $db a sample member variable that gets initialised
33
     */
34
    /**
35
     * The initialize method is optional and will always be called before the
36
     * target method/action. This is a convienient method where you could
37
     * setup internal properties that are commonly used by several methods.
38
     *
39
     * @return void
40
     */
41 3
    public function initialize() : void
42
    {
43
        // Use to initialise member variables.
44 3
        $this->ipVerify = new IpVerify();
45 3
        $this->request = $this->di->get("request");
46 3
        $this->session = $this->di->get("session");
47 3
        $this->response = $this->di->get("response");
48 3
    }
49
50
51
52
    /**
53
     * This is the index method action, it handles:
54
     * ANY METHOD mountpoint
55
     * ANY METHOD mountpoint/
56
     * ANY METHOD mountpoint/index
57
     *
58
     * @return object
59
     */
60 2
    public function indexAction() : object
61
    {
62 2
        $page = $this->di->get("page");
63 2
        $title = "Ip Validering";
64 2
        $ipAddress = $this->session->get("ipAddress");
65 2
        if ($ipAddress) {
66 1
            $protocol = $this->ipVerify->getIpInfo($ipAddress);
67 1
            $isValid = $this->ipVerify->ipVerify($ipAddress) ? "true" : "false";
68 1
            $domain = $this->ipVerify->getDomain($ipAddress);
69 1
            $this->session->set("ipAddress", null);
70
        } else {
71 1
            $protocol = "";
72 1
            $domain = "";
73 1
            $isValid = "";
74
        }
75
        
76 2
        $page->add("ipVerify/index", [
77 2
            "protocol" => $protocol,
78 2
            "domain" => $domain,
79 2
            "title" => $title,
80 2
            "ip" => $ipAddress,
81 2
            "isValid" => $isValid,
82
        ]);
83
84 2
        return $page->render();
85
    }
86
87
88
    /**
89
     * This sample method action it the handler for route:
90
     * POST mountpoint/create
91
     *
92
     * @return object
93
     */
94 1
    public function indexActionPost() : object
95
    {
96 1
        $ipAddress = $this->request->getPost("ipAddress");
97 1
        $this->session->set("ipAddress", $ipAddress);
98
99 1
        return $this->response->redirect("verify_ip/index");
100
    }
101
}
102