AccountSelectionForm::rules()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 10
rs 10
cc 2
nc 1
nop 0
1
<?php
2
3
namespace sample\models;
4
5
use yii\base\Model;
6
7
/**
8
 * AccountSelectionForm is the model behind the OpenID Connect user account selection form.
9
 *
10
 * @property-read User|null $user This property is read-only.
11
 *
12
 */
13
class AccountSelectionForm extends Model
14
{
15
    /**
16
     * ID of the selected identity
17
     * @var int|null
18
     */
19
    public $identityId = null;
20
21
    /**
22
     * Helper property to access current user identity (not set via user input)
23
     * @var User|null
24
     */
25
    public $user = null;
26
27
    /**
28
     * @return array the validation rules.
29
     */
30
    public function rules()
31
    {
32
        return [
33
            ['identityId', 'required'],
34
            ['identityId', 'integer'],
35
            ['identityId', function ($attribute) {
36
                if (!$this->user->hasLinkedIdentity($this->$attribute)) {
0 ignored issues
show
Bug introduced by
The method hasLinkedIdentity() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

36
                if (!$this->user->/** @scrutinizer ignore-call */ hasLinkedIdentity($this->$attribute)) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
37
                    $this->addError(
38
                        $attribute,
39
                        'The current user does not have access to account ' . $this->$attribute
40
                    );
41
                }
42
            }],
43
        ];
44
    }
45
}
46