Examples::login()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 18
c 2
b 0
f 0
rs 9.6111
cc 5
nc 4
nop 0
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