Passed
Pull Request — master (#105)
by Robbie
07:26
created

Result::getContext()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php declare(strict_types=1);
2
3
namespace SilverStripe\MFA\State;
4
5
use SilverStripe\Core\Injector\Injectable;
6
7
/**
8
 * An immutable result object often detailing the result of a registration or validation completed by the
9
 * respective handlers
10
 */
11
class Result
12
{
13
    use Injectable;
14
15
    /**
16
     * Indicates this result was successful
17
     *
18
     * @var bool
19
     */
20
    protected $success;
21
22
    /**
23
     * An message describing the result
24
     *
25
     * @var string
26
     */
27
    protected $message = '';
28
29
    /**
30
     * Context provided by the handler returning this result
31
     *
32
     * @var array
33
     */
34
    protected $context = [];
35
36
    /**
37
     * @param bool $success
38
     * @param string $message
39
     * @param array $context
40
     */
41
    public function __construct(bool $success = true, string $message = '', array $context = [])
42
    {
43
        $this->success = $success;
44
        $this->message = $message;
45
        $this->context = $context;
46
    }
47
48
    /**
49
     * @return bool
50
     */
51
    public function isSuccessful(): bool
52
    {
53
        return $this->success;
54
    }
55
56
    /**
57
     * @return string
58
     */
59
    public function getMessage(): string
60
    {
61
        return $this->message;
62
    }
63
64
    /**
65
     * @return array
66
     */
67
    public function getContext(): array
68
    {
69
        return $this->context;
70
    }
71
72
    /**
73
     * @param bool $success
74
     * @return Result
75
     */
76
    public function setSuccessful(bool $success): Result
77
    {
78
        return new static($success, $this->getMessage(), $this->getContext());
79
    }
80
81
    /**
82
     * @param string $message
83
     * @return Result
84
     */
85
    public function setMessage(string $message): Result
86
    {
87
        return new static($this->isSuccessful(), $message, $this->getContext());
88
    }
89
90
    /**
91
     * @param array $context
92
     * @return Result
93
     */
94
    public function setContext(array $context): Result
95
    {
96
        return new static($this->isSuccessful(), $this->getMessage(), $context);
97
    }
98
}
99