AdminUserForm::initialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 9.312
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * AdminUser
5
 * @copyright Copyright (c) 2011 - 2014 Aleksandr Torosh (http://wezoom.com.ua)
6
 * @author Aleksandr Torosh <[email protected]>
7
 */
8
9
namespace Admin\Form;
10
11
use Admin\Model\AdminUser;
12
use Application\Form\Form;
13
use Phalcon\Forms\Element\Select;
14
use Phalcon\Forms\Element\Text;
15
use Phalcon\Forms\Element\Email;
16
use Phalcon\Forms\Element\Password;
17
use Phalcon\Forms\Element\Check;
18
use Phalcon\Validation\Validator\Email as ValidatorEmail;
19
use Phalcon\Validation\Validator\PresenceOf;
20
21
class AdminUserForm extends Form
22
{
23
24
    public function initialize()
25
    {
26
        $this->add(
27
            (new Text('login', [
0 ignored issues
show
Documentation introduced by
(new \Phalcon\Forms\Elem...e)))->setLabel('Login') is of type null, but the function expects a object<Phalcon\Forms\ElementInterface>.

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...
28
                'required' => true,
29
            ]))->setLabel('Login')
30
        );
31
32
        $this->add(
33
            (new Email('email', [
0 ignored issues
show
Bug introduced by
The method setLabel cannot be called on (new \Phalcon\Forms\Elem...l format is invalid'))) (of type null).

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...
34
                'required' => true,
35
            ]))
36
                ->addValidator(new ValidatorEmail([
37
                    'message' => 'Email format is invalid',
38
                ]))
39
                ->setLabel('Email')
40
        );
41
42
        $this->add(
43
            (new Text('name'))
0 ignored issues
show
Documentation introduced by
(new \Phalcon\Forms\Elem...me'))->setLabel('Name') is of type null, but the function expects a object<Phalcon\Forms\ElementInterface>.

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...
44
                ->setLabel('Name')
45
        );
46
47
        $this->add(
48
            (new Select('role', AdminUser::$roles))
0 ignored issues
show
Documentation introduced by
(new \Phalcon\Forms\Elem...les))->setLabel('Role') is of type null, but the function expects a object<Phalcon\Forms\ElementInterface>.

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...
49
                ->setLabel('Role')
50
        );
51
52
        $this->add(
53
            (new Password('password'))
0 ignored issues
show
Documentation introduced by
(new \Phalcon\Forms\Elem...)->setLabel('Password') is of type null, but the function expects a object<Phalcon\Forms\ElementInterface>.

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...
54
                ->setLabel('Password')
55
        );
56
57
        $this->add(
58
            (new Check('active'))
0 ignored issues
show
Documentation introduced by
(new \Phalcon\Forms\Elem...'))->setLabel('Active') is of type null, but the function expects a object<Phalcon\Forms\ElementInterface>.

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...
59
                ->setLabel('Active')
60
        );
61
    }
62
63
    public function initAdding()
64
    {
65
        $password = $this->get('password');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $password is correct as $this->get('password') (which targets Phalcon\Forms\Form::get()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
66
        $password->setAttribute('required', true);
0 ignored issues
show
Bug introduced by
The method setAttribute cannot be called on $password (of type null).

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...
67
        $password->addValidator(new PresenceOf([
0 ignored issues
show
Bug introduced by
The method addValidator cannot be called on $password (of type null).

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...
68
            'message' => 'Password is required',
69
        ]));
70
71
    }
72
73
}
74