Completed
Push — master ( 751bb4...735cac )
by Jean-Christophe
04:44
created

SearchCategory   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 12
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 61
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A addResult() 0 4 1
A addResults() 0 4 1
A __toString() 0 4 1
A getId() 0 3 1
A setId() 0 4 1
A getName() 0 3 1
A setName() 0 4 1
A getResults() 0 3 1
A setResults() 0 4 1
A search() 0 7 2
1
<?php
2
3
namespace Ajax\semantic\components\search;
4
5
class SearchCategory {
6
	private $id;
7
	private $name;
8
	private $results;
9
10
	public function __construct($id, $name, $results=NULL) {
11
		$this->results=new SearchResults($results);
12
		$this->id=$id;
13
		$this->name=$name;
14
	}
15
16
	public function addResult($object) {
17
		$this->results->addResult($object);
18
		return $this;
19
	}
20
21
	public function addResults($objects) {
22
		$this->results->addResults($objects);
23
		return $this;
24
	}
25
26
	public function __toString() {
27
		$result="\"" . $this->id . "\": { \"name\": \"" . $this->name . "\"," . $this->results . "}";
28
		return $result;
29
	}
30
31
	public function getId() {
32
		return $this->id;
33
	}
34
35
	public function setId($id) {
36
		$this->id=$id;
37
		return $this;
38
	}
39
40
	public function getName() {
41
		return $this->name;
42
	}
43
44
	public function setName($name) {
45
		$this->name=$name;
46
		return $this;
47
	}
48
49
	public function getResults() {
50
		return $this->results;
51
	}
52
53
	public function setResults($results) {
54
		$this->results=$results;
55
		return $this;
56
	}
57
58
	public function search($query, $field="title") {
59
		$result=$this->results->search($query, $field);
60
		if ($result !== false) {
61
			return new SearchCategory($this->id, $this->name, $result);
62
		}
63
		return false;
64
	}
65
}