JarvisBehaviourLanguage   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
c 2
b 0
f 0
lcom 1
cbo 0
dl 0
loc 22
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A loadBehaviourLanguage() 0 5 2
A answer() 0 10 4
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
}