Passed
Push — master ( 0d72e8...44be60 )
by Gabor
04:58
created

Result   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 62
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 4 1
A setCode() 0 10 2
A getCode() 0 4 1
A getMessage() 0 4 1
1
<?php
2
/**
3
 * WebHemi.
4
 *
5
 * PHP version 7.1
6
 *
7
 * @copyright 2012 - 2017 Gixx-web (http://www.gixx-web.com)
8
 * @license   https://opensource.org/licenses/MIT The MIT License (MIT)
9
 *
10
 * @link      http://www.gixx-web.com
11
 */
12
declare(strict_types = 1);
13
14
namespace WebHemi\Auth\Result;
15
16
use WebHemi\Auth\ResultInterface;
17
18
/**
19
 * Class Result.
20
 */
21
class Result implements ResultInterface
22
{
23
    /** @var int */
24
    private $code;
25
    /** @var array */
26
    private $messages = [
27
        self::FAILURE => 'Authentication failed.',
28
        self::FAILURE_IDENTITY_NOT_FOUND => 'User is not found.',
29
        self::FAILURE_IDENTITY_DISABLED => 'The given user is disabled.',
30
        self::FAILURE_IDENTITY_INACTIVE => 'The given user is in inactive state.',
31
        self::FAILURE_CREDENTIAL_INVALID => 'The provided credentials are not valid.',
32
        self::FAILURE_OTHER => 'Authentication failed because of unknown reason.',
33
        self::SUCCESS => 'Authenticated.',
34
    ];
35
36
    /**
37
     * Checks the authentication result.
38
     *
39
     * @return bool
40
     */
41 2
    public function isValid() : bool
42
    {
43 2
        return $this->code == 1;
44
    }
45
46
    /**
47
     * Sets the result code.
48
     *
49
     * @param int $code
50
     * @return ResultInterface
51
     */
52 3
    public function setCode(int $code) : ResultInterface
53
    {
54 3
        if (!isset($this->messages[$code])) {
55 2
            $code = self::FAILURE_OTHER;
56
        }
57
58 3
        $this->code = $code;
59
60 3
        return $this;
61
    }
62
63
    /**
64
     * Gets the result code.
65
     *
66
     * @return int
67
     */
68 3
    public function getCode() : int
69
    {
70 3
        return $this->code;
71
    }
72
73
    /**
74
     * Gets the result message.
75
     *
76
     * @return string
77
     */
78 1
    public function getMessage() : string
79
    {
80 1
        return $this->messages[$this->code];
81
    }
82
}
83