Completed
Push — master ( 7ad915...1f6acb )
by Park Jong-Hun
03:16
created

Auth::doLogout()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace App\Controller;
4
5
use Core\Application;
6
use App\Auth\AuthManager;
7
use App\Auth\LoginManagerInterface;
8
use App\Auth\AccountManagerInterface;
9
10
class Auth
11
{
12
    /**
13
     * @var AccountManagerInterface
14
     */
15
    private $accountManager;
16
17
    /**
18
     * @var LoginManagerInterface
19
     */
20
    private $loginManager;
21
22
    public function __construct()
23
    {
24
        $this->accountManager = AuthManager::getInstance()->getDefaultAccountManager();
25
        $this->loginManager = AuthManager::getInstance()->getDefaultLoginManager();
26
    }
27
28
    public function viewLoginForm()
29
    {
30
        return 'auth/login';
31
    }
32
33
    public function doLogin()
0 ignored issues
show
Coding Style introduced by
doLogin uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
34
    {
35
        $this->loginManager->login($_POST['account_id'], $_POST['password']);
36
        return 'redirect: ' . Application::getInstance()->url();
37
    }
38
39
    public function doLogout()
40
    {
41
        $this->loginManager->logout();
42
        return 'redirect: ' . Application::getInstance()->url();
43
    }
44
}
45