Intraface_Controller_Login::postForm()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 0
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
ccs 0
cts 11
cp 0
crap 6
1
<?php
2
/**
3
 * Logout
4
 *
5
 * @package Intraface
6
 * @author  Lars Olesen <[email protected]>
7
 * @since   0.1.0
8
 * @version @package-version@
9
 */
10
class Intraface_Controller_Login extends k_Component
11
{
12
    protected $template;
13
    protected $kernel;
14
    protected $auth;
15
    protected $mdb2;
16
17
    function __construct(k_TemplateFactory $template, Intraface_Auth $auth, MDB2_Driver_Common $mdb2, Intraface_Log $log)
18
    {
19
        $this->template = $template;
20
        $this->auth = $auth;
21
        $this->mdb2 = $mdb2;
22
        $this->log = $log;
0 ignored issues
show
Bug introduced by
The property log does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
23
    }
24
25
    function execute()
26
    {
27
        $this->url_state->init("continue", $this->url('/restricted'));
28
        return parent::execute();
29
    }
30
31
    function renderHtml()
32
    {
33
        $this->document->setTitle('Login');
34
        $smarty = $this->template->create(dirname(__FILE__) . '/templates/login');
35
        return $smarty->render($this);
36
    }
37
38
    function postForm()
39
    {
40
        $user = $this->selectUser($this->body('email'), $this->body('password'));
41
        if ($user) {
42
            $this->session()->set('intraface_identity', $user);
0 ignored issues
show
Bug introduced by
The method set cannot be called on $this->session() (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
43
            return new k_SeeOther($this->query('continue'));
44
        } else {
45
            return new k_SeeOther($this->url(null, array('flare' => 'Wrong credentials')));
46
        }
47
        return $this->render();
0 ignored issues
show
Unused Code introduced by
return $this->render(); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
48
    }
49
50
    protected function selectUser($username, $password)
51
    {
52
        $adapter = new Intraface_Auth_User($this->mdb2, $this->session()->sessionId(), $username, $password);
0 ignored issues
show
Bug introduced by
The method sessionId cannot be called on $this->session() (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
53
54
        // $this->auth->attachObserver($this->log);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
55
        $this->auth->authenticate($adapter);
56
57
        if (!$this->auth->hasIdentity()) {
58
            return false;
59
        }
60
61
        return new Intraface_AuthenticatedUser($username, $this->language());
62
    }
63
}
64