LinkedinLoginForm::__construct()   D
last analyzed

Complexity

Conditions 9
Paths 28

Size

Total Lines 44
Code Lines 30

Duplication

Lines 44
Ratio 100 %

Importance

Changes 0
Metric Value
dl 44
loc 44
rs 4.909
c 0
b 0
f 0
cc 9
eloc 30
nc 28
nop 5
1
<?php
2
3 View Code Duplication
class LinkedinLoginForm extends LoginForm
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
    protected $authenticator_class = 'LinkedinAuthenticator';
6
7
    public function __construct($controller, $method, $fields = null, $actions = null, $checkCurrentUser = true)
0 ignored issues
show
Coding Style introduced by
__construct uses the super-global variable $_REQUEST 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...
8
    {
9
        if (isset($_REQUEST['BackURL'])) {
10
            $backURL = $_REQUEST['BackURL'];
11
        } else {
12
            $backURL = Session::get('BackURL');
13
        }
14
        if ($checkCurrentUser && Member::currentUser() && Member::logged_in_session_exists()) {
15
            $fields = new FieldSet(
16
                new HiddenField("AuthenticationMethod", null, $this->authenticator_class, $this)
0 ignored issues
show
Documentation introduced by
'AuthenticationMethod' is of type string, but the function expects a object<The>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$this->authenticator_class is of type string, but the function expects a object<The>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$this is of type this<LinkedinLoginForm>, but the function expects a object<reference>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
17
            );
18
            $actions = new FieldSet(
19
                new FormAction("logout", _t('Member.BUTTONLOGINOTHER', "Log in as someone else"))
0 ignored issues
show
Documentation introduced by
'logout' is of type string, but the function expects a object<The>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
20
            );
21
        } else {
22
            if (!$fields) {
23
                $fields = new FieldSet(
24
                    new HiddenField("AuthenticationMethod", null, $this->authenticator_class, $this)
0 ignored issues
show
Documentation introduced by
'AuthenticationMethod' is of type string, but the function expects a object<The>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$this->authenticator_class is of type string, but the function expects a object<The>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$this is of type this<LinkedinLoginForm>, but the function expects a object<reference>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
25
                );
26
                if (Security::$autologin_enabled) {
27
                    $fields->push(new CheckboxField(
28
                        "Remember",
0 ignored issues
show
Documentation introduced by
'Remember' is of type string, but the function expects a object<The>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
29
                        _t('Member.REMEMBERME'),
0 ignored issues
show
Documentation introduced by
_t('Member.REMEMBERME') is of type string, but the function expects a object<The>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
30
                        Session::get('SessionForms.LinkedinLoginForm.Remember'),
31
                        $this
0 ignored issues
show
Documentation introduced by
$this is of type this<LinkedinLoginForm>, but the function expects a object<reference>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
32
                    ));
33
                }
34
            }
35
            if (!$actions) {
36
                $actions = new FieldSet(
37
                    new ImageFormAction('dologin', 'Sign in with LinkedIn', 'linkedin/Images/linkedin.png')
0 ignored issues
show
Documentation introduced by
'dologin' is of type string, but the function expects a object<The>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
38
                );
39
            }
40
        }
41
        if (!empty($backURL)) {
42
            $fields->push(new HiddenField('BackURL', 'BackURL', $backURL));
0 ignored issues
show
Documentation introduced by
'BackURL' is of type string, but the function expects a object<The>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
'BackURL' is of type string, but the function expects a object<The>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
43
        }
44
        parent::__construct(
45
            $controller,
46
            $method,
47
            $fields,
48
            $actions
49
        );
50
    }
51
52
    protected function getMessageFromSession()
53
    {
54
        parent::getMessageFromSession();
55
        if (($member = Member::currentUser()) && !$this->message) {
56
            $this->message = sprintf(_t('Member.LOGGEDINAS'), $member->FirstName);
57
        }
58
    }
59
60
    protected function dologin($data)
61
    {
62
        if (!empty($data['BackURL'])) {
63
            Session::set('BackURL', $data['BackURL']);
64
        }
65
        Session::set('SessionForms.LinkedinLoginForm.Remember', !empty($data['Remember']));
0 ignored issues
show
Documentation introduced by
!empty($data['Remember']) is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
66
        return LinkedinAuthenticator::authenticate($data, $this);
67
    }
68
69
    /**
70
     * Log out form handler method
71
     *
72
     * This method is called when the user clicks on "logout" on the form
73
     * created when the parameter <i>$checkCurrentUser</i> of the
74
     * {@link __construct constructor} was set to TRUE and the user was
75
     * currently logged in.
76
     */
77
    public function logout()
78
    {
79
        $s = new Security();
80
        $s->logout();
81
    }
82
}
83