LoginFormTrait::processValidation()   A
last analyzed

Complexity

Conditions 6
Paths 9

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
eloc 12
c 0
b 0
f 0
dl 0
loc 18
ccs 0
cts 12
cp 0
rs 9.2222
cc 6
nc 9
nop 0
crap 42
1
<?php
2
3
namespace ByTIC\Hello\Modules\AbstractModule\Forms\Users;
4
5
/**
6
 * Trait LoginFormTrait
7
 * @package ByTIC\Hello\Modules\AbstractModule\Forms\Users
8
 */
9
trait LoginFormTrait
10
{
11
    public function init()
12
    {
13
        parent::init();
14
15
        $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

15
        $this->/** @scrutinizer ignore-call */ 
16
               removeClass('form-horizontal');
Loading history...
16
        $this->addClass('box', 'user-login');
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

16
        $this->/** @scrutinizer ignore-call */ 
17
               addClass('box', 'user-login');
Loading history...
17
18
        $this->addInput('email', translator()->trans('email'), true)
0 ignored issues
show
Bug introduced by
It seems like addInput() 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

18
        $this->/** @scrutinizer ignore-call */ 
19
               addInput('email', translator()->trans('email'), true)
Loading history...
19
            ->addPassword('password', translator()->trans('password'), true);
20
21
        $this->addButton('save', translator()->trans('signin'));
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

21
        $this->/** @scrutinizer ignore-call */ 
22
               addButton('save', translator()->trans('signin'));
Loading history...
22
        $this->getButton('save')->addClass('pull-right');
0 ignored issues
show
Bug introduced by
It seems like getButton() 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

22
        $this->/** @scrutinizer ignore-call */ 
23
               getButton('save')->addClass('pull-right');
Loading history...
23
    }
24
25
    public function processValidation()
26
    {
27
        parent::processValidation();
28
29
        $email = $this->getElement('email');
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

29
        /** @scrutinizer ignore-call */ 
30
        $email = $this->getElement('email');
Loading history...
30
        if (!$email->isError()) {
31
            $value = $email->getValue();
32
            if (!valid_email($value)) {
0 ignored issues
show
Bug introduced by
The function valid_email was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

32
            if (!/** @scrutinizer ignore-call */ valid_email($value)) {
Loading history...
33
                $email->addError($this->getModelMessage('email.bad'));
0 ignored issues
show
Bug introduced by
It seems like getModelMessage() 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

33
                $email->addError($this->/** @scrutinizer ignore-call */ getModelMessage('email.bad'));
Loading history...
34
            }
35
        }
36
37
        $password = $this->getElement('password');
38
        if (!$email->isError() && !$password->isError()) {
39
            $model = $this->getModel();
0 ignored issues
show
Bug introduced by
It seems like getModel() 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

39
            /** @scrutinizer ignore-call */ 
40
            $model = $this->getModel();
Loading history...
40
            $request = ['email' => $email->getValue(), 'password' => $password->getValue()];
41
            if (!$model->authenticate($request)) {
42
                $email->addError($this->getModelMessage('login.error'));
43
            }
44
        }
45
    }
46
47
    public function process()
48
    {
49
        return true;
50
    }
51
52
    /**
53
     * @inheritdoc
54
     */
55
    protected function getDataFromModel()
56
    {
57
        parent::getDataFromModel();
58
        $this->_addModelFormMessage('no-email', 'email.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

58
        $this->/** @scrutinizer ignore-call */ 
59
               _addModelFormMessage('no-email', 'email.empty')
Loading history...
59
            ->_addModelFormMessage('no-password', 'password.empty');
60
    }
61
}
62