From 1514af1fed3ae3abcfa2d2928b8a3f900b65b709 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sat, 27 May 2017 21:22:04 +0000 Subject: [PATCH] Apply fixes from StyleCI --- src/danog/MadelineProto/API.php | 2 +- src/danog/MadelineProto/Connection.php | 1 + src/danog/MadelineProto/MTProto.php | 34 ++++++++----------- .../MadelineProto/MTProtoTools/AckHandler.php | 1 + .../MTProtoTools/AuthKeyHandler.php | 4 ++- .../MTProtoTools/CallHandler.php | 4 ++- .../MadelineProto/MTProtoTools/Files.php | 2 +- .../MTProtoTools/MsgIdHandler.php | 2 ++ src/danog/MadelineProto/TL/TLConstructor.php | 15 ++++++-- src/danog/MadelineProto/TL/TLMethod.php | 9 +++-- 10 files changed, 46 insertions(+), 28 deletions(-) diff --git a/src/danog/MadelineProto/API.php b/src/danog/MadelineProto/API.php index 3d1d5b8fe..93d17ba0e 100644 --- a/src/danog/MadelineProto/API.php +++ b/src/danog/MadelineProto/API.php @@ -48,7 +48,7 @@ class API extends APIFactory } restore_error_handler(); } - + public function __sleep() { return ['API', 'storage']; diff --git a/src/danog/MadelineProto/Connection.php b/src/danog/MadelineProto/Connection.php index b99db25cd..4e0c531bb 100644 --- a/src/danog/MadelineProto/Connection.php +++ b/src/danog/MadelineProto/Connection.php @@ -215,6 +215,7 @@ class Connection extends \Volatile $this->close_and_reopen(); throw new Exception("WARNING: Wrong length was read (should've read ".($length).', read '.strlen($packet).')!'); } + return $packet; case 'udp': throw new Exception("Connection: This protocol wasn't implemented yet."); diff --git a/src/danog/MadelineProto/MTProto.php b/src/danog/MadelineProto/MTProto.php index 6e2ebd629..992fed175 100644 --- a/src/danog/MadelineProto/MTProto.php +++ b/src/danog/MadelineProto/MTProto.php @@ -49,18 +49,18 @@ class MTProto extends \Volatile const WAITING_PASSWORD = 2; const LOGGED_IN = 3; const DISALLOWED_METHODS = [ - 'auth.logOut' => 'You cannot use this method directly, use the logout method instead (see https://daniil.it/MadelineProto for more info)', + 'auth.logOut' => 'You cannot use this method directly, use the logout method instead (see https://daniil.it/MadelineProto for more info)', 'auth.importBotAuthorization' => 'You cannot use this method directly, use the bot_login method instead (see https://daniil.it/MadelineProto for more info)', - 'auth.sendCode' => 'You cannot use this method directly, use the phone_login method instead (see https://daniil.it/MadelineProto for more info)', - 'auth.signIn' => 'You cannot use this method directly, use the complete_phone_login method instead (see https://daniil.it/MadelineProto for more info)', - 'auth.signUp' => 'You cannot use this method directly, use the complete_signup method instead (see https://daniil.it/MadelineProto for more info)', - 'users.getFullUser' => 'You cannot use this method directly, use the get_pwr_chat, get_info, get_full_info methods instead (see https://daniil.it/MadelineProto for more info)', - 'channels.getFullChannel' => 'You cannot use this method directly, use the get_pwr_chat, get_info, get_full_info methods instead (see https://daniil.it/MadelineProto for more info)', - 'messages.getFullChat' => 'You cannot use this method directly, use the get_pwr_chat, get_info, get_full_info methods instead (see https://daniil.it/MadelineProto for more info)', - 'channels.getParticipants' => 'You cannot use this method directly, use the get_pwr_chat, get_info, get_full_info methods instead (see https://daniil.it/MadelineProto for more info)', - 'contacts.resolveUsername' => 'You cannot use this method directly, use the resolve_username, get_pwr_chat, get_info, get_full_info methods instead (see https://daniil.it/MadelineProto for more info)', + 'auth.sendCode' => 'You cannot use this method directly, use the phone_login method instead (see https://daniil.it/MadelineProto for more info)', + 'auth.signIn' => 'You cannot use this method directly, use the complete_phone_login method instead (see https://daniil.it/MadelineProto for more info)', + 'auth.signUp' => 'You cannot use this method directly, use the complete_signup method instead (see https://daniil.it/MadelineProto for more info)', + 'users.getFullUser' => 'You cannot use this method directly, use the get_pwr_chat, get_info, get_full_info methods instead (see https://daniil.it/MadelineProto for more info)', + 'channels.getFullChannel' => 'You cannot use this method directly, use the get_pwr_chat, get_info, get_full_info methods instead (see https://daniil.it/MadelineProto for more info)', + 'messages.getFullChat' => 'You cannot use this method directly, use the get_pwr_chat, get_info, get_full_info methods instead (see https://daniil.it/MadelineProto for more info)', + 'channels.getParticipants' => 'You cannot use this method directly, use the get_pwr_chat, get_info, get_full_info methods instead (see https://daniil.it/MadelineProto for more info)', + 'contacts.resolveUsername' => 'You cannot use this method directly, use the resolve_username, get_pwr_chat, get_info, get_full_info methods instead (see https://daniil.it/MadelineProto for more info)', - 'messages.acceptEncryption' => 'You cannot use this method directly, see https://daniil.it/MadelineProto for more info on handling secret chats', + 'messages.acceptEncryption' => 'You cannot use this method directly, see https://daniil.it/MadelineProto for more info on handling secret chats', 'messages.discardEncryption' => 'You cannot use this method directly, see https://daniil.it/MadelineProto for more info on handling secret chats', 'messages.requestEncryption' => 'You cannot use this method directly, see https://daniil.it/MadelineProto for more info on handling secret chats', /* @@ -70,13 +70,13 @@ class MTProto extends \Volatile 'phone.discardCall' => 'You cannot use this method directly, see https://daniil.it/MadelineProto for more info on handling calls', */ 'updates.getChannelDifference' => 'You cannot use this method directly, see https://daniil.it/MadelineProto for more info on handling updates', - 'updates.getDifference' => 'You cannot use this method directly, see https://daniil.it/MadelineProto for more info on handling updates', - 'updates.getState' => 'You cannot use this method directly, see https://daniil.it/MadelineProto for more info on handling updates', + 'updates.getDifference' => 'You cannot use this method directly, see https://daniil.it/MadelineProto for more info on handling updates', + 'updates.getState' => 'You cannot use this method directly, see https://daniil.it/MadelineProto for more info on handling updates', - 'upload.getCdnFile' => 'You cannot use this method directly, use the upload, download_to_stream, download_to_file, download_to_dir methods instead; see https://daniil.it/MadelineProto for more info', + 'upload.getCdnFile' => 'You cannot use this method directly, use the upload, download_to_stream, download_to_file, download_to_dir methods instead; see https://daniil.it/MadelineProto for more info', 'upload.reuploadCdnFile' => 'You cannot use this method directly, use the upload, download_to_stream, download_to_file, download_to_dir methods instead; see https://daniil.it/MadelineProto for more info', - 'upload.getFile' => 'You cannot use this method directly, use the upload, download_to_stream, download_to_file, download_to_dir methods instead; see https://daniil.it/MadelineProto for more info', - 'upload.saveFilePart' => 'You cannot use this method directly, use the upload, download_to_stream, download_to_file, download_to_dir methods instead; see https://daniil.it/MadelineProto for more info', + 'upload.getFile' => 'You cannot use this method directly, use the upload, download_to_stream, download_to_file, download_to_dir methods instead; see https://daniil.it/MadelineProto for more info', + 'upload.saveFilePart' => 'You cannot use this method directly, use the upload, download_to_stream, download_to_file, download_to_dir methods instead; see https://daniil.it/MadelineProto for more info', 'upload.saveBigFilePart' => 'You cannot use this method directly, use the upload, download_to_stream, download_to_file, download_to_dir methods instead; see https://daniil.it/MadelineProto for more info', ]; @@ -142,14 +142,11 @@ class MTProto extends \Volatile private $twoe2047; private $twoe2048; - - private $ipv6 = false; public $should_serialize = false; public $run_workers = false; public $threads = false; - public function ___construct($settings = []) { \danog\MadelineProto\Logger::class_exists(); @@ -229,7 +226,6 @@ class MTProto extends \Volatile // Detect ipv6 $this->ipv6 = (bool) strlen(@file_get_contents('http://ipv6.test-ipv6.com/', false, stream_context_create(['http' => ['timeout' => 1]]))) > 0; - $keys = array_keys((array) get_object_vars($this)); if (count($keys) !== count(array_unique($keys))) { throw new Bug74586Exception(); diff --git a/src/danog/MadelineProto/MTProtoTools/AckHandler.php b/src/danog/MadelineProto/MTProtoTools/AckHandler.php index 208ae8a9b..7eed27147 100644 --- a/src/danog/MadelineProto/MTProtoTools/AckHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/AckHandler.php @@ -42,6 +42,7 @@ trait AckHandler } $this->object_call('msgs_ack', ['msg_ids' => [$message_id]], ['datacenter' => $datacenter]); + return $this->datacenter->sockets[$datacenter]->incoming_messages[$message_id]['ack'] = true; } } diff --git a/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php b/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php index a61a9ce39..e4b6a994f 100644 --- a/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php @@ -416,7 +416,9 @@ trait AuthKeyHandler } catch (\danog\MadelineProto\Exception $e) { \danog\MadelineProto\Logger::log(['An exception occurred while generating the authorization key: '.$e->getMessage().' in '.basename($e->getFile(), '.php').' on line '.$e->getLine().'. Retrying...'], \danog\MadelineProto\Logger::WARNING); } catch (\danog\MadelineProto\RPCErrorException $e) { - if ($e->rpc === 'RPC_CALL_FAIL') throw $e; + if ($e->rpc === 'RPC_CALL_FAIL') { + throw $e; + } \danog\MadelineProto\Logger::log(['An RPCErrorException occurred while generating the authorization key: '.$e->getMessage().' Retrying (try number '.$retry_id_total.')...'], \danog\MadelineProto\Logger::WARNING); } finally { $this->datacenter->sockets[$datacenter]->new_outgoing = []; diff --git a/src/danog/MadelineProto/MTProtoTools/CallHandler.php b/src/danog/MadelineProto/MTProtoTools/CallHandler.php index 1a3050e36..fa4ff7278 100644 --- a/src/danog/MadelineProto/MTProtoTools/CallHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/CallHandler.php @@ -31,7 +31,9 @@ trait CallHandler if (basename(debug_backtrace(0)[0]['file']) === 'APIFactory.php' && isset(self::DISALLOWED_METHODS[$method])) { if ($method === 'channels.getParticipants' && $args['filter'] === ['_' => 'channelParticipantsRecent']) { \danog\MadelineProto\Logger::log([self::DISALLOWED_METHODS[$method]], \danog\MadelineProto\Logger::FATAL_ERROR); - } else throw new \danog\MadelineProto\Exception(self::DISALLOWED_METHODS[$method], 0, null, 'MadelineProto', 1); + } else { + throw new \danog\MadelineProto\Exception(self::DISALLOWED_METHODS[$method], 0, null, 'MadelineProto', 1); + } } if (isset($args['message']) && is_string($args['message']) && mb_strlen($args['message']) > 4096) { $message_chunks = $this->split_to_chunks($args['message']); diff --git a/src/danog/MadelineProto/MTProtoTools/Files.php b/src/danog/MadelineProto/MTProtoTools/Files.php index 2ca44404a..d3eacef23 100644 --- a/src/danog/MadelineProto/MTProtoTools/Files.php +++ b/src/danog/MadelineProto/MTProtoTools/Files.php @@ -27,7 +27,7 @@ trait Files } $datacenter = is_null($datacenter) ? $this->datacenter->curdc : $datacenter; $file_size = filesize($file); - if ($file_size > 512*1024*3000) { + if ($file_size > 512 * 1024 * 3000) { throw new \danog\MadelineProto\Exception('Given file is too big!'); } if ($cb === null) { diff --git a/src/danog/MadelineProto/MTProtoTools/MsgIdHandler.php b/src/danog/MadelineProto/MTProtoTools/MsgIdHandler.php index 2cd1a1f97..2faa7880d 100644 --- a/src/danog/MadelineProto/MTProtoTools/MsgIdHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/MsgIdHandler.php @@ -82,6 +82,7 @@ trait MsgIdHandler $message_id = $key->add($this->four); } $this->check_message_id($message_id, ['outgoing' => true, 'datacenter' => $datacenter, 'container' => false]); + return strrev($message_id->toBytes()); } @@ -91,6 +92,7 @@ trait MsgIdHandler if (isset($this->datacenter->sockets[$datacenter]->{'max_'.$incoming.'_id'}) && is_object($this->datacenter->sockets[$datacenter]->{'max_'.$incoming.'_id'})) { return $this->datacenter->sockets[$datacenter]->{'max_'.$incoming.'_id'}; } + return $this->zero; /* $keys = array_keys((array) $this->datacenter->sockets[$datacenter]->{$incoming.'_messages'}); diff --git a/src/danog/MadelineProto/TL/TLConstructor.php b/src/danog/MadelineProto/TL/TLConstructor.php index 3eacaeae1..0a8f7f949 100644 --- a/src/danog/MadelineProto/TL/TLConstructor.php +++ b/src/danog/MadelineProto/TL/TLConstructor.php @@ -47,6 +47,7 @@ class TLConstructor extends \Volatile public function find_by_type($type) { $id = array_search($type, (array) $this->type, true); + return ($id === false) ? false : [ 'id' => substr($id, 1), 'predicate' => $this->predicate[$id], @@ -59,13 +60,18 @@ class TLConstructor extends \Volatile { if ($layer !== '' && !isset($this->id[$predicate.$layer])) { foreach ($this->layers as $newlayer) { - if (isset($this->id[$predicate.$newlayer]) || $newlayer > $layer) break; + if (isset($this->id[$predicate.$newlayer]) || $newlayer > $layer) { + break; + } $nlayer = $newlayer; } $layer = $nlayer; } - if (!isset($this->id[$predicate.$layer])) return false; + if (!isset($this->id[$predicate.$layer])) { + return false; + } $id = $this->id[$predicate.$layer]; + return [ 'id' => substr($id, 1), 'predicate' => $this->predicate[$id], @@ -77,7 +83,10 @@ class TLConstructor extends \Volatile public function find_by_id($oid) { $id = 'a'.$oid; - if (!isset($this->predicate[$id])) return false; + if (!isset($this->predicate[$id])) { + return false; + } + return [ 'id' => $oid, 'predicate' => $this->predicate[$id], diff --git a/src/danog/MadelineProto/TL/TLMethod.php b/src/danog/MadelineProto/TL/TLMethod.php index 941642575..97dbfe159 100644 --- a/src/danog/MadelineProto/TL/TLMethod.php +++ b/src/danog/MadelineProto/TL/TLMethod.php @@ -45,7 +45,9 @@ class TLMethod extends \Volatile public function find_by_method($method) { - if (!isset($this->id[$method])) return false; + if (!isset($this->id[$method])) { + return false; + } $id = $this->id[$method]; return [ @@ -59,7 +61,10 @@ class TLMethod extends \Volatile public function find_by_id($oid) { $id = 'a'.$oid; - if (!isset($this->method[$id])) return false; + if (!isset($this->method[$id])) { + return false; + } + return [ 'id' => $oid, 'method' => $this->method[$id],