Passed
Push — master ( d5aa5c...daa8b9 )
by Robbie
07:27 queued 05:32
created

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