Completed
Push — master ( adf932...5ef467 )
by
unknown
08:09
created

GdprDeleteForm::attributeLabels()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of the 2amigos/yii2-usuario project.
5
 *
6
 * (c) 2amigOS! <http://2amigos.us/>
7
 * @author E. Alamo <[email protected]>
8
 *
9
 * For the full copyright and license information, please view
10
 * the LICENSE file that was distributed with this source code.
11
 */
12
13
namespace Da\User\Form;
14
15
16
use Da\User\Helper\SecurityHelper;
17
use Da\User\Model\User;
18
use Da\User\Traits\ContainerAwareTrait;
19
use Yii;
20
use yii\base\Model;
21
22
/**
23
 * Class GdprDeleteForm
24
 * @package Da\User\Form
25
 */
26
class GdprDeleteForm extends Model
27
{
28
    use ContainerAwareTrait;
29
30
    /**
31
     * @var string User's password
32
     */
33
    public $password;
34
    /**
35
     * @var SecurityHelper
36
     */
37
    protected $securityHelper;
38
    /**
39
     * @var User
40
     */
41
    protected $user;
42
43
    /**
44
     * @param SecurityHelper $securityHelper
45
     * @param array $config
46
     */
47 1
    public function __construct(SecurityHelper $securityHelper, $config = [])
48
    {
49 1
        $this->securityHelper = $securityHelper;
50 1
        parent::__construct($config);
51 1
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56 1
    public function rules()
57
    {
58
        return [
59 1
            'requiredFields' => [['password'], 'required'],
60
            'passwordValidate' => [
61 1
                'password',
62
                function ($attribute) {
63 1
                    if (!$this->securityHelper
64 1
                        ->validatePassword($this->password, $this->getUser()->password_hash)
0 ignored issues
show
Bug introduced by
Accessing password_hash on the interface yii\web\IdentityInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
65
                    ) {
66 1
                        $this->addError($attribute, Yii::t('usuario', 'Invalid password'));
67
                    }
68 1
                },
69
            ]
70
        ];
71
    }
72
73
    /**
74
     * @return User|null|\yii\web\IdentityInterface
75
     */
76 1
    public function getUser()
77
    {
78 1
        if ($this->user == null) {
79 1
            $this->user = Yii::$app->user->identity;
80
        }
81
82 1
        return $this->user;
83
    }
84
85 1
    public function attributeLabels()
86
    {
87
        return [
88 1
            'password' => Yii::t('usuario', 'Password'),
89
        ];
90
    }
91
}
92