Conditions | 11 |
Paths | 12 |
Total Lines | 69 |
Code Lines | 46 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
102 | public static function elaborateCommand($command, $forcedTTS) { |
||
103 | |||
104 | JarvisPHP::$TTS_name = $forcedTTS; |
||
105 | |||
106 | //Jarvis tries to understand if the magic words that stop the session were pronounced |
||
107 | if(preg_match(JarvisLanguage::translate('preg_match_magic_words_to_stop_session'),$command)) { |
||
108 | JarvisSession::terminate(); |
||
109 | } |
||
110 | |||
111 | //Verify if there is an active plugin and the command session timeout |
||
112 | if(JarvisSession::sessionInProgress() && (time() < (JarvisSession::get('last_command_timestamp')+_COMMAND_SESSION_TIMEOUT))) { |
||
113 | JarvisPHP::getLogger()->debug('Detected active session: '.JarvisSession::getActivePlugin() . ' - last command '.JarvisSession::get('last_command_timestamp').', now is '.time()); |
||
114 | $plugin_class = JarvisSession::getActivePlugin(); |
||
115 | //Load plugin's languages |
||
116 | JarvisLanguage::loadPluginTranslation($plugin_class); |
||
117 | $plugin = new $plugin_class(); |
||
118 | $plugin->answer($command); |
||
119 | } |
||
120 | else { |
||
121 | //Clear all session variable |
||
122 | JarvisSession::reset(); |
||
123 | JarvisPHP::getLogger()->debug('Active session not detected or expired'); |
||
124 | $max_priority_found=-9999; |
||
125 | $choosen_plugin = null; |
||
126 | //Cycling plugins |
||
127 | foreach(JarvisPHP::$active_plugins as $plugin_class) { |
||
128 | $plugin = new $plugin_class(); |
||
129 | //Load plugin's languages |
||
130 | JarvisLanguage::loadPluginTranslation($plugin_class); |
||
131 | if($plugin->isLikely($command)) { |
||
132 | JarvisPHP::getLogger()->debug('Maybe '.JarvisPHP::getRealClassName($plugin_class).', check priority'); |
||
133 | if($plugin->getPriority() > $max_priority_found) { |
||
134 | $max_priority_found = $plugin->getPriority(); |
||
135 | $choosen_plugin = $plugin; |
||
136 | } |
||
137 | } |
||
138 | } |
||
139 | if(!is_null($choosen_plugin)) { |
||
140 | JarvisPHP::getLogger()->debug('Choosen plugin: '.JarvisPHP::getRealClassName(get_class($choosen_plugin))); |
||
141 | if($choosen_plugin->hasSession()) { |
||
142 | JarvisSession::setActivePlugin(get_class($choosen_plugin)); |
||
143 | } |
||
144 | $choosen_plugin->answer($command); |
||
145 | } else { |
||
146 | if(preg_match(JarvisLanguage::translate('preg_match_magic_words_to_stop_session'),$command)) { |
||
147 | JarvisTTS::speak(JarvisLanguage::translate('response_to_magic_words_to_stop_session')); |
||
148 | $response = new \JarvisPHP\Core\JarvisResponse(JarvisLanguage::translate('response_to_magic_words_to_stop_session')); |
||
149 | $response->send(); |
||
150 | } |
||
151 | else { |
||
152 | JarvisBehaviourLanguage::loadBehaviourLanguage(); |
||
153 | $answer = JarvisBehaviourLanguage::answer($command); |
||
154 | if($answer) { |
||
155 | $response = new \JarvisPHP\Core\JarvisResponse($answer, 'none', true); |
||
156 | JarvisTTS::speak($answer); |
||
157 | } else { |
||
158 | JarvisPHP::getLogger()->debug('No plugin found for command: '.$command); |
||
159 | JarvisTTS::speak(JarvisLanguage::translate('core_command_not_understand')); |
||
160 | //Log the command |
||
161 | file_put_contents('notUnderstandCommands.log', '['.date('Y-m-d H:i:s').'] Command:'.$command. PHP_EOL , FILE_APPEND | LOCK_EX); |
||
162 | $response = new \JarvisPHP\Core\JarvisResponse(JarvisLanguage::translate('core_command_not_understand')); |
||
163 | } |
||
164 | $response->send(); |
||
165 | } |
||
166 | } |
||
167 | } |
||
168 | //Update last command timestamp |
||
169 | JarvisSession::set('last_command_timestamp', time()); |
||
170 | } |
||
171 | |||
202 | } //JarvisPHP |
This check marks private properties in classes that are never used. Those properties can be removed.