@@ -93,7 +93,7 @@ |
||
| 93 | 93 | |
| 94 | 94 | /** |
| 95 | 95 | * \brief Add various commands at once. |
| 96 | - * @param ...BasicCommand $commands The commands to add. |
|
| 96 | + * @param BasicCommand[] $commands The commands to add. |
|
| 97 | 97 | */ |
| 98 | 98 | public function addCommands(BasicCommand ...$commands) |
| 99 | 99 | { |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | */ |
| 100 | 100 | public function addCommands(BasicCommand ...$commands) |
| 101 | 101 | { |
| 102 | - foreach ($commands as $command) { |
|
| 102 | + foreach ($commands as $command) { |
|
| 103 | 103 | $this->addCommand($command); |
| 104 | 104 | } |
| 105 | 105 | } |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | public function addMessageCommand(string $command, callable $script) |
| 113 | 113 | { |
| 114 | - $this->_commands[] = new MessageCommand($command, $script); |
|
| 114 | + $this->_commands[] = new MessageCommand($command, $script); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | public function addCallbackCommand(string $data, callable $script) |
| 123 | 123 | { |
| 124 | - $this->_commands[] = new CallbackCommand($data, $script); |
|
| 124 | + $this->_commands[] = new CallbackCommand($data, $script); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** @} */ |
@@ -52,7 +52,7 @@ |
||
| 52 | 52 | |
| 53 | 53 | foreach ($this->_commands as $index => $array) { |
| 54 | 54 | // Sort them by priority |
| 55 | - uasort($this->_commands[$index], function ($a, $b) { |
|
| 55 | + uasort($this->_commands[$index], function($a, $b) { |
|
| 56 | 56 | return $a::$priority <=> $b::$priority; |
| 57 | 57 | }); |
| 58 | 58 | } |
@@ -4,16 +4,16 @@ |
||
| 4 | 4 | class DonateBot extends PhpBotFramework\Bot { |
| 5 | 5 | // Receive pre-checkout query. |
| 6 | 6 | protected function processPreCheckoutQuery($pre_checkout_query) { |
| 7 | - $money_donated = $pre_checkout_query['total_amount'] / 100; |
|
| 8 | - $currency = $pre_checkout_query['currency']; |
|
| 7 | + $money_donated = $pre_checkout_query['total_amount'] / 100; |
|
| 8 | + $currency = $pre_checkout_query['currency']; |
|
| 9 | 9 | |
| 10 | - echo "** Checkout for $currency $money_donated\n"; |
|
| 11 | - $this->answerPreCheckoutQuery(true); |
|
| 10 | + echo "** Checkout for $currency $money_donated\n"; |
|
| 11 | + $this->answerPreCheckoutQuery(true); |
|
| 12 | 12 | |
| 13 | - // If a user donated more than 2 euros or dollars or whatever currency. |
|
| 14 | - if ($money_donated > 2) { |
|
| 15 | - $this->sendMessage('Thanks for your donation'); |
|
| 16 | - } |
|
| 13 | + // If a user donated more than 2 euros or dollars or whatever currency. |
|
| 14 | + if ($money_donated > 2) { |
|
| 15 | + $this->sendMessage('Thanks for your donation'); |
|
| 16 | + } |
|
| 17 | 17 | } |
| 18 | 18 | } |
| 19 | 19 | |
@@ -22,7 +22,7 @@ |
||
| 22 | 22 | $bot = new DonateBot('BOT_TOKEN'); |
| 23 | 23 | $bot->setPayment('PROVIDER_TOKEN', 'EUR'); |
| 24 | 24 | |
| 25 | -$bot->addMessageCommand('start', function ($bot, $message) { |
|
| 25 | +$bot->addMessageCommand('start', function($bot, $message) { |
|
| 26 | 26 | $bot->sendInvoice('Donation', 'Small donation', 'don1', array('Donation' => 2)); |
| 27 | 27 | $bot->sendInvoice('Donation', 'Medium donation', 'don2', array('Donation' => 5)); |
| 28 | 28 | $bot->sendInvoice('Donation', 'Large donation', 'don3', array('Donation' => 10)); |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | abstract protected function execRequest(string $url); |
| 30 | 30 | |
| 31 | 31 | /** @internal |
| 32 | - * \brief Store ID of the callback query received. */ |
|
| 32 | + * \brief Store ID of the callback query received. */ |
|
| 33 | 33 | protected $_callback_query_id; |
| 34 | 34 | |
| 35 | 35 | /** @internal |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | protected $_shipping_query_id; |
| 42 | 42 | |
| 43 | 43 | /** @internal |
| 44 | - * \brief Store ID of the inline query received. */ |
|
| 44 | + * \brief Store ID of the inline query received. */ |
|
| 45 | 45 | protected $_inline_query_id; |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -123,30 +123,30 @@ discard block |
||
| 123 | 123 | * @return string A JSON string representation of the shipping options. |
| 124 | 124 | */ |
| 125 | 125 | private function generateShippingOptions(array $shipping_options) { |
| 126 | - $response = []; |
|
| 127 | - $option_index = 1; |
|
| 126 | + $response = []; |
|
| 127 | + $option_index = 1; |
|
| 128 | 128 | |
| 129 | - foreach ($shipping_options as $option => $prices) { |
|
| 129 | + foreach ($shipping_options as $option => $prices) { |
|
| 130 | 130 | array_push($response, ['id' => strval($option_index), 'title' => $option, 'prices' => []]); |
| 131 | 131 | |
| 132 | 132 | // Register prices for the specific shipping option |
| 133 | 133 | foreach ($prices as $service => $price) { |
| 134 | - if ($price < 0) { |
|
| 134 | + if ($price < 0) { |
|
| 135 | 135 | throw new Exception('Invalid negative price passed to "answerShippingQuery"'); |
| 136 | - } |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | - $formatted_price = intval($price * 100); |
|
| 138 | + $formatted_price = intval($price * 100); |
|
| 139 | 139 | |
| 140 | - // Selects the most recent shipping option pushed into the array. |
|
| 141 | - array_push($response[$option_index - 1]['prices'], [ |
|
| 140 | + // Selects the most recent shipping option pushed into the array. |
|
| 141 | + array_push($response[$option_index - 1]['prices'], [ |
|
| 142 | 142 | 'label' => $service, 'amount' => $formatted_price |
| 143 | - ]); |
|
| 143 | + ]); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | $option_index++; |
| 147 | - } |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - return json_encode($response); |
|
| 149 | + return json_encode($response); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | /** |
@@ -42,7 +42,7 @@ |
||
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | 44 | * \brief Get data parameter if it is set. |
| 45 | - * @return string $data if set or empty string otherwise. |
|
| 45 | + * @return Message|null $data if set or empty string otherwise. |
|
| 46 | 46 | */ |
| 47 | 47 | public function getData() |
| 48 | 48 | { |
@@ -36,7 +36,7 @@ |
||
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | 38 | * \brief Get result's query. |
| 39 | - * @return string $query If set or <code>null</code> if empty. |
|
| 39 | + * @return Message|null $query If set or <code>null</code> if empty. |
|
| 40 | 40 | */ |
| 41 | 41 | public function getQuery() |
| 42 | 42 | { |
@@ -34,7 +34,7 @@ |
||
| 34 | 34 | |
| 35 | 35 | /** |
| 36 | 36 | * \brief Get text parameter if it is set. |
| 37 | - * @return string If set or <code>null</code> otherwise. |
|
| 37 | + * @return Message|null If set or <code>null</code> otherwise. |
|
| 38 | 38 | */ |
| 39 | 39 | public function getText() |
| 40 | 40 | { |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | */ |
| 128 | 128 | public function addResult(array $result) : int |
| 129 | 129 | { |
| 130 | - if (array_key_exists('type', $result) && ! in_array($result['type'], $this->accepted_type)) { |
|
| 130 | + if (array_key_exists('type', $result) && !in_array($result['type'], $this->accepted_type)) { |
|
| 131 | 131 | throw new BotException("Result has wrong or no type at all. Check that the result has a value of key 'type' that correspond to a type in the API Reference"); |
| 132 | 132 | } |
| 133 | 133 | |
@@ -171,8 +171,8 @@ discard block |
||
| 171 | 171 | 'disable_web_page_preview' => $disable_web_preview |
| 172 | 172 | ]); |
| 173 | 173 | |
| 174 | - if ( is_null($reply_markup) ) { |
|
| 175 | - unset( $this->results[ $this->id_result ]['reply_markup'] ); |
|
| 174 | + if (is_null($reply_markup)) { |
|
| 175 | + unset($this->results[$this->id_result]['reply_markup']); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | return $this->id_result++; |