1 | <?php |
||
17 | class GecharlResponse |
||
18 | { |
||
19 | private $message; |
||
20 | |||
21 | /** |
||
22 | * @var bool |
||
23 | */ |
||
24 | private $hasError; |
||
25 | |||
26 | /** |
||
27 | * @var int |
||
28 | */ |
||
29 | private $code; |
||
30 | |||
31 | /** |
||
32 | * Response Body from |
||
33 | * @var object|null $body |
||
34 | */ |
||
35 | private $body; |
||
36 | |||
37 | const STATUS_MESSAGE = [ |
||
38 | "200" => '200 OK', |
||
39 | "201" => '201 Created', |
||
40 | "203" => '203 Non-Authoritative Information', |
||
41 | "204" => '204 No Content', |
||
42 | "301" => '301 Moved Permanently', |
||
43 | "307" => '307 Temporary Redirect', |
||
44 | "308" => '308 Permanent Redirect', |
||
45 | "400" => '400 Bad Request', |
||
46 | "401" => '401 Unauthorized', |
||
47 | "402" => '402 Payment Required', |
||
48 | "403" => '403 Forbidden', |
||
49 | "404" => '404 Not Found', |
||
50 | "408" => '408 Request Timeout', |
||
51 | "413" => '413 Payload Too Large', |
||
52 | "414" => '414 URI Too Long', |
||
53 | "422" => '422 Unprocessable Entity', |
||
54 | "500" => '500 Internal Server Error', |
||
55 | "502" => '502 Bad Gateway', |
||
56 | "503" => '503 Service Unavailable', |
||
57 | "504" => '504 Gateway Timeout', |
||
58 | "505" => '505 HTTP Version Not Supported', |
||
59 | ]; |
||
60 | |||
61 | |||
62 | /** |
||
63 | * GecharlResponse constructor. |
||
64 | * @param int $code |
||
65 | * @param object|array|null $responseBody |
||
66 | * @throws GecharlErrorException |
||
67 | */ |
||
68 | public function __construct(int $code, $responseBody = null) |
||
79 | |||
80 | /** |
||
81 | * Determine if this ise a success response object |
||
82 | * @return bool |
||
83 | */ |
||
84 | public function successful(): bool |
||
88 | |||
89 | /** |
||
90 | * @return string |
||
91 | */ |
||
92 | public function getMessage(): string |
||
96 | |||
97 | /** |
||
98 | * @return object|array|null |
||
99 | */ |
||
100 | public function getBody() |
||
104 | |||
105 | public function __toString() |
||
109 | |||
110 | } |
||
111 |
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
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. 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.