From a3b1759b5bf7528893908f11f82c1135829e437f Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 29 Nov 2016 00:48:19 +0000 Subject: [PATCH] Apply fixes from StyleCI --- src/danog/MadelineProto/MTProto.php | 4 ++-- .../MadelineProto/MTProtoTools/AckHandler.php | 3 +++ .../MTProtoTools/ResponseHandler.php | 4 +++- src/danog/MadelineProto/TL/TL.php | 24 ++++++++++++++----- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/danog/MadelineProto/MTProto.php b/src/danog/MadelineProto/MTProto.php index fe54697f..814f1c0e 100644 --- a/src/danog/MadelineProto/MTProto.php +++ b/src/danog/MadelineProto/MTProto.php @@ -40,7 +40,7 @@ class MTProto extends MTProtoTools $device_model = php_uname('s'); } catch (Exception $e) { } - + // Detect system version $system_version = phpversion(); @@ -48,7 +48,7 @@ class MTProto extends MTProtoTools $system_version = php_uname('r'); } catch (Exception $e) { } - + // Set default settings $default_settings = [ 'authorization' => [ // Authorization settings diff --git a/src/danog/MadelineProto/MTProtoTools/AckHandler.php b/src/danog/MadelineProto/MTProtoTools/AckHandler.php index fbd9b4bd..19b6dbd6 100644 --- a/src/danog/MadelineProto/MTProtoTools/AckHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/AckHandler.php @@ -22,8 +22,10 @@ class AckHandler extends \danog\MadelineProto\PrimeModule // The server acknowledges that it received my message if (!isset($this->datacenter->outgoing_messages[$message_id])) { \danog\MadelineProto\Logger::log("Couldn't find message id ".$message_id.' in the array of outgoing messages. Maybe try to increase its size?'); + return false; } + return $this->datacenter->outgoing_messages[$message_id]['ack'] = true; } @@ -38,6 +40,7 @@ class AckHandler extends \danog\MadelineProto\PrimeModule } $this->object_call('msgs_ack', ['msg_ids' => [$message_id]]); + return $this->datacenter->incoming_messages[$message_id]['ack'] = true; } } diff --git a/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php b/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php index fd8c3997..2e98ec1e 100644 --- a/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php @@ -130,7 +130,9 @@ class ResponseHandler extends MsgIdHandler break; } } - public function try_store_response($request, $response, $type, $force = true) { + + public function try_store_response($request, $response, $type, $force = true) + { if ($force) { return $this->datacenter->outgoing_messages[$request]['response'] = $response; } diff --git a/src/danog/MadelineProto/TL/TL.php b/src/danog/MadelineProto/TL/TL.php index dac97352..52ff61aa 100644 --- a/src/danog/MadelineProto/TL/TL.php +++ b/src/danog/MadelineProto/TL/TL.php @@ -54,15 +54,19 @@ class TL extends \danog\MadelineProto\Tools return $arguments; } - public function serialize_bool($bool) { + public function serialize_bool($bool) + { return \danog\PHP\Struct::pack('constructors->find_by_predicate('bool'.($bool ? 'True' : 'False'))['id']); } - public function deserialize_bool($data) { + + public function deserialize_bool($data) + { $id = \danog\PHP\Struct::unpack('constructors->find_by_id($id); if ($tl_elem === false) { throw new Exception('Could not extract boolean'); } + return $tl_elem['predicate'] === 'boolTrue'; } @@ -83,7 +87,7 @@ class TL extends \danog\MadelineProto\Tools return \danog\PHP\Struct::pack('posmod(-$l, 4)); } + return $concat; case 'Bool': if (!is_bool($object)) { @@ -125,6 +130,7 @@ var_dump($object); foreach ($object as $current_object) { $concat .= $this->serialize_object(['type' => $type['subtype']], $current_object); } + return $concat; } @@ -144,7 +150,7 @@ var_dump($object); throw new Exception('Could not extract type: '.$object); } - if ($bare = ($type['type'] != '' && $type['type'][0] == "%")) { + if ($bare = ($type['type'] != '' && $type['type'][0] == '%')) { $type['type'] = substr($type['type'], 1); } @@ -156,17 +162,20 @@ var_dump($object); if (!$bare) { $concat .= \danog\PHP\Struct::pack('serialize_params($constructorData, $object); + return $concat.$this->serialize_params($constructorData, $object); } + public function serialize_method($method, $arguments) { $tl = $this->methods->find_by_method($method); if ($tl === false) { throw new Exception('Could not extract type: '.$method); } + return \danog\PHP\Struct::pack('serialize_params($tl, $arguments); } + public function serialize_params($tl, $arguments) { $serialized = ''; @@ -267,6 +276,7 @@ var_dump($object); if (!is_string($x)) { throw new Exception("deserialize: generated value isn't a string"); } + return $x; case 'true': return true; @@ -291,13 +301,14 @@ var_dump($object); for ($i = 0; $i < $count; $i++) { $result[] = $this->deserialize($bytes_io, ['type' => $type['subtype']]); } + return $result; } if ($type['type'] != '' && $type['type'][0] == '%') { $checkType = substr($type['type'], 1); $constructorData = $this->constructors->find_by_type($checkType); if ($constructorData === false) { - throw new Exception('Constructor not found for type: '. $checkType); + throw new Exception('Constructor not found for type: '.$checkType); } } else { $constructorData = $this->constructors->find_by_predicate($type['type']); @@ -337,6 +348,7 @@ var_dump($object); if (isset($x['flags'])) { // I don't think we need this anymore unset($x['flags']); } + return $x; }