Result::getError()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types = 1);
4
5
/*
6
 * This file is part of the SmsGate package
7
 *
8
 * (c) SmsGate
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code
12
 */
13
14
namespace SmsGate;
15
16
/**
17
 * The value object for store result of sending SMS
18
 *
19
 * @author Vitaliy Zhuk <[email protected]>
20
 */
21
class Result
22
{
23
    /**
24
     * @var Phone
25
     */
26
    private $phone;
27
28
    /**
29
     * @var bool
30
     */
31
    private $status;
32
33
    /**
34
     * @var string
35
     */
36
    private $messageId;
37
38
    /**
39
     * @var Error
40
     */
41
    private $error;
42
43
    /**
44
     * Constructor.
45
     *
46
     * @param Phone  $phone
47
     * @param bool   $status
48
     * @param string $messageId
49
     * @param Error  $error
50
     */
51 7
    public function __construct(Phone $phone, bool $status, string $messageId = null, Error $error = null)
52
    {
53 7
        $this->phone = $phone;
54 7
        $this->status = $status;
55 7
        $this->messageId = $messageId;
56 7
        $this->error = $error;
57 7
    }
58
59
    /**
60
     * Create successfully result
61
     *
62
     * @param Phone  $phone
63
     * @param string $messageId
64
     *
65
     * @return Result
66
     */
67 6
    public static function successfully(Phone $phone, string $messageId = null): Result
68
    {
69 6
        return new self($phone, true, $messageId);
70
    }
71
72
    /**
73
     * Create failed result
74
     *
75
     * @param Phone  $phone
76
     * @param Error  $error
77
     * @param string $messageId
78
     *
79
     * @return Result
80
     */
81 4
    public static function failed(Phone $phone, Error $error, string $messageId = null): Result
82
    {
83 4
        return new self($phone, false, $messageId, $error);
84
    }
85
86
    /**
87
     * Is success send SMS?
88
     *
89
     * @return bool
90
     */
91 4
    public function isSuccessfully(): bool
92
    {
93 4
        return $this->status === true;
94
    }
95
96
    /**
97
     * Is failure send SMS?
98
     *
99
     * @return bool
100
     */
101 4
    public function isFailed(): bool
102
    {
103 4
        return $this->status === false;
104
    }
105
106
    /**
107
     * Get the phone
108
     *
109
     * @return Phone
110
     */
111 5
    public function getPhone(): Phone
112
    {
113 5
        return $this->phone;
114
    }
115
116
    /**
117
     * Get the identifier of message
118
     *
119
     * @return string
120
     */
121 3
    public function getMessageId(): ?string
122
    {
123 3
        return $this->messageId;
124
    }
125
126
    /**
127
     * Get the reason of error
128
     *
129
     * @return Error
130
     */
131 3
    public function getError(): ?Error
132
    {
133 3
        return $this->error;
134
    }
135
}
136