Passed
Branch master (af4cfe)
by Chizhov
13:05
created
src/phpagi.php 3 patches
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -1433,39 +1433,39 @@  discard block
 block discarded – undo
1433 1433
               'k9999' => 'Z',
1434 1434
               'k99999' => '9'];
1435 1435
     $symbol = ['k0' => '=',
1436
-               'k1' => '<',
1437
-               'k11' => '(',
1438
-               'k111' => '[',
1439
-               'k1111' => '{',
1440
-               'k11111' => '1',
1441
-               'k2' => '@',
1442
-               'k22' => '$',
1443
-               'k222' => '&',
1444
-               'k2222' => '%',
1445
-               'k22222' => '2',
1446
-               'k3' => '>',
1447
-               'k33' => ')',
1448
-               'k333' => ']',
1449
-               'k3333' => '}',
1450
-               'k33333' => '3',
1451
-               'k4' => '+',
1452
-               'k44' => '-',
1453
-               'k444' => '*',
1454
-               'k4444' => '/',
1455
-               'k44444' => '4',
1456
-               'k5' => "'",
1457
-               'k55' => '`',
1458
-               'k555' => '5',
1459
-               'k6' => '"',
1460
-               'k66' => '6',
1461
-               'k7' => '^',
1462
-               'k77' => '7',
1463
-               'k8' => "\\",
1464
-               'k88' => '|',
1465
-               'k888' => '8',
1466
-               'k9' => '_',
1467
-               'k99' => '~',
1468
-               'k999' => '9'];
1436
+                'k1' => '<',
1437
+                'k11' => '(',
1438
+                'k111' => '[',
1439
+                'k1111' => '{',
1440
+                'k11111' => '1',
1441
+                'k2' => '@',
1442
+                'k22' => '$',
1443
+                'k222' => '&',
1444
+                'k2222' => '%',
1445
+                'k22222' => '2',
1446
+                'k3' => '>',
1447
+                'k33' => ')',
1448
+                'k333' => ']',
1449
+                'k3333' => '}',
1450
+                'k33333' => '3',
1451
+                'k4' => '+',
1452
+                'k44' => '-',
1453
+                'k444' => '*',
1454
+                'k4444' => '/',
1455
+                'k44444' => '4',
1456
+                'k5' => "'",
1457
+                'k55' => '`',
1458
+                'k555' => '5',
1459
+                'k6' => '"',
1460
+                'k66' => '6',
1461
+                'k7' => '^',
1462
+                'k77' => '7',
1463
+                'k8' => "\\",
1464
+                'k88' => '|',
1465
+                'k888' => '8',
1466
+                'k9' => '_',
1467
+                'k99' => '~',
1468
+                'k999' => '9'];
1469 1469
     $text = '';
