Passed
Push — master ( ed3a21...c78a04 )
by Guido
06:24
created

Examples   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
eloc 11
dl 0
loc 26
c 3
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A login() 0 18 5
1
<?php
2
3
namespace Gvera\Validations;
4
5
use Exception;
6
use Gvera\Exceptions\EmptyValidationStrategiesException;
7
use Gvera\Exceptions\InvalidValidationMethodException;
8
use Gvera\Helpers\validation\IsNotEmptyValidationStrategy;
9
use Gvera\Helpers\validation\ValidationService;
10
11
class Examples extends ControllerValidationAbstract
12
{
13
14
    /**
15
     * @return bool
16
     * @throws EmptyValidationStrategiesException
17
     * @throws Exception
18
     */
19
    public function login(): bool
20
    {
21
        if (!isset($this->fields['username']) || !isset($this->fields['password'])) {
22
            throw new Exception('something went wrong with the validation');
23
        }
24
25
        $username = $this->fields['username'];
26
        $strategies = [new IsNotEmptyValidationStrategy()];
27
        if (!$this->validate($username, $strategies)) {
28
            return false;
29
        }
30
31
        $password = $this->fields['password'];
32
        if (!$this->validate($password, $strategies)) {
33
            return false;
34
        }
35
36
        return true;
37
    }
38
}
39