Completed
Push — master ( 22d22f...259b7d )
by Gabriel
19:09
created

RecoverControllerTrait::index()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 15
ccs 0
cts 9
cp 0
crap 6
rs 9.7666
c 0
b 0
f 0
1
<?php
2
3
namespace ByTIC\Hello\Modules\Frontend\Controllers\Traits;
4
5
use ByTIC\Hello\Models\Users\User;
6
use ByTIC\Hello\Modules\AbstractModule\Forms\Users\RecoverPasswordFormTrait;
7
use Nip\Form\Form;
8
use Nip\Records\Record;
9
use Nip\View;
10
11
/**
12
 * Trait RecoverControllerTrait
13
 * @package ByTIC\Hello\Modules\Frontend\Controllers\Traits
14
 *
15
 * @method View getView()
16
 * @method Record|User _getUser()
17
 */
18
trait RecoverControllerTrait
19
{
20
    public function index()
21
    {
22
        $this->getView()->set('headerTitle', $this->_getUser()->getManager()->getLabel('recoverPassword'));
23
24
        /** @var RecoverPasswordFormTrait|Form $formsRecover */
25
        $formsRecover = $this->_getUser()->getForm('recoverPassword');
26
27
        if ($formsRecover->execute()) {
0 ignored issues
show
Bug introduced by
The method execute does only exist in Nip\Form\Form, but not in ByTIC\Hello\Modules\Abst...ecoverPasswordFormTrait.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
28
            $redirect = $this->Url()->assemble('frontend.recover', $this->getRequest()->query->all());
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...
Bug introduced by
It seems like getRequest() 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...
29
            $this->flashRedirect($this->getModelManager()->getMessage('recoverPassword.success'), $redirect);
0 ignored issues
show
Bug introduced by
It seems like getModelManager() 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 flashRedirect() 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...
30
        }
31
32
        $this->forms['recover'] = $formsRecover;
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...
33
        $this->_setMeta('recoverPassword');
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...
34
    }
35
}
36