Apply fixes from StyleCI

This commit is contained in:
Daniil Gentili 2016-12-23 20:07:19 +00:00 committed by StyleCI Bot
parent 884232aec3
commit f0f8ae56bf
3 changed files with 14 additions and 9 deletions

View File

@ -54,7 +54,8 @@ trait PeerHandler
} }
} }
public function get_peer($id, $recursive = true) { public function get_peer($id, $recursive = true)
{
if (is_numeric($id)) { if (is_numeric($id)) {
if (isset($this->chats[$id])) { if (isset($this->chats[$id])) {
return $this->chats[$id]; return $this->chats[$id];
@ -71,16 +72,19 @@ trait PeerHandler
} }
if ($recursive) { if ($recursive) {
$this->resolve_username($id); $this->resolve_username($id);
return $this->get_peer($id, false); return $this->get_peer($id, false);
} }
throw new \danog\MadelineProto\Exception("Couldn't find peer by provided username ".$id); throw new \danog\MadelineProto\Exception("Couldn't find peer by provided username ".$id);
} }
public function get_input_peer($id) { public function get_input_peer($id)
{
return $this->constructor2inputpeer($this->get_peer($id)); return $this->constructor2inputpeer($this->get_peer($id));
} }
public function constructor2inputpeer($peer) { public function constructor2inputpeer($peer)
{
switch ($peer['_']) { switch ($peer['_']) {
case 'user': case 'user':
return $peer['self'] ? ['_' => 'inputPeerSelf'] : ['_' => 'inputPeerUser', 'user_id' => $peer['id'], 'access_hash' => $peer['access_hash']]; return $peer['self'] ? ['_' => 'inputPeerSelf'] : ['_' => 'inputPeerUser', 'user_id' => $peer['id'], 'access_hash' => $peer['access_hash']];
@ -94,14 +98,15 @@ trait PeerHandler
} }
} }
public function resolve_username($username) { public function resolve_username($username)
{
$res = $this->method_call('contacts.resolveUsername', ['username' => str_replace('@', '', $username)]); $res = $this->method_call('contacts.resolveUsername', ['username' => str_replace('@', '', $username)]);
if ($res['_'] == 'contacts.resolvedPeer') { if ($res['_'] == 'contacts.resolvedPeer') {
$this->add_users($res['users']); $this->add_users($res['users']);
$this->add_chats($res['chats']); $this->add_chats($res['chats']);
return $res; return $res;
} }
throw new \danog\MadelineProto\Exception('resolve_username returned an unexpected constructor: '.var_export($username, true)); throw new \danog\MadelineProto\Exception('resolve_username returned an unexpected constructor: '.var_export($username, true));
} }
} }