11
11
/**
12
12
* Class ServerResponse
13
13
*
14
+ * @link https://core.telegram.org/bots/api#making-requests
15
+ *
14
16
* @method bool getOk() If the request was successful
15
17
* @method mixed getResult() The result of the query
16
18
* @method int getErrorCode() Error code of the unsuccessful request
17
19
* @method string getDescription() Human-readable description of the result / unsuccessful request
18
20
*
19
- * @method_todo ResponseParameters getParameters() Field which can help to automatically handle the error
21
+ * @todo method ResponseParameters getParameters() Field which can help to automatically handle the error
20
22
*/
21
23
class ServerResponse extends Entity
22
24
{
@@ -30,37 +32,19 @@ class ServerResponse extends Entity
30
32
*/
31
33
public function __construct (array $ data , $ bot_name )
32
34
{
33
- // Make sure we don't double-save the raw_data.
35
+ // Make sure we don't double-save the raw_data
34
36
unset($ data ['raw_data ' ]);
35
37
$ data ['raw_data ' ] = $ data ;
36
38
37
39
$ is_ok = isset ($ data ['ok ' ]) ? (bool )$ data ['ok ' ] : false ;
38
40
$ result = isset ($ data ['result ' ]) ? $ data ['result ' ] : null ;
39
41
40
- if ($ is_ok && $ result !== null ) {
41
- $ data ['ok ' ] = true ;
42
-
43
- if (is_array ($ result )) {
44
- if ($ this ->isAssoc ($ result )) {
45
- $ data ['result ' ] = $ this ->createResultObject ($ result , $ bot_name );
46
- } else {
47
- $ data ['result ' ] = $ this ->createResultObjects ($ result , $ bot_name );
48
- }
49
-
50
- unset($ data ['error_code ' ], $ data ['description ' ]);
42
+ if ($ is_ok && is_array ($ result )) {
43
+ if ($ this ->isAssoc ($ result )) {
44
+ $ data ['result ' ] = $ this ->createResultObject ($ result , $ bot_name );
51
45
} else {
52
- $ data ['result ' ] = $ result ;
53
- if ($ result === true ) {
54
- //Response from setWebhook set
55
- unset($ data ['error_code ' ]);
56
- } elseif (!is_numeric ($ result )) { //Not response from getChatMembersCount
57
- $ data ['ok ' ] = false ;
58
- unset($ data ['result ' ]);
59
- }
46
+ $ data ['result ' ] = $ this ->createResultObjects ($ result , $ bot_name );
60
47
}
61
- } else {
62
- //webHook not set
63
- $ data ['ok ' ] = false ;
64
48
}
65
49
66
50
parent ::__construct ($ data , $ bot_name );
@@ -69,13 +53,15 @@ public function __construct(array $data, $bot_name)
69
53
/**
70
54
* Check if array is associative
71
55
*
56
+ * @link https://stackoverflow.com/a/4254008
57
+ *
72
58
* @param array $array
73
59
*
74
60
* @return bool
75
61
*/
76
62
protected function isAssoc (array $ array )
77
63
{
78
- return ( bool ) count (array_filter (array_keys ($ array ), 'is_string ' ));
64
+ return count (array_filter (array_keys ($ array ), 'is_string ' )) > 0 ;
79
65
}
80
66
81
67
/**
0 commit comments