Completed
Push — master ( 575823...f7fea2 )
by Stefano
02:38
created
Core/JarvisBehaviourLanguage.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -17,6 +17,9 @@
 block discarded – undo
17 17
 		}
18 18
 	}
19 19
 
20
+	/**
21
+	 * @param string $sentence
22
+	 */
20 23
 	public function answer($sentence) {
21 24
 		foreach(JarvisBehaviourLanguage::$jbl_set->rules as $rule) {
22 25
 			foreach($rule->matches as $match) {
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -12,15 +12,15 @@
 block discarded – undo
12 12
 	public static $jbl_set = array();
13 13
 
14 14
 	public function loadBehaviourLanguage() {
15
-		if(file_exists('language/jbl_'._LANGUAGE.'.jbl')) {
15
+		if (file_exists('language/jbl_'._LANGUAGE.'.jbl')) {
16 16
 			JarvisBehaviourLanguage::$jbl_set = json_decode(file_get_contents('language/jbl_'._LANGUAGE.'.jbl'));
17 17
 		}
18 18
 	}
19 19
 
20 20
 	public function answer($sentence) {
21
-		foreach(JarvisBehaviourLanguage::$jbl_set->rules as $rule) {
22
-			foreach($rule->matches as $match) {
23
-				if(preg_match($match, $sentence)) {
21
+		foreach (JarvisBehaviourLanguage::$jbl_set->rules as $rule) {
22
+			foreach ($rule->matches as $match) {
23
+				if (preg_match($match, $sentence)) {
24 24
 					return $rule->responses[array_rand($rule->responses)];
25 25
 				}
26 26
 			}
Please login to merge, or discard this patch.
Plugins/Gcalendar_plugin/Gcalendar_plugin.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
     /**
84 84
      * Is it the right plugin for the command?
85 85
      * @param string $command
86
-     * @return boolean
86
+     * @return integer
87 87
      */
88 88
     function isLikely($command) {
89 89
         return preg_match(JarvisLanguage::translate('preg_match_activate_plugin',get_called_class()), $command);
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 
100 100
     /**
101 101
      * Returns an authorized API client.
102
-     * @return Google_Client the authorized client object
102
+     * @return null|\Google_Client the authorized client object
103 103
      */
104 104
     function getClient() {
105 105
       $client = new \Google_Client();
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
  * @author Stefano Bianchini
21 21
  * @website http://www.stefanobianchini.net
22 22
  */
23
-class Gcalendar_plugin implements \JarvisPHP\Core\JarvisPluginInterface{
23
+class Gcalendar_plugin implements \JarvisPHP\Core\JarvisPluginInterface {
24 24
     /**
25 25
      * Priority of plugin
26 26
      * @var int  
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
         // Get the API client and construct the service object.
40 40
         $client = Gcalendar_plugin::getClient();
41 41
         
42
-        if($client==null) return null;
42
+        if ($client == null) return null;
43 43
 
44 44
         $service = new \Google_Service_Calendar($client);
45 45
 
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
         $results = $service->events->listEvents($calendarId, $optParams);
55 55
 
56 56
         if (count($results->getItems()) == 0) {
57
-          $answer = JarvisLanguage::translate('no_appointments',get_called_class());
57
+          $answer = JarvisLanguage::translate('no_appointments', get_called_class());
58 58
         } else {
59 59
           
60 60
           foreach ($results->getItems() as $event) {
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
             }
65 65
 
66 66
             $date = new \DateTime($start);
67
-            $answer.= sprintf(JarvisLanguage::translate('list_events',get_called_class()), $date->format('j'), JarvisLanguage::translate('month_'.$date->format('n'),get_called_class()), $date->format('H'), $date->format('i'), $event->getSummary())."\n";
67
+            $answer .= sprintf(JarvisLanguage::translate('list_events', get_called_class()), $date->format('j'), JarvisLanguage::translate('month_'.$date->format('n'), get_called_class()), $date->format('H'), $date->format('i'), $event->getSummary())."\n";
68 68
           }
69 69
         }
70 70
 
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
      * @return boolean
87 87
      */
88 88
     function isLikely($command) {
89
-        return preg_match(JarvisLanguage::translate('preg_match_activate_plugin',get_called_class()), $command);
89
+        return preg_match(JarvisLanguage::translate('preg_match_activate_plugin', get_called_class()), $command);
90 90
     }
91 91
     
92 92
     /**
Please login to merge, or discard this patch.
Plugins/Wemo_plugin/Wemo_plugin.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -86,7 +86,7 @@
 block discarded – undo
86 86
     /**
87 87
      * Is it the right plugin for the command?
88 88
      * @param string $command
89
-     * @return boolean
89
+     * @return integer
90 90
      */
91 91
     function isLikely($command) {
92 92
         return preg_match(JarvisLanguage::translate('preg_match_activate_plugin',get_called_class()), $command);
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
  * @author Stefano Bianchini
13 13
  * @website http://www.stefanobianchini.net
14 14
  */
15
-class Wemo_plugin implements \JarvisPHP\Core\JarvisPluginInterface{
15
+class Wemo_plugin implements \JarvisPHP\Core\JarvisPluginInterface {
16 16
     /**
17 17
      * Priority of plugin
18 18
      * @var int  
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
         $_IFTTT_MAKER_EVENT = '';
32 32
 
33 33
         //Load API key from json config
34
-        if(file_exists('Plugins/Wemo_plugin/api-key.json')) {
34
+        if (file_exists('Plugins/Wemo_plugin/api-key.json')) {
35 35
             //Create your own api key and put it in api-key.json
36 36
             $json_config = json_decode(file_get_contents('Plugins/Wemo_plugin/api-key.json'));
37 37
             $_IFTTT_MAKER_KEY = $json_config->ifttt_key;
@@ -60,12 +60,12 @@  discard block
 block discarded – undo
60 60
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
61 61
         $result = curl_exec($ch);
62 62
         
63
-        if(!$result) {
63
+        if (!$result) {
64 64
             JarvisPHP::getLogger()->error('Curl error: '.curl_error($ch));
65
-            $answer = JarvisLanguage::translate('command_not_sent',get_called_class());  
65
+            $answer = JarvisLanguage::translate('command_not_sent', get_called_class());  
66 66
         }
67 67
         else {
68
-            $answer = JarvisLanguage::translate('command_sent_to_light_switch',get_called_class());    
68
+            $answer = JarvisLanguage::translate('command_sent_to_light_switch', get_called_class());    
69 69
         }
70 70
         
71 71
         curl_close($ch);
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
      * @return boolean
90 90
      */
91 91
     function isLikely($command) {
92
-        return preg_match(JarvisLanguage::translate('preg_match_activate_plugin',get_called_class()), $command);
92
+        return preg_match(JarvisLanguage::translate('preg_match_activate_plugin', get_called_class()), $command);
93 93
     }
94 94
     
95 95
     /**
Please login to merge, or discard this patch.
TelegramBot/GenericCurl.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -8,6 +8,9 @@
 block discarded – undo
8 8
  */
9 9
 class GenericCurl {
10 10
 
11
+	/**
12
+	 * @param string $url
13
+	 */
11 14
 	static function exec($url, $fields) {
12 15
 
13 16
 
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -13,8 +13,8 @@  discard block
 block discarded – undo
13 13
 
14 14
 		$fields_string = "";
15 15
 		//url-ify the data for the POST
16
-		if(count($fields)>0) {
17
-			foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
16
+		if (count($fields) > 0) {
17
+			foreach ($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
18 18
 			rtrim($fields_string, '&');
19 19
 		} 
20 20
 		
@@ -23,11 +23,11 @@  discard block
 block discarded – undo
23 23
 		$ch = curl_init();
24 24
 
25 25
 		//set the url, number of POST vars, POST data
26
-		curl_setopt($ch,CURLOPT_URL, $url);
27
-		curl_setopt($ch,CURLOPT_POST, count($fields));
28
-		curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
26
+		curl_setopt($ch, CURLOPT_URL, $url);
27
+		curl_setopt($ch, CURLOPT_POST, count($fields));
28
+		curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
29 29
 		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
30
-		curl_setopt ($ch, CURLOPT_COOKIEFILE, "TelegramBot/JarvisPHPSession.cookie");
30
+		curl_setopt($ch, CURLOPT_COOKIEFILE, "TelegramBot/JarvisPHPSession.cookie");
31 31
 		curl_setopt($ch, CURLOPT_COOKIEJAR, "TelegramBot/JarvisPHPSession.cookie"); 
32 32
 
33 33
 		//execute post
@@ -40,6 +40,6 @@  discard block
 block discarded – undo
40 40
 
41 41
 
42 42
 
43
-		return ($http_response_code==200) ? json_decode($result) : false;
43
+		return ($http_response_code == 200) ? json_decode($result) : false;
44 44
 	}
45 45
 }
46 46
\ No newline at end of file
Please login to merge, or discard this patch.
TelegramBot/TelegramBot.php 2 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -9,6 +9,9 @@  discard block
 block discarded – undo
9 9
  */
10 10
 class TelegramBotApiWrapper {
11 11
 
12
+	/**
13
+	 * @param resource $handle
14
+	 */
12 15
 	function exec_curl_request($handle) {
13 16
 	  $response = curl_exec($handle);
14 17
 
@@ -45,6 +48,9 @@  discard block
 block discarded – undo
45 48
 	  return $response;
46 49
 	}
47 50
 
51
+	/**
52
+	 * @param string $method
53
+	 */
48 54
 	function apiRequestJson($method, $parameters) {
49 55
 	  if (!is_string($method)) {
50 56
 	    echo("Method name must be a string\n");
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@
 block discarded – undo
62 62
 
63 63
 	  $_BOT_TOKEN = '';
64 64
 	  //Load API key from json config
65
-      if(file_exists('TelegramBot/api-key.json')) {
65
+      if (file_exists('TelegramBot/api-key.json')) {
66 66
           //Create your own bot token and put it in api-key.json
67 67
           // like {"bot_token": "<your-bot-token>"}
68 68
           $json_config = json_decode(file_get_contents('TelegramBot/api-key.json'));
Please login to merge, or discard this patch.
TelegramBot/JarvisPHPTelegramBot.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
 use JarvisPHP\TelegramBot\GenericCurl;
6 6
 
7 7
 //Very important!
8
-define('_JARVISPHP_URL','http://localhost:8000');
8
+define('_JARVISPHP_URL', 'http://localhost:8000');
9 9
 
10 10
 /**
11 11
  * A TelegramBot for JarvisPHP
@@ -23,14 +23,14 @@  discard block
 block discarded – undo
23 23
 		echo "JarvisPHP Telegram Bot started at ".date('Y-m-d H:i:s')."\n";
24 24
 		echo "-----------------------------------------------------\n";
25 25
 
26
-		while(true) {
26
+		while (true) {
27 27
 
28 28
 			$updates = $bot->apiRequestJson("getUpdates", array('offset'=>$offset));
29 29
 			
30
-			if($updates) {
31
-				foreach($updates as $update) {
30
+			if ($updates) {
31
+				foreach ($updates as $update) {
32 32
 
33
-					if(isset($update->message->text)) {
33
+					if (isset($update->message->text)) {
34 34
 
35 35
 						//TODO check if $update->message->chat->id is in enabled list
36 36
 
@@ -40,28 +40,28 @@  discard block
 block discarded – undo
40 40
 
41 41
 						$message = $update->message->text;
42 42
 
43
-						$offset = $update->update_id + 1;
43
+						$offset = $update->update_id+1;
44 44
 
45 45
 						$response = '';
46 46
 
47 47
 						//Understand if the message is a telegram command (begins with "/")
48
-						if(preg_match('$^/(.+)$', $message)) {
48
+						if (preg_match('$^/(.+)$', $message)) {
49 49
 							
50 50
 							//Telegram command
51
-							switch($message) {
52
-								case '/start': $response='I am JarvisPHP, a private bot. \u1F510'; break;
53
-								case '/info': $response='I am JarvisPHP, a private bot. \u1F510'; break;
51
+							switch ($message) {
52
+								case '/start': $response = 'I am JarvisPHP, a private bot. \u1F510'; break;
53
+								case '/info': $response = 'I am JarvisPHP, a private bot. \u1F510'; break;
54 54
 								case '/register': 
55
-												$response='Ok, i registered your ID in registerIdLog.log'; 
56
-												file_put_contents('TelegramBot/registerIdLog.log', '['.date('Y-m-d H:i:s').'] ID:'.$update->message->from->id . '; FIRSTNAME:'. $update->message->from->first_name . '; LASTNAME:'. $update->message->from->last_name. '; USERNAME:'. $update->message->from->username.PHP_EOL , FILE_APPEND | LOCK_EX);
55
+												$response = 'Ok, i registered your ID in registerIdLog.log'; 
56
+												file_put_contents('TelegramBot/registerIdLog.log', '['.date('Y-m-d H:i:s').'] ID:'.$update->message->from->id.'; FIRSTNAME:'.$update->message->from->first_name.'; LASTNAME:'.$update->message->from->last_name.'; USERNAME:'.$update->message->from->username.PHP_EOL, FILE_APPEND | LOCK_EX);
57 57
 												break;	
58
-								case '/say': $response='Use /say "sentence" (without quotes) to make JarvisPHP speak a sentence.'; break;	
58
+								case '/say': $response = 'Use /say "sentence" (without quotes) to make JarvisPHP speak a sentence.'; break;	
59 59
 							}
60 60
 
61 61
 							//"Say" Telegram command
62
-							if(preg_match('$^/say (.+)$', $message, $matches)) {
63
-								if($matches) {
64
-									if(in_array($update->message->chat->id, $allowedClientIdList)) {
62
+							if (preg_match('$^/say (.+)$', $message, $matches)) {
63
+								if ($matches) {
64
+									if (in_array($update->message->chat->id, $allowedClientIdList)) {
65 65
 										//Redirect message to JarvisPhp
66 66
 										$JarvisResponse = GenericCurl::exec(_JARVISPHP_URL.'/answer', array('sentence'=>$matches[0]));
67 67
 
@@ -73,12 +73,12 @@  discard block
 block discarded – undo
73 73
 							}
74 74
 
75 75
 							//Encode emoji
76
-							$response = preg_replace_callback('/\\\\u([0-9a-fA-F]+)/', function ($match) {
76
+							$response = preg_replace_callback('/\\\\u([0-9a-fA-F]+)/', function($match) {
77 77
 							    return iconv('UCS-4LE', 'UTF-8', pack('V', hexdec($match[1])));
78 78
 							}, $response);
79 79
 
80 80
 						} else {
81
-							if(in_array($update->message->chat->id, $allowedClientIdList)) {
81
+							if (in_array($update->message->chat->id, $allowedClientIdList)) {
82 82
 								//Redirect message to JarvisPhp
83 83
 								$JarvisResponse = GenericCurl::exec(_JARVISPHP_URL.'/answer', array('command'=>$message, 'tts' => 'None_tts'));
84 84
 
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 							}
89 89
 
90 90
 						}
91
-						if($response) {
91
+						if ($response) {
92 92
 							$bot->apiRequestJson("sendMessage", array('chat_id' => $update->message->chat->id, "text" => $response));
93 93
 						}
94 94
 					}
Please login to merge, or discard this patch.
config/Espeak_config.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -5,10 +5,10 @@
 block discarded – undo
5 5
  * m1, m2, ... m8 male voices
6 6
  * f1, f2, f3, f4 female voices
7 7
  */
8
-define('_ESPEAK_VOICE','m2');
8
+define('_ESPEAK_VOICE', 'm2');
9 9
 
10 10
 //Language of text-to-speech
11 11
 define('_ESPEAK_LANGUAGE', _LANGUAGE);
12 12
 
13 13
 //Amplitude (espeak -a <amplitude>)
14
-define('_ESPEAK_AMPLITUDE','100');
15 14
\ No newline at end of file
15
+define('_ESPEAK_AMPLITUDE', '100');
16 16
\ No newline at end of file
Please login to merge, or discard this patch.
config/Jarvis.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  */
5 5
 
6 6
 //Set locale
7
-define('_LANGUAGE','en');
7
+define('_LANGUAGE', 'en');
8 8
 
9 9
 //Command session timeout, in seconds
10 10
 define('_COMMAND_SESSION_TIMEOUT', 30);
@@ -13,4 +13,4 @@  discard block
 block discarded – undo
13 13
 define('_JARVIS_TTS', 'None_tts');
14 14
 
15 15
 //Define system's name
16
-define('_SYSTEM_NAME','JarvisPhp');
17 16
\ No newline at end of file
17
+define('_SYSTEM_NAME', 'JarvisPhp');
18 18
\ No newline at end of file
Please login to merge, or discard this patch.
Plugins/Info_plugin/Info_plugin.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
  * @author Stefano Bianchini
13 13
  * @website http://www.stefanobianchini.net
14 14
  */
15
-class Info_plugin implements \JarvisPHP\Core\JarvisPluginInterface{
15
+class Info_plugin implements \JarvisPHP\Core\JarvisPluginInterface {
16 16
     /**
17 17
      * Priority of plugin
18 18
      * @var int  
@@ -25,15 +25,15 @@  discard block
 block discarded – undo
25 25
      */
26 26
     function answer($command) {
27 27
         $answer = '';
28
-        if(preg_match(JarvisLanguage::translate('preg_match_tell_more',get_called_class()), $command)) {
28
+        if (preg_match(JarvisLanguage::translate('preg_match_tell_more', get_called_class()), $command)) {
29 29
             //Testing session
30 30
             JarvisPHP::getLogger()->debug('User says: '.$command);
31
-            $answer = 'Ok, i am on '. php_uname();
31
+            $answer = 'Ok, i am on '.php_uname();
32 32
             JarvisSession::terminate();
33 33
         }
34 34
         else {
35 35
             JarvisPHP::getLogger()->debug('Answering to command: "'.$command.'"');
36
-            $answer = sprintf(JarvisLanguage::translate('my_name_is',get_called_class()),_SYSTEM_NAME, $_SERVER['SERVER_NAME'],$_SERVER['SERVER_ADDR']);
36
+            $answer = sprintf(JarvisLanguage::translate('my_name_is', get_called_class()), _SYSTEM_NAME, $_SERVER['SERVER_NAME'], $_SERVER['SERVER_ADDR']);
37 37
             
38 38
         }
39 39
         JarvisTTS::speak($answer);
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
      * @return boolean
55 55
      */
56 56
     function isLikely($command) {
57
-        return preg_match(JarvisLanguage::translate('preg_match_activate_plugin',get_called_class()), $command);
57
+        return preg_match(JarvisLanguage::translate('preg_match_activate_plugin', get_called_class()), $command);
58 58
     }
59 59
     
60 60
     /**
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -86,7 +86,7 @@
 block discarded – undo
86 86
     /**
87 87
      * Is it the right plugin for the command?
88 88
      * @param string $command
89
-     * @return boolean
89
+     * @return integer
90 90
      */
91 91
     function isLikely($command) {
92 92
         return preg_match(JarvisLanguage::translate('preg_match_activate_plugin',get_called_class()), $command);
Please login to merge, or discard this patch.