Result::isSuccessful()   A
last analyzed

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