Completed
Push — master ( afa4f8...42f6c3 )
by Peter
22:39
created

QueryBuilder   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 85.71%

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 4
c 4
b 1
f 0
lcom 1
cbo 2
dl 0
loc 55
ccs 12
cts 14
cp 0.8571
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A range() 0 4 1
A search() 0 16 1
A hasHits() 0 5 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;
10
11
use Maslosoft\Addendum\Interfaces\AnnotatedInterface;
12
use Maslosoft\Mangan\Helpers\CollectionNamer;
13
14
/**
15
 * QueryBuilder
16
 *
17
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
18
 */
19
class QueryBuilder
20
{
21
22
	/**
23
	 * Manganel instance
24
	 * @var Manganel
25
	 */
26
	private $manganel = null;
27
28
	/**
29
	 * Annotated model
30
	 * @var AnnotatedInterface
31
	 */
32
	private $model;
33
34 1
	public function __construct($model)
35
	{
36 1
		$this->model = $model;
37 1
		$this->manganel = Manganel::create($this->model);
38 1
	}
39
40
	public function range($field, $start, $end = null)
0 ignored issues
show
Unused Code introduced by
The parameter $field is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $start is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $end is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
41
	{
42
		return $this;
43
	}
44
45 1
	public function search($q = null)
46
	{
47
		$params = [
48 1
			'index' => strtolower($this->manganel->index),
49 1
			'type' => CollectionNamer::nameCollection($this->model),
50
			'body' => [
51
				'query' => [
52
					'query_string' => [
53
						'query' => $q
54 1
					]
55 1
				]
56 1
			]
57 1
		];
58
59 1
		return $this->manganel->getClient()->search($params);
60
	}
61
62
	/**
63
	 * TODO Return true if search has hits
64
	 * @return boolean
65
	 * @throws Exception
66
	 */
67
	public function hasHits()
68
	{
69
		throw new Exception('Not implemented');
70
		return true;
0 ignored issues
show
Unused Code introduced by
return true; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
71
	}
72
73
}
74