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

checkIsAuthenticated()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
nc 2
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
ccs 0
cts 4
cp 0
crap 12
1
<?php
2
3
namespace ByTIC\Hello\Modules\AbstractModule\Controllers\Traits;
4
5
/**
6
 * Trait AbstractAuthenticationControllerTrait
7
 * @package ByTIC\Hello\Modules\AbstractModule\Controllers\Traits
8
 */
9
trait AbstractAuthenticationControllerTrait
10
{
11
    use HasAuthenticationVariablesTrait;
12
13
    protected function beforeAction()
14
    {
15
        parent::beforeAction();
16
        $this->checkIsAuthenticated();
17
    }
18
19
    protected function afterActionViewVariables()
20
    {
21
        parent::afterActionViewVariables();
22
23
        $this->setAuthenticationVariablesInView();
24
    }
25
26
    /**
27
     * @param null $type
0 ignored issues
show
Bug introduced by
There is no parameter named $type. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
28
     */
29
    protected function checkIsAuthenticated()
30
    {
31
        if ($this->getName() != 'logout' && $this->_getUser()->authenticated()) {
0 ignored issues
show
Bug introduced by
It seems like getName() 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...
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->doSuccessRedirect();
33
        }
34
    }
35
36
    /**
37
     * @param null $type
38
     */
39
    protected function doSuccessRedirect($type = null)
40
    {
41
        $type = empty($type) ? $this->getName() : $type;
0 ignored issues
show
Bug introduced by
It seems like getName() 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...
42
        $this->flashRedirect(
43
            $this->getModelManager()->getMessage($type . '-success'),
44
            $this->getRedirectURL(),
45
            'success',
46
            'index'
0 ignored issues
show
Documentation introduced by
'index' is of type string, but the function expects a boolean.

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...
47
        );
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    protected function getRedirectURL()
54
    {
55
        $redirectVariable = $this->getAuthenticationValue('redirect');
56
        if (!empty($redirectVariable)) {
57
            $url = urldecode($redirectVariable);
58
            if (valid_url($url)) {
59
                return $url;
60
            }
61
        }
62
        return $this->getGenericRedirectURL();
63
    }
64
65
    /**
66
     * @return string|null
67
     */
68
    protected function getGenericRedirectURL()
69
    {
70
        $module = $this->getRequest()->getModuleName();
71
        return $this->Url()->assemble($module . '.logged_in');
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...
72
    }
73
74
    /**
75
     * @param $action
76
     */
77
    protected function _setMeta($action)
78
    {
79
        $label = $this->getModelManager()->getLabel($action . '-title');
80
        $urlMethod = 'get' . ucfirst($action) . 'URL';
81
        $this->getView()->Breadcrumbs()->addItem($label, $this->_getUser()->getManager()->$urlMethod());
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...
82
83
        $this->getView()->Meta()->prependTitle($label);
84
    }
85
86
    /**
87
     * @inheritdoc
88
     */
89
    protected function generateModelName()
90
    {
91
        return get_class($this->_getUser()->getManager());
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...
92
    }
93
}
94