Test Failed
Push — master ( a6b51e...5fffdb )
by Gabriel
08:05
created

OAuthControllerTrait::with()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 0
dl 0
loc 24
rs 9.536
c 0
b 0
f 0
ccs 0
cts 14
cp 0
crap 12
1
<?php
2
3
namespace ByTIC\Hello\Modules\Frontend\Controllers\Traits;
4
5
use Exception;
6
use Hybrid_Endpoint;
7
use ByTIC\Hello\Library\Hybridauth\Hybridauth;
8
use Nip\Controllers\Traits\AbstractControllerTrait;
9
use Nip\Records\Locator\ModelLocator;
10
11
/**
12
 * Trait OAuthControllerTrait
13
 * @package ByTIC\Hello\Modules\Frontend\Controllers\Traits
14
 */
15
trait OAuthControllerTrait
16
{
17
    use AbstractControllerTrait;
18
    /**
19
     * @return Hybrid_Endpoint
20
     */
21
    public function index()
22
    {
23
        return Hybrid_Endpoint::process();
24
    }
25
26
    public function link()
27
    {
28
        $providerName = $_REQUEST["provider"];
29
        $userProfile = Hybridauth::instance()->authenticate($providerName);
30
31
        $this->_getUser()->first_name = $userProfile->firstName;
0 ignored issues
show
Bug introduced by
The property firstName does not seem to exist in Exception.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
Bug introduced by
It seems like _getUser() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
32
        $this->_getUser()->last_name = $userProfile->lastName;
0 ignored issues
show
Bug introduced by
The property lastName does not seem to exist in Exception.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
Bug introduced by
It seems like _getUser() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
33
        $this->_getUser()->email = $userProfile->email;
0 ignored issues
show
Bug introduced by
The property email does not seem to exist in Exception.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
Bug introduced by
It seems like _getUser() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
34
35
        $this->getView()->set('headerTitle', ModelLocator::get('users')->getLabel('o_auth_link.title'));
36
37
        foreach (['login', 'register'] as $userAction) {
38
            $form = $this->_getUser()->getForm($userAction);
0 ignored issues
show
Bug introduced by
It seems like _getUser() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
39
40
            if ($form->execute()) {
41
                $userLogin = ModelLocator::get('User_Logins')->getNew();
42
                $userLogin->id_user = $this->_getUser()->id;
0 ignored issues
show
Bug introduced by
It seems like _getUser() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
43
                $userLogin->provider_name = $providerName;
44
                $userLogin->provider_uid = $userProfile->identifier;
0 ignored issues
show
Bug introduced by
The property identifier does not seem to exist in Exception.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
45
                $userLogin->insert();
46
47
                $this->doSuccessRedirect($userAction);
0 ignored issues
show
Bug introduced by
The method doSuccessRedirect() does not exist on ByTIC\Hello\Modules\Fron...ts\OAuthControllerTrait. Did you maybe mean redirect()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
48
            }
49
            $this->forms[$userAction] = $form;
0 ignored issues
show
Bug introduced by
The property forms 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...
50
        }
51
52
        $this->_setMeta('login');
0 ignored issues
show
Bug introduced by
It seems like _setMeta() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
53
    }
54
55
    public function with()
56
    {
57
        $providerName = $this->getRequest()->get('provider');
58
        $userProfile = Hybridauth::instance()->authenticate($providerName);
59
60
        if ($userProfile instanceof Exception) {
61
            $this->getView()->set('exception', $userProfile);
62
        } else {
63
            $userExist = ModelLocator::get('User_Logins')->getUserByProvider($providerName, $userProfile->identifier);
64
65
            if (!$userExist) {
66
                $this->redirect($this->Url()->assemble(
0 ignored issues
show
Bug introduced by
It seems like Url() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
67
                    'frontend.o_auth.link',
68
                    [
69
                        'provider' => $providerName,
70
                        'redirect' => $this->getRedirectURL(),
0 ignored issues
show
Bug introduced by
The method getRedirectURL() does not exist on ByTIC\Hello\Modules\Fron...ts\OAuthControllerTrait. Did you maybe mean redirect()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
71
                    ]
72
                ));
73
            }
74
75
            $userExist->doAuthentication();
76
            $this->doSuccessRedirect();
0 ignored issues
show
Bug introduced by
The method doSuccessRedirect() does not exist on ByTIC\Hello\Modules\Fron...ts\OAuthControllerTrait. Did you maybe mean redirect()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
77
        }
78
    }
79
}
80