|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created By: Henry Ejemuta |
|
4
|
|
|
* PC: Enrico Systems |
|
5
|
|
|
* Project: laravel-gecharl |
|
6
|
|
|
* Company: Stimolive Technologies Limited |
|
7
|
|
|
* Class Name: GecharlResponse.php |
|
8
|
|
|
* Date Created: 9/27/20 |
|
9
|
|
|
* Time Created: 6:00 PM |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace HenryEjemuta\LaravelGecharl\Classes; |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
use HenryEjemuta\LaravelGecharl\Exceptions\GecharlErrorException; |
|
16
|
|
|
|
|
17
|
|
|
class GecharlResponse |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var bool |
|
22
|
|
|
*/ |
|
23
|
|
|
private $hasError; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var string $title |
|
27
|
|
|
*/ |
|
28
|
|
|
private $title; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Response Message as determined by status code |
|
32
|
|
|
* @var string $message |
|
33
|
|
|
*/ |
|
34
|
|
|
private $message; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Response Body from |
|
38
|
|
|
* @var object|null $body |
|
39
|
|
|
*/ |
|
40
|
|
|
private $body; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var array $additionalStatusDetails |
|
44
|
|
|
*/ |
|
45
|
|
|
private $additionalStatus; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* GecharlResponse constructor. |
|
49
|
|
|
* @param string $code |
|
50
|
|
|
* @param object|array|null $responseBody |
|
51
|
|
|
* @throws GecharlErrorException |
|
52
|
|
|
*/ |
|
53
|
|
|
public function __construct(string $code, $responseBody = null) |
|
54
|
|
|
{ |
|
55
|
|
|
$this->body = $responseBody; |
|
|
|
|
|
|
56
|
|
|
$this->additionalStatus = []; |
|
57
|
|
|
$this->title = "Empty Response"; |
|
58
|
|
|
$this->message = "Empty Response from VTPass server"; |
|
59
|
|
|
$this->hasError = false; |
|
60
|
|
|
|
|
61
|
|
|
if (isset(GecharlResponse::RESPONSE["$code"])) { |
|
62
|
|
|
$msg = GecharlResponse::RESPONSE["$code"]; |
|
63
|
|
|
$this->title = $msg['title']; |
|
64
|
|
|
$this->message = $msg['message']; |
|
65
|
|
|
$this->hasError = $msg['error']; |
|
66
|
|
|
if ("$code" === "000" && isset($responseBody->status)) { |
|
67
|
|
|
if (isset(GecharlResponse::TRANSACTION_PROCESSED_STATUS["{$responseBody->status}"])) { |
|
68
|
|
|
$this->additionalStatus = GecharlResponse::TRANSACTION_PROCESSED_STATUS["{$responseBody->status}"]; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
if ($this->hasError) |
|
74
|
|
|
throw new GecharlErrorException($this->message, "$code"); |
|
75
|
|
|
|
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Determine if this ise a success response object |
|
80
|
|
|
* @return bool |
|
81
|
|
|
*/ |
|
82
|
|
|
public function successful(): bool |
|
83
|
|
|
{ |
|
84
|
|
|
return !($this->hasError); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @return string |
|
89
|
|
|
*/ |
|
90
|
|
|
public function getTitle(): string |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->title; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @return string |
|
97
|
|
|
*/ |
|
98
|
|
|
public function getMessage(): string |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->message; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @return object|array|null |
|
105
|
|
|
*/ |
|
106
|
|
|
public function getBody() |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->body; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function __toString() |
|
112
|
|
|
{ |
|
113
|
|
|
return json_encode($this->body); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
} |
|
117
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.