From 59c9bc057280ca6ad702e43038e90392aa505d9a Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 18 May 2017 10:13:05 +0000 Subject: [PATCH] Apply fixes from StyleCI --- src/danog/MadelineProto/API.php | 19 +++++++++++++++---- src/danog/MadelineProto/MTProto.php | 1 + .../MTProtoTools/AuthKeyHandler.php | 1 - .../MTProtoTools/MessageHandler.php | 2 +- src/danog/MadelineProto/RSA.php | 7 ++++++- src/danog/MadelineProto/TL/TL.php | 5 ++++- src/danog/MadelineProto/TL/TLConstructor.php | 6 +++++- src/danog/MadelineProto/TL/TLMethod.php | 7 ++++++- src/danog/MadelineProto/TL/Types/Button.php | 7 ++++++- src/danog/MadelineProto/TL/Types/Bytes.php | 13 +++++++++++-- .../MadelineProto/Threads/SocketReader.php | 4 ++-- 11 files changed, 57 insertions(+), 15 deletions(-) diff --git a/src/danog/MadelineProto/API.php b/src/danog/MadelineProto/API.php index abd79b235..1c9415b54 100644 --- a/src/danog/MadelineProto/API.php +++ b/src/danog/MadelineProto/API.php @@ -55,14 +55,25 @@ class API extends APIFactory { return ['API']; } - public function &__get($name) { - if ($name === 'settings') return $this->API->settings; + + public function &__get($name) + { + if ($name === 'settings') { + return $this->API->settings; + } + return $this->{$name}; } - public function &__set($name, $value) { - if ($name === 'settings') return $this->API->__construct($value); + + public function &__set($name, $value) + { + if ($name === 'settings') { + return $this->API->__construct($value); + } + return $this->{$name} = $value; } + public function APIFactory() { foreach ($this->API->get_method_namespaces() as $namespace) { diff --git a/src/danog/MadelineProto/MTProto.php b/src/danog/MadelineProto/MTProto.php index b89d3c7dd..f56cc004c 100644 --- a/src/danog/MadelineProto/MTProto.php +++ b/src/danog/MadelineProto/MTProto.php @@ -154,6 +154,7 @@ class MTProto extends \Volatile $this->get_config([], ['datacenter' => $this->datacenter->curdc]); $this->v = $this->getV(); $this->should_serialize = true; + return $this->settings; } diff --git a/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php b/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php index 6e6f3b137..140564456 100644 --- a/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/AuthKeyHandler.php @@ -20,7 +20,6 @@ namespace danog\MadelineProto\MTProtoTools; */ trait AuthKeyHandler { - public function create_auth_key($expires_in, $datacenter) { for ($retry_id_total = 1; $retry_id_total <= $this->settings['max_tries']['authorization']; $retry_id_total++) { diff --git a/src/danog/MadelineProto/MTProtoTools/MessageHandler.php b/src/danog/MadelineProto/MTProtoTools/MessageHandler.php index 22c28a4ca..3f2aea6a0 100644 --- a/src/danog/MadelineProto/MTProtoTools/MessageHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/MessageHandler.php @@ -21,7 +21,6 @@ trait MessageHandler * Forming the message frame and sending message to server * :param message: byte string to send. */ - public function send_message($message_data, $content_related, $aargs = []) { if (!isset($aargs['message_id']) || $aargs['message_id'] === null) { @@ -120,6 +119,7 @@ trait MessageHandler $this->datacenter->sockets[$datacenter]->incoming_messages[$message_id]['response'] = -1; $this->datacenter->sockets[$datacenter]->new_incoming[$message_id] = $message_id; $this->last_recv = time(); + return true; } } diff --git a/src/danog/MadelineProto/RSA.php b/src/danog/MadelineProto/RSA.php index 7542aaf01..133ab3bf4 100644 --- a/src/danog/MadelineProto/RSA.php +++ b/src/danog/MadelineProto/RSA.php @@ -52,7 +52,12 @@ class RSA extends \Volatile return true; } - public function __sleep() { return ['e', 'n', 'fp']; } + + public function __sleep() + { + return ['e', 'n', 'fp']; + } + public function encrypt($data) { \danog\MadelineProto\Logger::log(['Encrypting with rsa key...'], Logger::VERBOSE); diff --git a/src/danog/MadelineProto/TL/TL.php b/src/danog/MadelineProto/TL/TL.php index c1a36243e..cad40bfa6 100644 --- a/src/danog/MadelineProto/TL/TL.php +++ b/src/danog/MadelineProto/TL/TL.php @@ -594,7 +594,9 @@ trait TL return $this->deserialize($stream, $constructorData); } - if ($constructorData['type'] === 'Bool') return $constructorData['predicate'] === 'boolTrue'; + if ($constructorData['type'] === 'Bool') { + return $constructorData['predicate'] === 'boolTrue'; + } $x = ['_' => $constructorData['predicate']]; foreach ($constructorData['params'] as $arg) { if ($arg['flag']) { @@ -654,6 +656,7 @@ trait TL } } } + return $x; } } diff --git a/src/danog/MadelineProto/TL/TLConstructor.php b/src/danog/MadelineProto/TL/TLConstructor.php index 1efb2d848..ff779cb47 100644 --- a/src/danog/MadelineProto/TL/TLConstructor.php +++ b/src/danog/MadelineProto/TL/TLConstructor.php @@ -24,7 +24,11 @@ class TLConstructor extends \Volatile public $params = []; public $layer = []; public $key = 0; - public function __sleep() { return ['id', 'predicate', 'type', 'params', 'layer', 'key']; } + + public function __sleep() + { + return ['id', 'predicate', 'type', 'params', 'layer', 'key']; + } public function add($json_dict, $scheme_type) { diff --git a/src/danog/MadelineProto/TL/TLMethod.php b/src/danog/MadelineProto/TL/TLMethod.php index b180a67a3..c76cf115f 100644 --- a/src/danog/MadelineProto/TL/TLMethod.php +++ b/src/danog/MadelineProto/TL/TLMethod.php @@ -23,7 +23,12 @@ class TLMethod extends \Volatile public $params = []; public $method_namespace = []; public $key = 0; - public function __sleep() { return ['id', 'method', 'type', 'params', 'method_namespace', 'key']; } + + public function __sleep() + { + return ['id', 'method', 'type', 'params', 'method_namespace', 'key']; + } + public function add($json_dict) { $this->id[$this->key] = $json_dict['id']; diff --git a/src/danog/MadelineProto/TL/Types/Button.php b/src/danog/MadelineProto/TL/Types/Button.php index 8fb5d784b..58da6292b 100644 --- a/src/danog/MadelineProto/TL/Types/Button.php +++ b/src/danog/MadelineProto/TL/Types/Button.php @@ -25,7 +25,12 @@ class Button extends \Volatile implements \JsonSerializable $this->info['id'] = $message['id']; $this->info['API'] = $API; } - public function __sleep() { return ['data', 'info']; } + + public function __sleep() + { + return ['data', 'info']; + } + public function click($donotwait = false) { switch ($this->data['_']) { diff --git a/src/danog/MadelineProto/TL/Types/Bytes.php b/src/danog/MadelineProto/TL/Types/Bytes.php index 49db0ff23..cf545c0c6 100644 --- a/src/danog/MadelineProto/TL/Types/Bytes.php +++ b/src/danog/MadelineProto/TL/Types/Bytes.php @@ -21,8 +21,17 @@ class Bytes extends \Volatile implements \JsonSerializable { $this->bytes = $bytes; } - public function __sleep() { return ['bytes']; } - public function __toString() { return $this->bytes; } + + public function __sleep() + { + return ['bytes']; + } + + public function __toString() + { + return $this->bytes; + } + public function jsonSerialize() { return utf8_encode($this->bytes); diff --git a/src/danog/MadelineProto/Threads/SocketReader.php b/src/danog/MadelineProto/Threads/SocketReader.php index 9f4be5f86..fb8dde509 100644 --- a/src/danog/MadelineProto/Threads/SocketReader.php +++ b/src/danog/MadelineProto/Threads/SocketReader.php @@ -49,11 +49,11 @@ class SocketReader extends \Threaded implements \Collectable while ($this->API->run_workers) { try { $this->API->datacenter->sockets[$this->current]->reading = true; -var_dumP('RECEIVING'); + var_dump('RECEIVING'); $error = $this->API->recv_message($this->current); var_dump('NOW HANDLE'); $handler_pool->submit(new SocketHandler($this->API, $this->current, $error)); - var_dump("SUBMITTED"); + var_dump('SUBMITTED'); $this->API->datacenter->sockets[$this->current]->reading = false; } catch (\danog\MadelineProto\NothingInTheSocketException $e) { \danog\MadelineProto\Logger::log(['Nothing in the socket for dc '.$this->current], \danog\MadelineProto\Logger::VERBOSE);