1470 1470
     do {
1471 1471
       $command = false;
@@ -1656,8 +1656,8 @@  discard block
 block discarded – undo
1656 1656
    */
1657 1657
   function evaluate($command) {
1658 1658
     $broken = ['code' => 500,
1659
-               'result' => -1,
1660
-               'data' => ''];
1659
+                'result' => -1,
1660
+                'data' => ''];
1661 1661
 
1662 1662
     // write command
1663 1663
     if (!@fwrite($this->out, trim($command) . "\n")) return $broken;
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1637,7 +1637,7 @@
 block discarded – undo
1637 1637
   function &new_AsteriskManager() {
1638 1638
     $this->asm = new AGI_AsteriskManager(null, $this->config['asmanager']);
1639 1639
     $this->asm->setPagi($this);
1640
-    $this->config['asmanager'] =& $this->asm->config['asmanager'];
1640
+    $this->config['asmanager'] = & $this->asm->config['asmanager'];
1641 1641
     return $this->asm;
1642 1642
   }
1643 1643
 
Please login to merge, or discard this patch.
Braces   +222 added lines, -134 removed lines patch added patch discarded remove patch
@@ -143,26 +143,40 @@  discard block
 block discarded – undo
143 143
    */
144 144
   function __construct($config = null, $optconfig = []) {
145 145
     // load config
146
-    if (!is_null($config) && file_exists($config))
147
-      $this->config = parse_ini_file($config, true);
148
-    elseif (file_exists(DEFAULT_PHPAGI_CONFIG))
149
-      $this->config = parse_ini_file(DEFAULT_PHPAGI_CONFIG, true);
146
+    if (!is_null($config) && file_exists($config)) {
147
+          $this->config = parse_ini_file($config, true);
148
+    } elseif (file_exists(DEFAULT_PHPAGI_CONFIG)) {
149
+          $this->config = parse_ini_file(DEFAULT_PHPAGI_CONFIG, true);
150
+    }
150 151
 
151 152
     // If optconfig is specified, stuff vals and vars into 'phpagi' config array.
152
-    foreach ($optconfig as $var => $val)
153
-      $this->config['phpagi'][$var] = $val;
153
+    foreach ($optconfig as $var => $val) {
154
+          $this->config['phpagi'][$var] = $val;
155
+    }
154 156
 
155 157
     // add default values to config for uninitialized values
156
-    if (!isset($this->config['phpagi']['error_handler'])) $this->config['phpagi']['error_handler'] = true;
157
-    if (!isset($this->config['phpagi']['debug'])) $this->config['phpagi']['debug'] = false;
158
-    if (!isset($this->config['phpagi']['admin'])) $this->config['phpagi']['admin'] = null;
159
-    if (!isset($this->config['phpagi']['tempdir'])) $this->config['phpagi']['tempdir'] = AST_TMP_DIR;
158
+    if (!isset($this->config['phpagi']['error_handler'])) {
159
+      $this->config['phpagi']['error_handler'] = true;
160
+    }
161
+    if (!isset($this->config['phpagi']['debug'])) {
162
+      $this->config['phpagi']['debug'] = false;
163
+    }
164
+    if (!isset($this->config['phpagi']['admin'])) {
165
+      $this->config['phpagi']['admin'] = null;
166
+    }
167
+    if (!isset($this->config['phpagi']['tempdir'])) {
168
+      $this->config['phpagi']['tempdir'] = AST_TMP_DIR;
169
+    }
160 170
 
161 171
     // festival TTS config
162
-    if (!isset($this->config['festival']['text2wave'])) $this->config['festival']['text2wave'] = $this->which('text2wave');
172
+    if (!isset($this->config['festival']['text2wave'])) {
173
+      $this->config['festival']['text2wave'] = $this->which('text2wave');
174
+    }
163 175
 
164 176
     // swift TTS config
165
-    if (!isset($this->config['cepstral']['swift'])) $this->config['cepstral']['swift'] = $this->which('swift');
177
+    if (!isset($this->config['cepstral']['swift'])) {
178
+      $this->config['cepstral']['swift'] = $this->which('swift');
179
+    }
166 180
 
167 181
     ob_implicit_flush(true);
168 182
 
@@ -190,15 +204,18 @@  discard block
 block discarded – undo
190 204
 
191 205
     // open audio if eagi detected
192 206
     if ($this->request['agi_enhanced'] == '1.0') {
193
-      if (file_exists('/proc/' . getmypid() . '/fd/3'))
194
-        $this->audio = fopen('/proc/' . getmypid() . '/fd/3', 'r');
195
-      elseif (file_exists('/dev/fd/3')) {
207
+      if (file_exists('/proc/' . getmypid() . '/fd/3')) {
208
+              $this->audio = fopen('/proc/' . getmypid() . '/fd/3', 'r');
209
+      } elseif (file_exists('/dev/fd/3')) {
196 210
         // may need to mount fdescfs
197 211
         $this->audio = fopen('/dev/fd/3', 'r');
198
-      } else
199
-        $this->conlog('Unable to open audio stream');
212
+      } else {
213
+              $this->conlog('Unable to open audio stream');
214
+      }
200 215
 
201
-      if ($this->audio) stream_set_blocking($this->audio, 0);
216
+      if ($this->audio) {
217
+        stream_set_blocking($this->audio, 0);
218
+      }
202 219
     }
203 220
 
204 221
     $this->conlog('AGI Request:');
@@ -297,7 +314,9 @@  discard block
 block discarded – undo
297 314
    */
298 315
   function database_deltree($family, $keytree = '') {
299 316
     $cmd = "DATABASE DELTREE \"$family\"";
300
-    if ($keytree != '') $cmd .= " \"$keytree\"";
317
+    if ($keytree != '') {
318
+      $cmd .= " \"$keytree\"";
319
+    }
301 320
     return $this->evaluate($cmd);
302 321
   }
303 322
 
@@ -337,10 +356,11 @@  discard block
 block discarded – undo
337 356
    * @return array, see evaluate for return information. ['result'] is 1 on sucess, 0 otherwise
338 357
    */
339 358
   function set_global_var($pVariable, $pValue) {
340
-    if (is_numeric($pValue))
341
-      return $this->evaluate("Set({$pVariable}={$pValue},g);");
342
-    else
343
-      return $this->evaluate("Set({$pVariable}=\"{$pValue}\",g);");
359
+    if (is_numeric($pValue)) {
360
+          return $this->evaluate("Set({$pVariable}={$pValue},g);");
361
+    } else {
362
+          return $this->evaluate("Set({$pVariable}=\"{$pValue}\",g);");
363
+    }
344 364
   }
345 365
 
346 366
 
@@ -354,10 +374,11 @@  discard block
 block discarded – undo
354 374
    * @return array, see evaluate for return information. ['result'] is 1 on sucess, 0 otherwise
355 375
    */
356 376
   function set_var($pVariable, $pValue) {
357
-    if (is_numeric($pValue))
358
-      return $this->evaluate("Set({$pVariable}={$pValue});");
359
-    else
360
-      return $this->evaluate("Set({$pVariable}=\"{$pValue}\");");
377
+    if (is_numeric($pValue)) {
378
+          return $this->evaluate("Set({$pVariable}={$pValue});");
379
+    } else {
380
+          return $this->evaluate("Set({$pVariable}=\"{$pValue}\");");
381
+    }
361 382
   }
362 383
 
363 384
 
@@ -371,7 +392,9 @@  discard block
 block discarded – undo
371 392
    * @return array, see evaluate for return information. ['result'] is whatever the application returns, or -2 on failure to find application
372 393
    */
373 394
   function exec($application, $options) {
374
-    if (is_array($options)) $options = join('|', $options);
395
+    if (is_array($options)) {
396
+      $options = join('|', $options);
397
+    }
375 398
     return $this->evaluate("EXEC $application $options");
376 399
   }
377 400
 
@@ -430,8 +453,9 @@  discard block
 block discarded – undo
430 453
   function get_variable($variable, $getvalue = false) {
431 454
     $res = $this->evaluate("GET VARIABLE $variable");
432 455
 
433
-    if ($getvalue == false)
434
-      return ($res);
456
+    if ($getvalue == false) {
457
+          return ($res);
458
+    }
435 459
 
436 460
     return ($res['data']);
437 461
   }
@@ -457,8 +481,9 @@  discard block
 block discarded – undo
457 481
 
458 482
     $res = $this->evaluate('GET FULL VARIABLE ' . $req);
459 483
 
460
-    if ($getvalue == false)
461
-      return ($res);
484
+    if ($getvalue == false) {
485
+          return ($res);
486
+    }
462 487
 
463 488
     return ($res['data']);
464 489
 
@@ -523,8 +548,12 @@  discard block
 block discarded – undo
523 548
    */
524 549
   function record_file($file, $format, $escape_digits = '', $timeout = -1, $offset = null, $beep = false, $silence = null) {
525 550
     $cmd = trim("RECORD FILE $file $format \"$escape_digits\" $timeout $offset");
526
-    if ($beep) $cmd .= ' BEEP';
527
-    if (!is_null($silence)) $cmd .= " s=$silence";
551
+    if ($beep) {
552
+      $cmd .= ' BEEP';
553
+    }
554
+    if (!is_null($silence)) {
555
+      $cmd .= " s=$silence";
556
+    }
528 557
     return $this->evaluate($cmd);
529 558
   }
530 559
 
@@ -590,7 +619,9 @@  discard block
 block discarded – undo
590 619
    * digit received, otherwise a decimal value of the DTMF tone.  Use chr() to convert to ASCII.
591 620
    */
592 621
   function say_time($time = null, $escape_digits = '') {
593
-    if (is_null($time)) $time = time();
622
+    if (is_null($time)) {
623
+      $time = time();
624
+    }
594 625
     return $this->evaluate("SAY TIME $time \"$escape_digits\"");
595 626
   }
596 627
 
@@ -905,13 +936,15 @@  discard block
 block discarded – undo
905 936
   function fastpass_say_digits(&$buffer, $digits, $escape_digits = '') {
906 937
     $proceed = false;
907 938
     if ($escape_digits != '' && $buffer != '') {
908
-      if (!strpos(chr(255) . $escape_digits, $buffer[strlen($buffer) - 1]))
909
-        $proceed = true;
939
+      if (!strpos(chr(255) . $escape_digits, $buffer[strlen($buffer) - 1])) {
940
+              $proceed = true;
941
+      }
910 942
     }
911 943
     if ($buffer == '' || $proceed) {
912 944
       $res = $this->say_digits($digits, $escape_digits);
913
-      if ($res['code'] == AGIRES_OK && $res['result'] > 0)
914
-        $buffer .= chr($res['result']);
945
+      if ($res['code'] == AGIRES_OK && $res['result'] > 0) {
946
+              $buffer .= chr($res['result']);
947
+      }
915 948
       return $res;
916 949
     }
917 950
     return ['code' => AGIRES_OK,
@@ -932,13 +965,15 @@  discard block
 block discarded – undo
932 965
   function fastpass_say_number(&$buffer, $number, $escape_digits = '') {
933 966
     $proceed = false;
934 967
     if ($escape_digits != '' && $buffer != '') {
935
-      if (!strpos(chr(255) . $escape_digits, $buffer[strlen($buffer) - 1]))
936
-        $proceed = true;
968
+      if (!strpos(chr(255) . $escape_digits, $buffer[strlen($buffer) - 1])) {
969
+              $proceed = true;
970
+      }
937 971
     }
938 972
     if ($buffer == '' || $proceed) {
939 973
       $res = $this->say_number($number, $escape_digits);
940
-      if ($res['code'] == AGIRES_OK && $res['result'] > 0)
941
-        $buffer .= chr($res['result']);
974
+      if ($res['code'] == AGIRES_OK && $res['result'] > 0) {
975
+              $buffer .= chr($res['result']);
976
+      }
942 977
       return $res;
943 978
     }
944 979
     return ['code' => AGIRES_OK,
@@ -959,13 +994,15 @@  discard block
 block discarded – undo
959 994
   function fastpass_say_phonetic(&$buffer, $text, $escape_digits = '') {
960 995
     $proceed = false;
961 996
     if ($escape_digits != '' && $buffer != '') {
962
-      if (!strpos(chr(255) . $escape_digits, $buffer[strlen($buffer) - 1]))
963
-        $proceed = true;
997
+      if (!strpos(chr(255) . $escape_digits, $buffer[strlen($buffer) - 1])) {
998
+              $proceed = true;
999
+      }
964 1000
     }
965 1001
     if ($buffer == '' || $proceed) {
966 1002
       $res = $this->say_phonetic($text, $escape_digits);
967
-      if ($res['code'] == AGIRES_OK && $res['result'] > 0)
968
-        $buffer .= chr($res['result']);
1003
+      if ($res['code'] == AGIRES_OK && $res['result'] > 0) {
1004
+              $buffer .= chr($res['result']);
1005
+      }
969 1006
       return $res;
970 1007
     }
971 1008
     return ['code' => AGIRES_OK,
@@ -986,13 +1023,15 @@  discard block
 block discarded – undo
986 1023
   function fastpass_say_time(&$buffer, $time = null, $escape_digits = '') {
987 1024
     $proceed = false;
988 1025
     if ($escape_digits != '' && $buffer != '') {
989
-      if (!strpos(chr(255) . $escape_digits, $buffer[strlen($buffer) - 1]))
990
-        $proceed = true;
1026
+      if (!strpos(chr(255) . $escape_digits, $buffer[strlen($buffer) - 1])) {
1027
+              $proceed = true;
1028
+      }
991 1029
     }
992 1030
     if ($buffer == '' || $proceed) {
993 1031
       $res = $this->say_time($time, $escape_digits);
994
-      if ($res['code'] == AGIRES_OK && $res['result'] > 0)
995
-        $buffer .= chr($res['result']);
1032
+      if ($res['code'] == AGIRES_OK && $res['result'] > 0) {
1033
+              $buffer .= chr($res['result']);
1034
+      }
996 1035
       return $res;
997 1036
     }
998 1037
     return ['code' => AGIRES_OK,
@@ -1016,13 +1055,15 @@  discard block
 block discarded – undo
1016 1055
   function fastpass_stream_file(&$buffer, $filename, $escape_digits = '', $offset = 0) {
1017 1056
     $proceed = false;
1018 1057
     if ($escape_digits != '' && $buffer != '') {
1019
-      if (!strpos(chr(255) . $escape_digits, $buffer[strlen($buffer) - 1]))
1020
-        $proceed = true;
1058
+      if (!strpos(chr(255) . $escape_digits, $buffer[strlen($buffer) - 1])) {
1059
+              $proceed = true;
1060
+      }
1021 1061
     }
1022 1062
     if ($buffer == '' || $proceed) {
1023 1063
       $res = $this->stream_file($filename, $escape_digits, $offset);
1024
-      if ($res['code'] == AGIRES_OK && $res['result'] > 0)
1025
-        $buffer .= chr($res['result']);
1064
+      if ($res['code'] == AGIRES_OK && $res['result'] > 0) {
1065
+              $buffer .= chr($res['result']);
1066
+      }
1026 1067
       return $res;
1027 1068
     }
1028 1069
     return ['code' => AGIRES_OK,
@@ -1044,13 +1085,15 @@  discard block
 block discarded – undo
1044 1085
   function fastpass_text2wav(&$buffer, $text, $escape_digits = '', $frequency = 8000) {
1045 1086
     $proceed = false;
1046 1087
     if ($escape_digits != '' && $buffer != '') {
1047
-      if (!strpos(chr(255) . $escape_digits, $buffer[strlen($buffer) - 1]))
1048
-        $proceed = true;
1088
+      if (!strpos(chr(255) . $escape_digits, $buffer[strlen($buffer) - 1])) {
1089
+              $proceed = true;
1090
+      }
1049 1091
     }
1050 1092
     if ($buffer == '' || $proceed) {
1051 1093
       $res = $this->text2wav($text, $escape_digits, $frequency);
1052
-      if ($res['code'] == AGIRES_OK && $res['result'] > 0)
1053
-        $buffer .= chr($res['result']);
1094
+      if ($res['code'] == AGIRES_OK && $res['result'] > 0) {
1095
+              $buffer .= chr($res['result']);
1096
+      }
1054 1097
       return $res;
1055 1098
     }
1056 1099
     return ['code' => AGIRES_OK,
@@ -1072,13 +1115,15 @@  discard block
 block discarded – undo
1072 1115
   function fastpass_swift(&$buffer, $text, $escape_digits = '', $frequency = 8000, $voice = null) {
1073 1116
     $proceed = false;
1074 1117
     if ($escape_digits != '' && $buffer != '') {
1075
-      if (!strpos(chr(255) . $escape_digits, $buffer[strlen($buffer) - 1]))
1076
-        $proceed = true;
1118
+      if (!strpos(chr(255) . $escape_digits, $buffer[strlen($buffer) - 1])) {
1119
+              $proceed = true;
1120
+      }
1077 1121
     }
1078 1122
     if ($buffer == '' || $proceed) {
1079 1123
       $res = $this->swift($text, $escape_digits, $frequency, $voice);
1080
-      if ($res['code'] == AGIRES_OK && $res['result'] > 0)
1081
-        $buffer .= chr($res['result']);
1124
+      if ($res['code'] == AGIRES_OK && $res['result'] > 0) {
1125
+              $buffer .= chr($res['result']);
1126
+      }
1082 1127
       return $res;
1083 1128
     }
1084 1129
     return ['code' => AGIRES_OK,
@@ -1099,13 +1144,15 @@  discard block
 block discarded – undo
1099 1144
   function fastpass_say_punctuation(&$buffer, $text, $escape_digits = '', $frequency = 8000) {
1100 1145
     $proceed = false;
1101 1146
     if ($escape_digits != '' && $buffer != '') {
1102
-      if (!strpos(chr(255) . $escape_digits, $buffer[strlen($buffer) - 1]))
1103
-        $proceed = true;
1147
+      if (!strpos(chr(255) . $escape_digits, $buffer[strlen($buffer) - 1])) {
1148
+              $proceed = true;
1149
+      }
1104 1150
     }
1105 1151
     if ($buffer == '' || $proceed) {
1106 1152
       $res = $this->say_punctuation($text, $escape_digits, $frequency);
1107
-      if ($res['code'] == AGIRES_OK && $res['result'] > 0)
1108
-        $buffer .= chr($res['result']);
1153
+      if ($res['code'] == AGIRES_OK && $res['result'] > 0) {
1154
+              $buffer .= chr($res['result']);
1155
+      }
1109 1156
       return $res;
1110 1157
     }
1111 1158
     return ['code' => AGIRES_OK,
@@ -1153,14 +1200,19 @@  discard block
 block discarded – undo
1153 1200
     if (is_null($max_digits) || strlen($buffer) < $max_digits) {
1154 1201
       if ($buffer == '') {
1155 1202
         $res = $this->get_data($filename, $timeout, $max_digits);
1156
-        if ($res['code'] == AGIRES_OK)
1157
-          $buffer .= $res['result'];
1203
+        if ($res['code'] == AGIRES_OK) {
1204
+                  $buffer .= $res['result'];
1205
+        }
1158 1206
         return $res;
1159 1207
       } else {
1160 1208
         while (is_null($max_digits) || strlen($buffer) < $max_digits) {
1161 1209
           $res = $this->wait_for_digit();
1162
-          if ($res['code'] != AGIRES_OK) return $res;
1163
-          if ($res['result'] == ord('#')) break;
1210
+          if ($res['code'] != AGIRES_OK) {
1211
+            return $res;
1212
+          }
1213
+          if ($res['result'] == ord('#')) {
1214
+            break;
1215
+          }
1164 1216
           $buffer .= chr($res['result']);
1165 1217
         }
1166 1218
       }
@@ -1189,10 +1241,11 @@  discard block
 block discarded – undo
1189 1241
     $choice = null;
1190 1242
     while (is_null($choice)) {
1191 1243
       foreach ($choices as $prompt) {
1192
-        if ($prompt[0] == '*')
1193
-          $ret = $this->text2wav(substr($prompt, 1), $keys);
1194
-        else
1195
-          $ret = $this->stream_file($prompt, $keys);
1244
+        if ($prompt[0] == '*') {
1245
+                  $ret = $this->text2wav(substr($prompt, 1), $keys);
1246
+        } else {
1247
+                  $ret = $this->stream_file($prompt, $keys);
1248
+        }
1196 1249
 
1197 1250
         if ($ret['code'] != AGIRES_OK || $ret['result'] == -1) {
1198 1251
           $choice = -1;
@@ -1207,10 +1260,11 @@  discard block
 block discarded – undo
1207 1260
 
1208 1261
       if (is_null($choice)) {
1209 1262
         $ret = $this->get_data('beep', $timeout, 1);
1210
-        if ($ret['code'] != AGIRES_OK || $ret['result'] == -1)
1211
-          $choice = -1;
1212
-        elseif ($ret['result'] != '' && strpos(' ' . $keys, $ret['result']))
1213
-          $choice = $ret['result'];
1263
+        if ($ret['code'] != AGIRES_OK || $ret['result'] == -1) {
1264
+                  $choice = -1;
1265
+        } elseif ($ret['result'] != '' && strpos(' ' . $keys, $ret['result'])) {
1266
+                  $choice = $ret['result'];
1267
+        }
1214 1268
       }
1215 1269
     }
1216 1270
     return $choice;
@@ -1241,8 +1295,9 @@  discard block
 block discarded – undo
1241 1295
    *
1242 1296
    */
1243 1297
   function parse_callerid($callerid = null) {
1244
-    if (is_null($callerid))
1245
-      $callerid = $this->request['agi_callerid'];
1298
+    if (is_null($callerid)) {
1299
+          $callerid = $this->request['agi_callerid'];
1300
+    }
1246 1301
 
1247 1302
     $ret = ['name' => '',
1248 1303
             'protocol' => '',
@@ -1260,18 +1315,18 @@  discard block
 block discarded – undo
1260 1315
 
1261 1316
     $callerid = explode('@', trim($callerid, '<> '));
1262 1317
     $username = explode(':', array_shift($callerid));
1263
-    if (count($username) == 1)
1264
-      $ret['username'] = $username[0];
1265
-    else {
1318
+    if (count($username) == 1) {
1319
+          $ret['username'] = $username[0];
1320
+    } else {
1266 1321
       $ret['protocol'] = array_shift($username);
1267 1322
       $ret['username'] = join(':', $username);
1268 1323
     }
1269 1324
 
1270 1325
     $callerid = join('@', $callerid);
1271 1326
     $host = explode(':', $callerid);
1272
-    if (count($host) == 1)
1273
-      $ret['host'] = $host[0];
1274
-    else {
1327
+    if (count($host) == 1) {
1328
+          $ret['host'] = $host[0];
1329
+    } else {
1275 1330
       $ret['host'] = array_shift($host);
1276 1331
       $ret['port'] = join(':', $host);
1277 1332
     }
@@ -1294,7 +1349,9 @@  discard block
 block discarded – undo
1294 1349
    */
1295 1350
   function text2wav($text, $escape_digits = '', $frequency = 8000) {
1296 1351
     $text = trim($text);
1297
-    if ($text == '') return true;
1352
+    if ($text == '') {
1353
+      return true;
1354
+    }
1298 1355
 
1299 1356
     $hash = md5($text);
1300 1357
     $fname = $this->config['phpagi']['tempdir'] . DIRECTORY_SEPARATOR;
@@ -1320,9 +1377,10 @@  discard block
 block discarded – undo
1320 1377
 
1321 1378
     // clean up old files
1322 1379
     $delete = time() - 2592000; // 1 month
1323
-    foreach (glob($this->config['phpagi']['tempdir'] . DIRECTORY_SEPARATOR . 'text2wav_*') as $file)
1324
-      if (filemtime($file) < $delete)
1380
+    foreach (glob($this->config['phpagi']['tempdir'] . DIRECTORY_SEPARATOR . 'text2wav_*') as $file) {
1381
+          if (filemtime($file) < $delete)
1325 1382
         unlink($file);
1383
+    }
1326 1384
 
1327 1385
     return $ret;
1328 1386
   }
@@ -1337,13 +1395,16 @@  discard block
 block discarded – undo
1337 1395
    * @return array, see evaluate for return information.
1338 1396
    */
1339 1397
   function swift($text, $escape_digits = '', $frequency = 8000, $voice = null) {
1340
-    if (!is_null($voice))
1341
-      $voice = "-n $voice";
1342
-    elseif (isset($this->config['cepstral']['voice']))
1343
-      $voice = "-n {$this->config['cepstral']['voice']}";
1398
+    if (!is_null($voice)) {
1399
+          $voice = "-n $voice";
1400
+    } elseif (isset($this->config['cepstral']['voice'])) {
1401
+          $voice = "-n {$this->config['cepstral']['voice']}";
1402
+    }
1344 1403
 
1345 1404
     $text = trim($text);
1346
-    if ($text == '') return true;
1405
+    if ($text == '') {
1406
+      return true;
1407
+    }
1347 1408
 
1348 1409
     $hash = md5($text);
1349 1410
     $fname = $this->config['phpagi']['tempdir'] . DIRECTORY_SEPARATOR;
@@ -1366,9 +1427,10 @@  discard block
 block discarded – undo
1366 1427
 
1367 1428
     // clean up old files
1368 1429
     $delete = time() - 2592000; // 1 month
1369
-    foreach (glob($this->config['phpagi']['tempdir'] . DIRECTORY_SEPARATOR . 'swift_*') as $file)
1370
-      if (filemtime($file) < $delete)
1430
+    foreach (glob($this->config['phpagi']['tempdir'] . DIRECTORY_SEPARATOR . 'swift_*') as $file) {
1431
+          if (filemtime($file) < $delete)
1371 1432
         unlink($file);
1433
+    }
1372 1434
 
1373 1435
     return $ret;
1374 1436
   }
@@ -1497,16 +1559,17 @@  discard block
 block discarded – undo
1497 1559
           $code = substr($code, 1);
1498 1560
           $command = false;
1499 1561
         }
1500
-        if ($code == '')
1501
-          $command = true;
1502
-        elseif ($mode == 'NUMERIC')
1503
-          $text .= $code;
1504
-        elseif ($mode == 'UPPERCASE' && isset($alpha['k' . $code]))
1505
-          $text .= $alpha['k' . $code];
1506
-        elseif ($mode == 'LOWERCASE' && isset($alpha['k' . $code]))
1507
-          $text .= strtolower($alpha['k' . $code]);
1508
-        elseif ($mode == 'SYMBOL' && isset($symbol['k' . $code]))
1509
-          $text .= $symbol['k' . $code];
1562
+        if ($code == '') {
1563
+                  $command = true;
1564
+        } elseif ($mode == 'NUMERIC') {
1565
+                  $text .= $code;
1566
+        } elseif ($mode == 'UPPERCASE' && isset($alpha['k' . $code])) {
1567
+                  $text .= $alpha['k' . $code];
1568
+        } elseif ($mode == 'LOWERCASE' && isset($alpha['k' . $code])) {
1569
+                  $text .= strtolower($alpha['k' . $code]);
1570
+        } elseif ($mode == 'SYMBOL' && isset($symbol['k' . $code])) {
1571
+                  $text .= $symbol['k' . $code];
1572
+        }
1510 1573
       }
1511 1574
       $this->say_punctuation($text);
1512 1575
     } while (substr($result['result'], -2) == '**');
@@ -1660,7 +1723,9 @@  discard block
 block discarded – undo
1660 1723
                'data' => ''];
1661 1724
 
1662 1725
     // write command
1663
-    if (!@fwrite($this->out, trim($command) . "\n")) return $broken;
1726
+    if (!@fwrite($this->out, trim($command) . "\n")) {
1727
+      return $broken;
1728
+    }
1664 1729
     fflush($this->out);
1665 1730
 
1666 1731
     // Read result.  Occasionally, a command return a string followed by an extra new line.
@@ -1682,9 +1747,11 @@  discard block
 block discarded – undo
1682 1747
     $ret['code'] = substr($str, 0, 3);
1683 1748
     $str = trim(substr($str, 3));
1684 1749
 
1685
-    if ($str[0] == '-') // we have a multiline response!
1750
+    if ($str[0] == '-') {
1751
+      // we have a multiline response!
1686 1752
     {
1687 1753
       $count = 0;
1754
+    }
1688 1755
       $str = substr($str, 1) . "\n";
1689 1756
       $line = fgets($this->in, 4096);
1690 1757
       while (substr($line, 0, 3) != $ret['code'] && $count < 5) {
@@ -1700,34 +1767,44 @@  discard block
 block discarded – undo
1700 1767
 
1701 1768
     $ret['result'] = null;
1702 1769
     $ret['data'] = '';
1703
-    if ($ret['code'] != AGIRES_OK) // some sort of error
1770
+    if ($ret['code'] != AGIRES_OK) {
1771
+      // some sort of error
1704 1772
     {
1705 1773
       $ret['data'] = $str;
1774
+    }
1706 1775
       $this->conlog(print_r($ret, true));
1707 1776
     } else // normal AGIRES_OK response
1708 1777
     {
1709 1778
       $parse = explode(' ', trim($str));
1710 1779
       $in_token = false;
1711 1780
       foreach ($parse as $token) {
1712
-        if ($in_token) // we previously hit a token starting with ')' but not ending in ')'
1781
+        if ($in_token) {
1782
+          // we previously hit a token starting with ')' but not ending in ')'
1713 1783
         {
1714 1784
           $ret['data'] .= ' ' . trim($token, '() ');
1715
-          if ($token[strlen($token) - 1] == ')') $in_token = false;
1785
+        }
1786
+          if ($token[strlen($token) - 1] == ')') {
1787
+            $in_token = false;
1788
+          }
1716 1789
         } elseif ($token[0] == '(') {
1717
-          if ($token[strlen($token) - 1] != ')') $in_token = true;
1790
+          if ($token[strlen($token) - 1] != ')') {
1791
+            $in_token = true;
1792
+          }
1718 1793
           $ret['data'] .= ' ' . trim($token, '() ');
1719 1794
         } elseif (strpos($token, '=')) {
1720 1795
           $token = explode('=', $token);
1721 1796
           $ret[$token[0]] = $token[1];
1722
-        } elseif ($token != '')
1723
-          $ret['data'] .= ' ' . $token;
1797
+        } elseif ($token != '') {
1798
+                  $ret['data'] .= ' ' . $token;
1799
+        }
1724 1800
       }
1725 1801
       $ret['data'] = trim($ret['data']);
1726 1802
     }
1727 1803
 
1728 1804
     // log some errors
1729
-    if ($ret['result'] < 0)
1730
-      $this->conlog("$command returned {$ret['result']}");
1805
+    if ($ret['result'] < 0) {
1806
+          $this->conlog("$command returned {$ret['result']}");
1807
+    }
1731 1808
 
1732 1809
     return $ret;
1733 1810
   }
@@ -1744,9 +1821,11 @@  discard block
 block discarded – undo
1744 1821
     static $busy = false;
1745 1822
 
1746 1823
     if ($this->config['phpagi']['debug'] != false) {
1747
-      if (!$busy) // no conlogs inside conlog!!!
1824
+      if (!$busy) {
1825
+        // no conlogs inside conlog!!!
1748 1826
       {
1749 1827
         $busy = true;
1828
+      }
1750 1829
         $this->verbose($str, $vbl);
1751 1830
         $busy = false;
1752 1831
       }
@@ -1772,9 +1851,10 @@  discard block
 block discarded – undo
1772 1851
       $chpath = $checkpath;
1773 1852
     }
1774 1853
 
1775
-    foreach (explode(':', $chpath) as $path)
1776
-      if (is_executable("$path/$cmd"))
1854
+    foreach (explode(':', $chpath) as $path) {
1855
+          if (is_executable("$path/$cmd"))
1777 1856
         return "$path/$cmd";
1857
+    }
1778 1858
 
1779 1859
     return false;
1780 1860
   }
@@ -1815,18 +1895,23 @@  discard block
 block discarded – undo
1815 1895
  * @param array $context variables in the current scope
1816 1896
  */
1817 1897
 function phpagi_error_handler(int $level, string $message, string $file, int $line, array $context) {
1818
-  if (ini_get('error_reporting') == 0) return; // this happens with an @
1898
+  if (ini_get('error_reporting') == 0) {
1899
+    return;
1900
+  }
1901
+  // this happens with an @
1819 1902
 
1820 1903
   @syslog(LOG_WARNING, $file . '[' . $line . ']: ' . $message);
1821 1904
 
1822 1905
   global $phpagi_error_handler_email;
1823
-  if (function_exists('mail') && !is_null($phpagi_error_handler_email)) // generate email debugging information
1906
+  if (function_exists('mail') && !is_null($phpagi_error_handler_email)) {
1907
+    // generate email debugging information
1824 1908
   {
1825 1909
     // decode error level
1826 1910
     switch ($level) {
1827 1911
       case E_WARNING:
1828 1912
       case E_USER_WARNING:
1829 1913
         $level = "Warning";
1914
+  }
1830 1915
         break;
1831 1916
       case E_NOTICE:
1832 1917
       case E_USER_NOTICE:
@@ -1871,29 +1956,32 @@  discard block
 block discarded – undo
1871 1956
     if (file_exists($file)) {
1872 1957
       $message .= "\n\n$file:\n";
1873 1958
       $code = @file($file);
1874
-      for ($i = max(0, $line - 10); $i < min($line + 10, count($code)); $i++)
1875
-        $message .= ($i + 1) . "\t$code[$i]";
1959
+      for ($i = max(0, $line - 10); $i < min($line + 10, count($code)); $i++) {
1960
+              $message .= ($i + 1) . "\t$code[$i]";
1961
+      }
1876 1962
     }
1877 1963
 
1878 1964
     // make sure message is fully readable (convert unprintable chars to hex representation)
1879 1965
     $ret = '';
1880 1966
     for ($i = 0; $i < strlen($message); $i++) {
1881 1967
       $c = ord($message[$i]);
1882
-      if ($c == 10 || $c == 13 || $c == 9)
1883
-        $ret .= $message[$i];
1884
-      elseif ($c < 16)
1885
-        $ret .= '\x0' . dechex($c);
1886
-      elseif ($c < 32 || $c > 127)
1887
-        $ret .= '\x' . dechex($c);
1888
-      else
1889
-        $ret .= $message[$i];
1968
+      if ($c == 10 || $c == 13 || $c == 9) {
1969
+              $ret .= $message[$i];
1970
+      } elseif ($c < 16) {
1971
+              $ret .= '\x0' . dechex($c);
1972
+      } elseif ($c < 32 || $c > 127) {
1973
+              $ret .= '\x' . dechex($c);
1974
+      } else {
1975
+              $ret .= $message[$i];
1976
+      }
1890 1977
     }
1891 1978
     $message = $ret;
1892 1979
 
1893 1980
     // send the mail if less than 5 errors
1894 1981
     static $mailcount = 0;
1895
-    if ($mailcount < 5)
1896
-      @mail($phpagi_error_handler_email, $subject, $message);
1982
+    if ($mailcount < 5) {
1983
+          @mail($phpagi_error_handler_email, $subject, $message);
1984
+    }
1897 1985
     $mailcount++;
1898 1986
   }
1899 1987
 }
Please login to merge, or discard this patch.
src/phpagi-fastagi.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -33,8 +33,9 @@
 block discarded – undo
33 33
 
34 34
 $fastagi->verbose(print_r($fastagi, true));
35 35
 
36
-if (!isset($fastagi->config['fastagi']['basedir']))
36
+if (!isset($fastagi->config['fastagi']['basedir'])) {
37 37
   $fastagi->config['fastagi']['basedir'] = dirname(__FILE__);
38
+}
38 39
 
39 40
 // perform some security checks
40 41
 
Please login to merge, or discard this patch.
src/phpagi-asmanager.php 3 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
 
328 328
     // login
329 329
     $res = $this->send_request('login', ['Username' => $username,
330
-                                         'Secret' => $secret]);
330
+                                          'Secret' => $secret]);
331 331
     if ($res['Response'] != 'Success') {
332 332
       $this->_logged_in = false;
333 333
       $this->log("Failed to login.");
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
    */
367 367
   function AbsoluteTimeout(string $channel, int $timeout): array {
368 368
     return $this->send_request('AbsoluteTimeout', ['Channel' => $channel,
369
-                                                   'Timeout' => $timeout]);
369
+                                                    'Timeout' => $timeout]);
370 370
   }
371 371
 
372 372
   /**
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
    */
381 381
   function ChangeMonitor(string $channel, string $file): array {
382 382
     return $this->send_request('ChangeMonitor', ['Channel' => $channel,
383
-                                                 'File' => $file]);
383
+                                                  'File' => $file]);
384 384
   }
385 385
 
386 386
   /**
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
    */
433 433
   function DBGet(string $family, string $key, $actionid = null): string {
434 434
     $parameters = ['Family' => $family,
435
-                   'Key' => $key];
435
+                    'Key' => $key];
436 436
     if ($actionid == null)
437 437
       $actionid = $this->ActionID();
438 438
     $parameters['ActionID'] = $actionid;
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
    */
457 457
   function ExtensionState(string $exten, string $context, $actionid = null): array {
458 458
     $parameters = ['Exten' => $exten,
459
-                   'Context' => $context];
459
+                    'Context' => $context];
460 460
     if ($actionid) $parameters['ActionID'] = $actionid;
461 461
     return $this->send_request('ExtensionState', $parameters);
462 462
   }
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
    */
475 475
   function GetVar(string $channel, string $variable, $actionid = null): array {
476 476
     $parameters = ['Channel' => $channel,
477
-                   'Variable' => $variable];
477
+                    'Variable' => $variable];
478 478
     if ($actionid) $parameters['ActionID'] = $actionid;
479 479
     return $this->send_request('GetVar', $parameters);
480 480
   }
@@ -603,9 +603,9 @@  discard block
 block discarded – undo
603 603
    * @throws Exception
604 604
    */
605 605
   function Originate(string $channel,
606
-                     $exten = null, $context = null, $priority = null,
607
-                     $application = null, $data = null,
608
-                     $timeout = null, $callerid = null, $variable = null, $account = null, $async = null, $actionid = null): array {
606
+                      $exten = null, $context = null, $priority = null,
607
+                      $application = null, $data = null,
608
+                      $timeout = null, $callerid = null, $variable = null, $account = null, $async = null, $actionid = null): array {
609 609
     $parameters = ['Channel' => $channel];
610 610
 
611 611
     if ($exten) $parameters['Exten'] = $exten;
@@ -660,7 +660,7 @@  discard block
 block discarded – undo
660 660
    */
661 661
   function QueueAdd(string $queue, string $interface, int $penalty = 0, $memberName = false): array {
662 662
     $parameters = ['Queue' => $queue,
663
-                   'Interface' => $interface];
663
+                    'Interface' => $interface];
664 664
     if ($penalty) $parameters['Penalty'] = $penalty;
665 665
     if ($memberName) $parameters["MemberName"] = $memberName;
666 666
     return $this->send_request('QueueAdd', $parameters);
@@ -677,7 +677,7 @@  discard block
 block discarded – undo
677 677
    */
678 678
   function QueueRemove(string $queue, string $interface): array {
679 679
     return $this->send_request('QueueRemove', ['Queue' => $queue,
680
-                                               'Interface' => $interface]);
680
+                                                'Interface' => $interface]);
681 681
   }
682 682
 
683 683
   /**
@@ -757,7 +757,7 @@  discard block
 block discarded – undo
757 757
    */
758 758
   function SetCDRUserField(string $userfield, string $channel, $append = null): array {
759 759
     $parameters = ['UserField' => $userfield,
760
-                   'Channel' => $channel];
760
+                    'Channel' => $channel];
761 761
     if ($append) $parameters['Append'] = $append;
762 762
     return $this->send_request('SetCDRUserField', $parameters);
763 763
   }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -201,7 +201,7 @@
 block discarded – undo
201 201
     }
202 202
 
203 203
     $haveData = array_key_exists("data", $parameters);
204
-    $asteriskRawOutput = [];;
204
+    $asteriskRawOutput = []; ;
205 205
 
206 206
     foreach ($msgarr as $num => $str) {
207 207
       $kv = explode(':', $str, 2);
Please login to merge, or discard this patch.
Braces   +125 added lines, -53 removed lines patch added patch discarded remove patch
@@ -109,21 +109,33 @@  discard block
 block discarded – undo
109 109
    */
110 110
   function __construct($config = null, array $optconfig = []) {
111 111
     // load config
112
-    if (!is_null($config) && file_exists($config))
113
-      $this->config = parse_ini_file($config, true);
114
-    elseif (file_exists(DEFAULT_PHPAGI_CONFIG))
115
-      $this->config = parse_ini_file(DEFAULT_PHPAGI_CONFIG, true);
112
+    if (!is_null($config) && file_exists($config)) {
113
+          $this->config = parse_ini_file($config, true);
114
+    } elseif (file_exists(DEFAULT_PHPAGI_CONFIG)) {
115
+          $this->config = parse_ini_file(DEFAULT_PHPAGI_CONFIG, true);
116
+    }
116 117
 
117 118
     // If optconfig is specified, stuff values and vars into 'asmanager' config array.
118
-    foreach ($optconfig as $var => $val)
119
-      $this->config['asmanager'][$var] = $val;
119
+    foreach ($optconfig as $var => $val) {
120
+          $this->config['asmanager'][$var] = $val;
121
+    }
120 122
 
121 123
     // add default values to config for uninitialized values
122
-    if (!isset($this->config['asmanager']['server'])) $this->config['asmanager']['server'] = 'localhost';
123
-    if (!isset($this->config['asmanager']['port'])) $this->config['asmanager']['port'] = 5038;
124
-    if (!isset($this->config['asmanager']['username'])) $this->config['asmanager']['username'] = 'phpagi';
125
-    if (!isset($this->config['asmanager']['secret'])) $this->config['asmanager']['secret'] = 'phpagi';
126
-    if (!isset($this->config['asmanager']['write_log'])) $this->config['asmanager']['write_log'] = false;
124
+    if (!isset($this->config['asmanager']['server'])) {
125
+      $this->config['asmanager']['server'] = 'localhost';
126
+    }
127
+    if (!isset($this->config['asmanager']['port'])) {
128
+      $this->config['asmanager']['port'] = 5038;
129
+    }
130
+    if (!isset($this->config['asmanager']['username'])) {
131
+      $this->config['asmanager']['username'] = 'phpagi';
132
+    }
133
+    if (!isset($this->config['asmanager']['secret'])) {
134
+      $this->config['asmanager']['secret'] = 'phpagi';
135
+    }
136
+    if (!isset($this->config['asmanager']['write_log'])) {
137
+      $this->config['asmanager']['write_log'] = false;
138
+    }
127 139
   }
128 140
 
129 141
   /**
@@ -270,10 +282,11 @@  discard block
 block discarded – undo
270 282
       $evlist = [];
271 283
       do {
272 284
         $res = $this->wait_response(false, $actionid);
273
-        if (isset($res['EventList']) && $res['EventList'] == 'Complete')
274
-          break;
275
-        else
276
-          $evlist[] = $res;
285
+        if (isset($res['EventList']) && $res['EventList'] == 'Complete') {
286
+                  break;
287
+        } else {
288
+                  $evlist[] = $res;
289
+        }
277 290
       } while (true);
278 291
       $res['events'] = $evlist;
279 292
     }
@@ -295,9 +308,15 @@  discard block
 block discarded – undo
295 308
    */
296 309
   function connect($server = null, $username = null, $secret = null): bool {
297 310
     // use config if not specified
298
-    if (is_null($server)) $server = $this->config['asmanager']['server'];
299
-    if (is_null($username)) $username = $this->config['asmanager']['username'];
300
-    if (is_null($secret)) $secret = $this->config['asmanager']['secret'];
311
+    if (is_null($server)) {
312
+      $server = $this->config['asmanager']['server'];
313
+    }
314
+    if (is_null($username)) {
315
+      $username = $this->config['asmanager']['username'];
316
+    }
317
+    if (is_null($secret)) {
318
+      $secret = $this->config['asmanager']['secret'];
319
+    }
301 320
 
302 321
     // get port from server if specified
303 322
     if (strpos($server, ':') !== false) {
@@ -344,8 +363,9 @@  discard block
 block discarded – undo
344 363
    * @example examples/sip_show_peer.php Get information about a sip peer
345 364
    */
346 365
   function disconnect() {
347
-    if ($this->_logged_in)
348
-      $this->logoff();
366
+    if ($this->_logged_in) {
367
+          $this->logoff();
368
+    }
349 369
     fclose($this->socket);
350 370
   }
351 371
 
@@ -396,7 +416,9 @@  discard block
 block discarded – undo
396 416
    */
397 417
   function Command(string $command, $actionid = null): array {
398 418
     $parameters = ['Command' => $command];
399
-    if ($actionid) $parameters['ActionID'] = $actionid;
419
+    if ($actionid) {
420
+      $parameters['ActionID'] = $actionid;
421
+    }
400 422
     return $this->send_request('Command', $parameters);
401 423
   }
402 424
 
@@ -433,8 +455,9 @@  discard block
 block discarded – undo
433 455
   function DBGet(string $family, string $key, $actionid = null): string {
434 456
     $parameters = ['Family' => $family,
435 457
                    'Key' => $key];
436
-    if ($actionid == null)
437
-      $actionid = $this->ActionID();
458
+    if ($actionid == null) {
459
+          $actionid = $this->ActionID();
460
+    }
438 461
     $parameters['ActionID'] = $actionid;
439 462
     $response = $this->send_request("DBGet", $parameters);
440 463
     if ($response['Response'] == "Success") {
@@ -457,7 +480,9 @@  discard block
 block discarded – undo
457 480
   function ExtensionState(string $exten, string $context, $actionid = null): array {
458 481
     $parameters = ['Exten' => $exten,
459 482
                    'Context' => $context];
460
-    if ($actionid) $parameters['ActionID'] = $actionid;
483
+    if ($actionid) {
484
+      $parameters['ActionID'] = $actionid;
485
+    }
461 486
     return $this->send_request('ExtensionState', $parameters);
462 487
   }
463 488
 
@@ -475,7 +500,9 @@  discard block
 block discarded – undo
475 500
   function GetVar(string $channel, string $variable, $actionid = null): array {
476 501
     $parameters = ['Channel' => $channel,
477 502
                    'Variable' => $variable];
478
-    if ($actionid) $parameters['ActionID'] = $actionid;
503
+    if ($actionid) {
504
+      $parameters['ActionID'] = $actionid;
505
+    }
479 506
     return $this->send_request('GetVar', $parameters);
480 507
   }
481 508
 
@@ -540,7 +567,9 @@  discard block
 block discarded – undo
540 567
    */
541 568
   function MailboxCount(string $mailbox, $actionid = null): array {
542 569
     $parameters = ['Mailbox' => $mailbox];
543
-    if ($actionid) $parameters['ActionID'] = $actionid;
570
+    if ($actionid) {
571
+      $parameters['ActionID'] = $actionid;
572
+    }
544 573
     return $this->send_request('MailboxCount', $parameters);
545 574
   }
546 575
 
@@ -560,7 +589,9 @@  discard block
 block discarded – undo
560 589
    */
561 590
   function MailboxStatus(string $mailbox, $actionid = null): array {
562 591
     $parameters = ['Mailbox' => $mailbox];
563
-    if ($actionid) $parameters['ActionID'] = $actionid;
592
+    if ($actionid) {
593
+      $parameters['ActionID'] = $actionid;
594
+    }
564 595
     return $this->send_request('MailboxStatus', $parameters);
565 596
   }
566 597
 
@@ -577,9 +608,15 @@  discard block
 block discarded – undo
577 608
    */
578 609
   function Monitor(string $channel, $file = null, $format = null, $mix = null): array {
579 610
     $parameters = ['Channel' => $channel];
580
-    if ($file) $parameters['File'] = $file;
581
-    if ($format) $parameters['Format'] = $format;
582
-    if (!is_null($file)) $parameters['Mix'] = ($mix) ? 'true' : 'false';
611
+    if ($file) {
612
+      $parameters['File'] = $file;
613
+    }
614
+    if ($format) {
615
+      $parameters['Format'] = $format;
616
+    }
617
+    if (!is_null($file)) {
618
+      $parameters['Mix'] = ($mix) ? 'true' : 'false';
619
+    }
583 620
     return $this->send_request('Monitor', $parameters);
584 621
   }
585 622
 
@@ -608,19 +645,41 @@  discard block
 block discarded – undo
608 645
                      $timeout = null, $callerid = null, $variable = null, $account = null, $async = null, $actionid = null): array {
609 646
     $parameters = ['Channel' => $channel];
610 647
 
611
-    if ($exten) $parameters['Exten'] = $exten;
612
-    if ($context) $parameters['Context'] = $context;
613
-    if ($priority) $parameters['Priority'] = $priority;
648
+    if ($exten) {
649
+      $parameters['Exten'] = $exten;
650
+    }
651
+    if ($context) {
652
+      $parameters['Context'] = $context;
653
+    }
654
+    if ($priority) {
655
+      $parameters['Priority'] = $priority;
656
+    }
614 657
 
615
-    if ($application) $parameters['Application'] = $application;
616
-    if ($data) $parameters['Data'] = $data;
658
+    if ($application) {
659
+      $parameters['Application'] = $application;
660
+    }
661
+    if ($data) {
662
+      $parameters['Data'] = $data;
663
+    }
617 664
 
618
-    if ($timeout) $parameters['Timeout'] = $timeout;
619
-    if ($callerid) $parameters['CallerID'] = $callerid;
620
-    if ($variable) $parameters['Variable'] = $variable;
621
-    if ($account) $parameters['Account'] = $account;
622
-    if (!is_null($async)) $parameters['Async'] = ($async) ? 'true' : 'false';
623
-    if ($actionid) $parameters['ActionID'] = $actionid;
665
+    if ($timeout) {
666
+      $parameters['Timeout'] = $timeout;
667
+    }
668
+    if ($callerid) {
669
+      $parameters['CallerID'] = $callerid;
670
+    }
671
+    if ($variable) {
672
+      $parameters['Variable'] = $variable;
673
+    }
674
+    if ($account) {
675
+      $parameters['Account'] = $account;
676
+    }
677
+    if (!is_null($async)) {
678
+      $parameters['Async'] = ($async) ? 'true' : 'false';
679
+    }
680
+    if ($actionid) {
681
+      $parameters['ActionID'] = $actionid;
682
+    }
624 683
 
625 684
     return $this->send_request('Originate', $parameters);
626 685
   }
@@ -661,8 +720,12 @@  discard block
 block discarded – undo
661 720
   function QueueAdd(string $queue, string $interface, int $penalty = 0, $memberName = false): array {
662 721
     $parameters = ['Queue' => $queue,
663 722
                    'Interface' => $interface];
664
-    if ($penalty) $parameters['Penalty'] = $penalty;
665
-    if ($memberName) $parameters["MemberName"] = $memberName;
723
+    if ($penalty) {
724
+      $parameters['Penalty'] = $penalty;
725
+    }
726
+    if ($memberName) {
727
+      $parameters["MemberName"] = $memberName;
728
+    }
666 729
     return $this->send_request('QueueAdd', $parameters);
667 730
   }
668 731
 
@@ -758,7 +821,9 @@  discard block
 block discarded – undo
758 821
   function SetCDRUserField(string $userfield, string $channel, $append = null): array {
759 822
     $parameters = ['UserField' => $userfield,
760 823
                    'Channel' => $channel];
761
-    if ($append) $parameters['Append'] = $append;
824
+    if ($append) {
825
+      $parameters['Append'] = $append;
826
+    }
762 827
     return $this->send_request('SetCDRUserField', $parameters);
763 828
   }
764 829
 
@@ -789,7 +854,9 @@  discard block
 block discarded – undo
789 854
    */
790 855
   function Status(string $channel, $actionid = null): array {
791 856
     $parameters = ['Channel' => $channel];
792
-    if ($actionid) $parameters['ActionID'] = $actionid;
857
+    if ($actionid) {
858
+      $parameters['ActionID'] = $actionid;
859
+    }
793 860
     return $this->send_request('Status', $parameters);
794 861
   }
795 862
 
@@ -890,10 +957,11 @@  discard block
 block discarded – undo
890 957
    * @param integer $level from 1 to 4
891 958
    */
892 959
   function log(string $message, int $level = 1) {
893
-    if ($this->pagi != false)
894
-      $this->pagi->conlog($message, $level);
895
-    elseif ($this->config['asmanager']['write_log'])
896
-      error_log(date('r') . ' - ' . $message);
960
+    if ($this->pagi != false) {
961
+          $this->pagi->conlog($message, $level);
962
+    } elseif ($this->config['asmanager']['write_log']) {
963
+          error_log(date('r') . ' - ' . $message);
964
+    }
897 965
   }
898 966
 
899 967
   /**
@@ -976,16 +1044,20 @@  discard block
 block discarded – undo
976 1044
     $this->log("Got event.. $e");
977 1045
 
978 1046
     $handler = '';
979
-    if (isset($this->event_handlers[$e])) $handler = $this->event_handlers[$e];
980
-    elseif (isset($this->event_handlers['*'])) $handler = $this->event_handlers['*'];
1047
+    if (isset($this->event_handlers[$e])) {
1048
+      $handler = $this->event_handlers[$e];
1049
+    } elseif (isset($this->event_handlers['*'])) {
1050
+      $handler = $this->event_handlers['*'];
1051
+    }
981 1052
 
982 1053
     if (function_exists($handler)) {
983 1054
       $this->log("Execute handler $handler");
984 1055
       $ret = $handler($e, $parameters, $this->server, $this->port);
985 1056
     } elseif (is_array($handler)) {
986 1057
       $ret = call_user_func($handler, $e, $parameters, $this->server, $this->port);
987
-    } else
988
-      $this->log("No event handler for event '$e'");
1058
+    } else {
1059
+          $this->log("No event handler for event '$e'");
1060
+    }
989 1061
     return $ret;
990 1062
   }
991 1063
 }
Please login to merge, or discard this patch.