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

SearchCategories   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A add() 0 6 1
A search() 0 10 3
A __toString() 0 3 1
1
<?php
2
3
namespace Ajax\semantic\components\search;
4
5
class SearchCategories {
6
	private $categories;
7
8
	public function __construct() {
9
		$this->categories=array ();
10
	}
11
12
	public function add($results, $category) {
13
		$count=\sizeof($this->categories);
14
		$category=new SearchCategory("category" . $count, $category, $results);
15
		$this->categories[]=$category;
16
		return $this;
17
	}
18
19
	public function search($query, $field="title") {
20
		$result=array ();
21
		foreach ( $this->categories as $category ) {
22
			$r=$category->search($query, $field);
23
			if ($r !== false)
24
				$result[]=$r;
25
		}
26
		$this->categories=$result;
27
		return $this;
28
	}
29
30
	public function __toString() {
31
		return "{\"results\":{" . \implode(",", $this->categories) . "}}";
32
	}
33
}