From b496ca87805c40fd2e005bffa1af7fb912926e39 Mon Sep 17 00:00:00 2001 From: Camilo Sperberg Date: Tue, 2 Jan 2018 23:38:46 +0100 Subject: [PATCH] Minor opcode cache optimizations --- src/Abstracts/TelegramMethods.php | 6 +++--- src/Abstracts/TelegramTypes.php | 4 ++-- src/InternalFunctionality/PostOptionsConstructor.php | 6 +++--- src/InternalFunctionality/TelegramDocument.php | 2 +- src/Telegram/Types/Custom/InputFile.php | 2 +- src/Telegram/Types/Custom/ResultBoolean.php | 3 +-- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/Abstracts/TelegramMethods.php b/src/Abstracts/TelegramMethods.php index 3d3ae58..f9a06b7 100644 --- a/src/Abstracts/TelegramMethods.php +++ b/src/Abstracts/TelegramMethods.php @@ -121,7 +121,7 @@ final protected function mandatoryUserOrInlineMessageId(array &$return): array * @param TelegramTypes $replyMarkup * @return TelegramTypes */ - final private function formatReplyMarkup(TelegramTypes $replyMarkup): TelegramTypes + private function formatReplyMarkup(TelegramTypes $replyMarkup): TelegramTypes { if ($replyMarkup instanceof Markup) { $replyMarkup->inline_keyboard = $this->getArrayFromKeyboard($replyMarkup->inline_keyboard); @@ -132,7 +132,7 @@ final private function formatReplyMarkup(TelegramTypes $replyMarkup): TelegramTy return $replyMarkup; } - final private function getArrayFromKeyboard(array $keyboardArray): array + private function getArrayFromKeyboard(array $keyboardArray): array { $finalCleanArray = []; @@ -161,7 +161,7 @@ final private function getArrayFromKeyboard(array $keyboardArray): array * @param TelegramTypes $markupItem * @return array */ - final private function exportReplyMarkupItem(TelegramTypes $markupItem): array + private function exportReplyMarkupItem(TelegramTypes $markupItem): array { $finalArray = []; $cleanObject = new $markupItem; diff --git a/src/Abstracts/TelegramTypes.php b/src/Abstracts/TelegramTypes.php index 5ca1206..3b580af 100644 --- a/src/Abstracts/TelegramTypes.php +++ b/src/Abstracts/TelegramTypes.php @@ -37,7 +37,7 @@ final protected function populateObject(array $data = []): TelegramTypes { foreach ($data as $key => $value) { $candidateKey = null; - if (is_array($value)) { + if (\is_array($value)) { $this->logger->debug('Array detected, mapping subobjects for key', ['key' => $key]); $candidateKey = $this->mapSubObjects($key, $value); } @@ -76,7 +76,7 @@ protected function mapSubObjects(string $key, array $data): TelegramTypes $key, 'https://github.com/unreal4u/telegram-api/issues' ), [ - 'object' => get_class($this), + 'object' => \get_class($this), 'data' => $data, ]); } diff --git a/src/InternalFunctionality/PostOptionsConstructor.php b/src/InternalFunctionality/PostOptionsConstructor.php index b3c702e..ad2c457 100644 --- a/src/InternalFunctionality/PostOptionsConstructor.php +++ b/src/InternalFunctionality/PostOptionsConstructor.php @@ -63,7 +63,7 @@ public function constructOptions(TelegramMethods $method): array return [ 'headers' => [ 'Content-Type' => 'application/x-www-form-urlencoded', - 'Content-Length' => strlen($body), + 'Content-Length' => \strlen($body), 'User-Agent' => 'PHP7+ Bot API', ], 'body' => $body @@ -84,7 +84,7 @@ private function checkIsMultipart(TelegramMethods $method): array $return = []; foreach ($method as $key => $value) { - if (is_object($value) && $value instanceof InputFile) { + if (\is_object($value) && $value instanceof InputFile) { $this->logger->debug('About to send a file, so changing request to use multi-part instead'); // If we are about to send a file, we must use the multipart/form-data way $this->formType = 'multipart/form-data'; @@ -131,7 +131,7 @@ public function constructMultipartOptions(array $data, string $fileKeyName, $str $array = [ 'headers' => [ 'Content-Type' => 'multipart/form-data; boundary="' . $builder->getBoundary() . '"', - 'Content-Length' => strlen($body) + 'Content-Length' => \strlen($body) ], 'body' => $body ]; diff --git a/src/InternalFunctionality/TelegramDocument.php b/src/InternalFunctionality/TelegramDocument.php index 407126c..dbba399 100644 --- a/src/InternalFunctionality/TelegramDocument.php +++ b/src/InternalFunctionality/TelegramDocument.php @@ -41,7 +41,7 @@ public function __construct(TelegramResponse $response) // Same with file length $this->file_size = !empty($headers['Content-Length']) ? $headers['Content-Length'] - : strlen($response->getRawData()); + : \strlen($response->getRawData()); $this->contents = $response->getRawData(); } diff --git a/src/Telegram/Types/Custom/InputFile.php b/src/Telegram/Types/Custom/InputFile.php index aacbd83..8e6e448 100644 --- a/src/Telegram/Types/Custom/InputFile.php +++ b/src/Telegram/Types/Custom/InputFile.php @@ -41,7 +41,7 @@ public function __construct(string $path) private function setStream(): InputFile { if (is_readable($this->path)) { - $this->stream = fopen($this->path, 'r'); + $this->stream = fopen($this->path, 'rb'); } else { throw new FileNotReadable(sprintf('Can not read local file "%s", please check', $this->path)); } diff --git a/src/Telegram/Types/Custom/ResultBoolean.php b/src/Telegram/Types/Custom/ResultBoolean.php index 1603749..411a806 100644 --- a/src/Telegram/Types/Custom/ResultBoolean.php +++ b/src/Telegram/Types/Custom/ResultBoolean.php @@ -26,8 +26,7 @@ public function __toString() { if ($this->data === true) { return '1'; - } else { - return '0'; } + return '0'; } }