JarvisBehaviourLanguage::answer()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.2
cc 4
eloc 6
nc 4
nop 1
1
<?php
2
namespace JarvisPHP\Core;
3
4
/**
5
 * JarvisAil
6
 *
7
 * @author Stefano Bianchini
8
 * @website http://www.stefanobianchini.net
9
 */
10
class JarvisBehaviourLanguage {
11
12
	public static $jbl_set = array();
13
14
	public function loadBehaviourLanguage() {
15
		if(file_exists('language/jbl_'._LANGUAGE.'.jbl')) {
16
			JarvisBehaviourLanguage::$jbl_set = json_decode(file_get_contents('language/jbl_'._LANGUAGE.'.jbl'));
0 ignored issues
show
Documentation Bug introduced by
It seems like json_decode(file_get_con... . _LANGUAGE . '.jbl')) of type * is incompatible with the declared type array of property $jbl_set.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
17
		}
18
	}
19
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)) {
24
					return $rule->responses[array_rand($rule->responses)];
25
				}
26
			}
27
		}
28
		return false;
29
	}
30
31
}