Completed
Pull Request — master (#7)
by
unknown
01:37
created
src/Smoqadam/Keyboard/Inline.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
   /**
14 14
   * Create new row.
15 15
   *
16
-  * @return object
16
+  * @return Inline
17 17
   */
18 18
   public function addRow(){
19 19
     $this->current_row++;
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
   * @param string $switch_inline_query Optional. If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot‘s username and the specified inline query in the input field. Can be empty, in which case just the bot’s username will be inserted.
31 31
   * @param string $switch_inline_query_current_chat Optional. If set, pressing the button will insert the bot‘s username and the specified inline query in the current chat's input field. Can be empty, in which case only the bot’s username will be inserted.
32 32
   * @param string $callback_game Optional. Description of the game that will be launched when the user presses the button. NOTE: This type of button must always be the first button in the first row.
33
-  * @return object
33
+  * @return Inline
34 34
   */
35 35
   public function addButton(string $text, string $url = '', string $callback_data = '', string $switch_inline_query = '', string $switch_inline_query_current_chat = '', string $callback_game = ''){
36 36
     $btn['text'] = $text;
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
   *
16 16
   * @return object
17 17
   */
18
-  public function addRow(){
18
+  public function addRow() {
19 19
     $this->current_row++;
20 20
     
21 21
     return $this;
@@ -32,17 +32,17 @@  discard block
 block discarded – undo
32 32
   * @param string $callback_game Optional. Description of the game that will be launched when the user presses the button. NOTE: This type of button must always be the first button in the first row.
33 33
   * @return object
34 34
   */
35
-  public function addButton(string $text, string $url = '', string $callback_data = '', string $switch_inline_query = '', string $switch_inline_query_current_chat = '', string $callback_game = ''){
35
+  public function addButton(string $text, string $url = '', string $callback_data = '', string $switch_inline_query = '', string $switch_inline_query_current_chat = '', string $callback_game = '') {
36 36
     $btn['text'] = $text;
37
-    if($url != '')
37
+    if ($url != '')
38 38
       $btn['url'] = $url;
39
-    elseif($callback_data != '')
39
+    elseif ($callback_data != '')
40 40
       $btn['callback_data'] = $callback_data;
41
-    elseif($switch_inline_query != '')
41
+    elseif ($switch_inline_query != '')
42 42
      $btn['switch_inline_query'] = $switch_inline_query;
43
-    elseif($switch_inline_query_current_chat != '')
43
+    elseif ($switch_inline_query_current_chat != '')
44 44
       $btn['switch_inline_query_current_chat'] = $switch_inline_query_current_chat;
45
-    elseif($callback_game != '')
45
+    elseif ($callback_game != '')
46 46
       $btn['callback_game'] = $callback_game;
47 47
     else
48 48
       $btn['callback_data'] = $text;
Please login to merge, or discard this patch.
src/Smoqadam/Telegram.php 2 patches
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 
220 220
     /**
221 221
      * execute telegram api commands
222
-     * @param $command
222
+     * @param string $command
223 223
      * @param array $params
224 224
      */
225 225
     private function exec($command, $params = []) {
@@ -254,9 +254,9 @@  discard block
 block discarded – undo
254 254
 
255 255
     /**
256 256
      * get the $url content with CURL
257
-     * @param $url
257
+     * @param string $url
258 258
      * @param $params
259
-     * @return mixed
259
+     * @return string
260 260
      */
261 261
     private function curl_get_contents($url, $params) {
262 262
         $ch = curl_init();
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
     }
299 299
 
300 300
     /**
301
-     * @param null $offset
301
+     * @param integer $offset
302 302
      * @param int $limit
303 303
      * @param int $timeout
304 304
      */
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
 
454 454
     /**
455 455
      * send chat action : Telegram::ACTION_TYPING , ...
456
-     * @param $action
456
+     * @param string $action
457 457
      * @param null $chat_id
458 458
      */
459 459
     public function sendChatAction($action, $chat_id = null) {
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -105,11 +105,11 @@  discard block
 block discarded – undo
105 105
     }
106 106
 
107 107
 
108
-    public function PDO(){
108
+    public function PDO() {
109 109
 
110
-        $servername ='YOUR_SERVER_NAME';
110
+        $servername = 'YOUR_SERVER_NAME';
111 111
         $username = 'YOUR_USERNAME';
112
-        $password ='YOUR_PASSWORD';
112
+        $password = 'YOUR_PASSWORD';
113 113
         $dbname = 'YOUR_DATABASE_NAME';
114 114
         try {
115 115
             $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password, [PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"]);
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 
118 118
             return $conn;
119 119
         }
120
-        catch(PDOException $e)
120
+        catch (PDOException $e)
121 121
         {
122 122
             return $e->getMessage();
123 123
         }
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
         $result = $this->getUpdates();
143 143
         while (true) {
144 144
             $update_id = isset($result->update_id) ? $result->update_id : 1;
145
-            $result = $this->getUpdates($update_id + 1);
145
+            $result = $this->getUpdates($update_id+1);
146 146
 
147 147
             $this->processPayload($result);
148 148
 
@@ -166,13 +166,13 @@  discard block
 block discarded – undo
166 166
                 $this->result = $result;
167 167
 
168 168
                 // now i select the right triggers for payload received by Telegram
169
-                if( isset($this->result->message->text) ) {
169
+                if (isset($this->result->message->text)) {
170 170
                     $payload = $this->result->message->text;
171 171
                     $triggers = $this->commands;
172
-                } elseif ( isset($this->result->inline_query) ) {
172
+                } elseif (isset($this->result->inline_query)) {
173 173
                     $payload = $this->result->inline_query->query;
174 174
                     $triggers = $this->inlines;
175
-                } else {
175
+                }else {
176 176
                     throw new \Exception("Error Processing Request", 1);
177 177
                 }
178 178
 
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
                     //find args pattern
188 188
                     $args = $this->getArgs($pattern, $payload);
189 189
 
190
-                    $pattern = '/^' . $pattern . '/i';
190
+                    $pattern = '/^'.$pattern.'/i';
191 191
 
192 192
                     preg_match($pattern, $payload, $matches);
193 193
 
@@ -196,11 +196,11 @@  discard block
 block discarded – undo
196 196
                         return call_user_func($func, $args);
197 197
                     }
198 198
                 }
199
-            } catch (\Exception $e) {
199
+            }catch (\Exception $e) {
200 200
                 error_log($e->getMessage());
201
-                echo "\r\n Exception :: " . $e->getMessage();
201
+                echo "\r\n Exception :: ".$e->getMessage();
202 202
             }
203
-        } else {
203
+        }else {
204 204
             echo "\r\nNo new message\r\n";
205 205
         }
206 206
     }
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
             $tmp_args_pattern = str_replace(['<<', '>>'], ['(', ')'], $pattern);
222 222
 
223 223
             //if args set
224
-            if (preg_match('/' . $tmp_args_pattern . '/i', $payload, $matches)) {
224
+            if (preg_match('/'.$tmp_args_pattern.'/i', $payload, $matches)) {
225 225
                 //remove first element
226 226
                 array_shift($matches);
227 227
                 if (isset($matches[0])) {
@@ -244,16 +244,16 @@  discard block
 block discarded – undo
244 244
     private function exec($command, $params = []) {
245 245
         if (in_array($command, $this->available_commands)) {
246 246
             // convert json to array then get the last messages info
247
-            $output = json_decode($this->curl_get_contents($this->api . '/' . $command, $params), true);
247
+            $output = json_decode($this->curl_get_contents($this->api.'/'.$command, $params), true);
248 248
 
249 249
             return $this->convertToObject($output);
250
-        } else {
250
+        }else {
251 251
             echo 'command not found';
252 252
         }
253 253
     }
254 254
 
255
-    private function convertToObject($jsonObject , $webhook = false) {
256
-        if( ! $webhook) {
255
+    private function convertToObject($jsonObject, $webhook = false) {
256
+        if (!$webhook) {
257 257
             if ($jsonObject['ok']) {
258 258
                 //error_log(print_r($jsonObject, true));
259 259
 
@@ -261,12 +261,12 @@  discard block
 block discarded – undo
261 261
                 $output = end($jsonObject);
262 262
 
263 263
                 $result = is_array($output) ? end($output) : $output;
264
-                if ( ! empty($result)) {
264
+                if (!empty($result)) {
265 265
                     // convert to object
266 266
                     return json_decode(json_encode($result));
267 267
                 }
268 268
             }
269
-        } else {
269
+        }else {
270 270
             return json_decode(json_encode($jsonObject));
271 271
         }
272 272
     }
@@ -304,14 +304,14 @@  discard block
 block discarded – undo
304 304
             if ($chat_id)
305 305
                 return $chat_id;
306 306
 
307
-            if( isset($this->result->message) ) {
307
+            if (isset($this->result->message)) {
308 308
                 return $this->result->message->chat->id;
309
-            } elseif ( isset($this->result->inline_query) ) {
309
+            } elseif (isset($this->result->inline_query)) {
310 310
                 return $this->result->inline_query->from->id;
311
-            } else {
311
+            }else {
312 312
                 throw new \Exception("Error Processing Request", 1);
313 313
             }
314
-        } catch (\Exception $e) {
314
+        }catch (\Exception $e) {
315 315
             error_log($e->getMessage());
316 316
         }
317 317
     }
Please login to merge, or discard this patch.
src/Smoqadam/InlineQuery/Result/Article.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
   public function __construct($title, $content) {
14 14
     $this->title = $title;
15 15
     $this->input_message_content = $content;
16
-    $this->id = '' . rand();
16
+    $this->id = ''.rand();
17 17
   }
18 18
 
19 19
 }
Please login to merge, or discard this patch.
src/Smoqadam/Keyboard/Standard.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
   *
25 25
   * @return object Standard
26 26
   */
27
-  public function addRow(){
27
+  public function addRow() {
28 28
     $this->current_row++;
29 29
     
30 30
     return $this;
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
   * @param boolean $request_location Optional. If True, the user's current location will be sent when the button is pressed. Available in private chats only
39 39
   * @return object
40 40
   */
41
-  public function addButton(string $text, boolean $request_contact = null, boolean $request_location = null){
41
+  public function addButton(string $text, boolean $request_contact = null, boolean $request_location = null) {
42 42
     $this->keyboard[$this->current_row][] = [
43 43
       'text' => $text,
44 44
       'request_contact' => ($request_contact != null) ? $request_contact : false,
Please login to merge, or discard this patch.
src/Smoqadam/Keyboard/Remove.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
     *
14 14
     * @param boolean $selective Optional. Use this parameter if you want to remove the keyboard for specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message.
15 15
     */
16
-    public function __construct($selective = false){
17
-        $this->selective        = $selective;
16
+    public function __construct($selective = false) {
17
+        $this->selective = $selective;
18 18
     }
19 19
 }
20 20
\ No newline at end of file
Please login to merge, or discard this patch.
index.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -7,14 +7,14 @@
 block discarded – undo
7 7
 
8 8
 $tg = new Telegram('API_TOKEN');
9 9
 
10
-$tg->cmd('name:<<[a-zA-Z]{0,}>>', function ($args) use ($tg){
10
+$tg->cmd('name:<<[a-zA-Z]{0,}>>', function($args) use ($tg){
11 11
 	
12
-		$tg->sendMessage("my username is @".$args , $tg->getChatId());
12
+		$tg->sendMessage("my username is @".$args, $tg->getChatId());
13 13
 });
14 14
 
15 15
 
16
-$tg->cmd('<<:any>>',function ($arg) use ($tg){
17
-	$tg->sendMessage("You Message is : " . $arg, $tg->getChatId()); 
16
+$tg->cmd('<<:any>>', function($arg) use ($tg){
17
+	$tg->sendMessage("You Message is : ".$arg, $tg->getChatId()); 
18 18
 });
19 19
 
20 20
 $tg->run();
Please login to merge, or discard this patch.