Skip to content

Commit b1cc1f0

Browse files
committed
Update docblock comments for Request methods.
Clean out useless code from ServerResponse. Fix ServerResponseTest.
1 parent be54377 commit b1cc1f0

File tree

3 files changed

+197
-111
lines changed

3 files changed

+197
-111
lines changed

src/Entities/ServerResponse.php

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
/**
1212
* Class ServerResponse
1313
*
14+
* @link https://core.telegram.org/bots/api#making-requests
15+
*
1416
* @method bool getOk() If the request was successful
1517
* @method mixed getResult() The result of the query
1618
* @method int getErrorCode() Error code of the unsuccessful request
1719
* @method string getDescription() Human-readable description of the result / unsuccessful request
1820
*
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
2022
*/
2123
class ServerResponse extends Entity
2224
{
@@ -30,37 +32,19 @@ class ServerResponse extends Entity
3032
*/
3133
public function __construct(array $data, $bot_name)
3234
{
33-
// Make sure we don't double-save the raw_data.
35+
// Make sure we don't double-save the raw_data
3436
unset($data['raw_data']);
3537
$data['raw_data'] = $data;
3638

3739
$is_ok = isset($data['ok']) ? (bool)$data['ok'] : false;
3840
$result = isset($data['result']) ? $data['result'] : null;
3941

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);
5145
} 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);
6047
}
61-
} else {
62-
//webHook not set
63-
$data['ok'] = false;
6448
}
6549

6650
parent::__construct($data, $bot_name);
@@ -69,13 +53,15 @@ public function __construct(array $data, $bot_name)
6953
/**
7054
* Check if array is associative
7155
*
56+
* @link https://stackoverflow.com/a/4254008
57+
*
7258
* @param array $array
7359
*
7460
* @return bool
7561
*/
7662
protected function isAssoc(array $array)
7763
{
78-
return (bool)count(array_filter(array_keys($array), 'is_string'));
64+
return count(array_filter(array_keys($array), 'is_string')) > 0;
7965
}
8066

8167
/**

0 commit comments

Comments
 (0)