DeleteAccountForm::rules()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
namespace site\models;
3
4
use common\models\User;
5
use yii\base\Model;
6
use Yii;
7
8
/**
9
 * edit profile form
10
 */
11
class DeleteAccountForm extends Model
12
{
13
  public $password;
14
  private $user;
15
16
  /**
17
   * Creates a form model
18
   *
19
   * @param  object                          $user
20
   * @param  array                           $config name-value pairs that will be used to initialize the object properties
21
   */
22
  public function __construct(\common\interfaces\UserInterface $user, $config = []) {
23
    $this->user = $user;
24
    parent::__construct($config);
25
  }
26
27
  /**
28
   * @inheritdoc
29
   */
30
  public function rules()
31
  {
32
    return [
33
      ['password', 'required'],
34
      ['password', 'string', 'min' => 6],
35
    ];
36
  }
37
38
  public function attributeLabels() {
39
    return [
40
      'password' => 'Password'
41
    ];
42
  }
43
44
  /**
45
   * saves user's profile info.
46
   *
47
   * @return User|null the saved model or null if saving fails
48
   */
49
  public function deleteAccount()
50
  {
51
    if ($this->validate() && $this->user->validatePassword($this->password)) {
0 ignored issues
show
Bug introduced by
The method validatePassword() does not exist on common\interfaces\UserInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to common\interfaces\UserInterface. ( Ignorable by Annotation )

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

51
    if ($this->validate() && $this->user->/** @scrutinizer ignore-call */ validatePassword($this->password)) {
Loading history...
52
      $this->user->sendDeleteNotificationEmail();
0 ignored issues
show
Bug introduced by
The method sendDeleteNotificationEmail() does not exist on common\interfaces\UserInterface. It seems like you code against a sub-type of common\interfaces\UserInterface such as common\models\User. ( Ignorable by Annotation )

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

52
      $this->user->/** @scrutinizer ignore-call */ 
53
                   sendDeleteNotificationEmail();
Loading history...
53
      $this->user->delete();
54
      return true;
0 ignored issues
show
Bug Best Practice introduced by
The expression return true returns the type true which is incompatible with the documented return type common\models\User|null.
Loading history...
55
    }
56
57
    return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type common\models\User|null.
Loading history...
58
  }
59
}
60