Passed
Push — master ( b82988...313288 )
by Gabriel
13:03
created

processValidationPasswordNew()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 7
c 1
b 0
f 1
dl 0
loc 9
rs 10
cc 4
nc 3
nop 0
1
<?php
2
3
namespace ByTIC\Hello\Modules\AbstractModule\Forms\Users;
4
5
/**
6
 * Trait ChangePasswordFormTrait
7
 * @package ByTIC\Hello\Modules\AbstractModule\Forms\Users
8
 *
9
 * @method getModel
10
 */
11
trait ChangePasswordFormTrait
12
{
13
    public function init()
14
    {
15
        parent::init();
16
        $this->removeClass('form-horizontal');
0 ignored issues
show
Bug introduced by
It seems like removeClass() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

16
        $this->/** @scrutinizer ignore-call */ 
17
               removeClass('form-horizontal');
Loading history...
17
        $this->addClass('user-recover');
0 ignored issues
show
Bug introduced by
It seems like addClass() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

17
        $this->/** @scrutinizer ignore-call */ 
18
               addClass('user-recover');
Loading history...
18
19
        $this->initPasswordOld();
20
        $this->initPasswordNew();
21
        $this->initPasswordRepeat();
22
23
        $this->addButton('save', translator()->trans('submit'));
0 ignored issues
show
Bug introduced by
It seems like addButton() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

23
        $this->/** @scrutinizer ignore-call */ 
24
               addButton('save', translator()->trans('submit'));
Loading history...
24
    }
25
26
    protected function initPasswordOld()
27
    {
28
        $this->addPassword('password_old', translator()->trans('password_old'), true);
0 ignored issues
show
Bug introduced by
It seems like addPassword() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

28
        $this->/** @scrutinizer ignore-call */ 
29
               addPassword('password_old', translator()->trans('password_old'), true);
Loading history...
29
    }
30
31
    protected function initPasswordNew()
32
    {
33
        $this->addPassword('password_new', translator()->trans('password_new'), true);
34
    }
35
36
    protected function initPasswordRepeat()
37
    {
38
        $this->addPassword('password_repeat', translator()->trans('password_repeat'), true);
39
    }
40
41
    public function processValidation()
42
    {
43
        parent::processValidation();
44
45
        $this->processValidationPasswordOld();
46
        $this->processValidationPasswordNew();
47
    }
48
49
    public function processValidationPasswordOld()
50
    {
51
        $passwordOld = $this->getElement('password_old');
0 ignored issues
show
Bug introduced by
It seems like getElement() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

51
        /** @scrutinizer ignore-call */ 
52
        $passwordOld = $this->getElement('password_old');
Loading history...
52
        if ($passwordOld->isError()) {
53
            return;
54
        }
55
56
        $hashCheck = $this->getModel()->checkSaltedPassword($passwordOld->getValue());
57
        if ($hashCheck) {
58
            $passwordOld->addError($this->getModelMessage('password_old.bad'));
0 ignored issues
show
Bug introduced by
The method getModelMessage() does not exist on ByTIC\Hello\Modules\Abst...ChangePasswordFormTrait. Did you maybe mean getModel()? ( Ignorable by Annotation )

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

58
            $passwordOld->addError($this->/** @scrutinizer ignore-call */ getModelMessage('password_old.bad'));

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...
59
        }
60
    }
61
62
    public function processValidationPasswordNew()
63
    {
64
        $password = $this->getElement('password_new');
65
        $password_repeat = $this->getElement('password_repeat');
66
        if (!$password->isError() && !$password_repeat->isError()) {
67
            if ($password->getValue() == $password_repeat->getValue()) {
68
                $this->changePassword = true;
0 ignored issues
show
Bug Best Practice introduced by
The property changePassword does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
69
            } else {
70
                $password->addError($this->getModelMessage('password.match'));
71
            }
72
        }
73
    }
74
75
    public function process()
76
    {
77
        $this->getModel()->new_password = $this->getElement('password_new')->getValue();
78
        $this->getModel()->hashPassword();
79
        $this->getModel()->update();
80
81
        return true;
82
    }
83
84
    protected function getDataFromModel()
85
    {
86
        parent::getDataFromModel();
87
        $this->_addModelFormMessage('no-password_old', 'password_old.empty')
0 ignored issues
show
Bug introduced by
It seems like _addModelFormMessage() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

87
        $this->/** @scrutinizer ignore-call */ 
88
               _addModelFormMessage('no-password_old', 'password_old.empty')
Loading history...
88
            ->_addModelFormMessage('no-password_new', 'password_new.empty')
89
            ->_addModelFormMessage('no-password_repeat', 'password_repeat.empty');
90
    }
91
}
92