Completed
Push — master ( 4a9289...6c8c8c )
by Peter
08:35
created

SearchDecorator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 33
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A decorate() 0 21 2
A getKind() 0 4 1
1
<?php
2
3
/*
4
 * To change this license header, choose License Headers in Project Properties.
5
 * To change this template file, choose Tools | Templates
6
 * and open the template in the editor.
7
 */
8
9
namespace Maslosoft\Manganel\Decorators\QueryBuilder;
10
11
use Maslosoft\Manganel\Interfaces\QueryBuilder\ConditionDecoratorInterface;
12
use Maslosoft\Manganel\SearchCriteria;
13
14
/**
15
 * SearchDecorator
16
 *
17
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
18
 */
19
class SearchDecorator implements ConditionDecoratorInterface
20
{
21
22
	const Ns = __NAMESPACE__;
23
24 10
	public function decorate(&$conditions, SearchCriteria $criteria)
25
	{
26 10
		$q = $criteria->getSearch();
27
28 10
		if (empty($q))
29 10
		{
30
			// Match all documents if query is null
31 3
			$conditions[] = [
32 3
				'match_all' => []
33 3
			];
34 3
		}
35
		else
36
		{
37
			// Use query string matching
38 7
			$conditions[] = [
39
				'simple_query_string' => [
40
					'query' => $q
41 7
				]
42 7
			];
43
		}
44 10
	}
45
46 10
	public function getKind()
47
	{
48 10
		return self::KindMust;
49
	}
50
51
}
52