Passed
Branch master (8cb5b2)
by Christopher
04:37
created

InnerHit::parentInnerHit()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 3
dl 0
loc 13
ccs 8
cts 8
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Triadev\Leopard\Business\Dsl\Query;
3
4
use ONGR\ElasticsearchDSL\InnerHit\NestedInnerHit;
5
use ONGR\ElasticsearchDSL\InnerHit\ParentInnerHit;
6
use Triadev\Leopard\Business\Dsl\Search;
7
use Triadev\Leopard\Business\Dsl\AbstractQuery;
8
9
class InnerHit extends AbstractQuery
10
{
11
    /**
12
     * Nested inner hit
13
     *
14
     * @param string $name
15
     * @param string $path
16
     * @param \Closure|null $search
17
     * @return InnerHit
18
     */
19 2
    public function nestedInnerHit(string $name, string $path, ?\Closure $search = null) : InnerHit
20
    {
21 2
        $searchForNested = null;
22
        
23 2
        if ($search) {
24 2
            $searchBuilder = app()->make(Search::class);
25 2
            $search($searchBuilder);
26
            
27 2
            $searchForNested = $searchBuilder->getSearch();
28
        }
29
        
30 2
        $this->search->addInnerHit(new NestedInnerHit($name, $path, $searchForNested));
31 2
        return $this;
32
    }
33
    
34
    /**
35
     * Parent inner hits
36
     *
37
     * @param string $name
38
     * @param string $path
39
     * @param \Closure|null $search
40
     * @return InnerHit
41
     */
42 1
    public function parentInnerHit(string $name, string $path, ?\Closure $search = null) : InnerHit
43
    {
44 1
        $searchForNested = null;
45
        
46 1
        if ($search) {
47 1
            $searchBuilder = app()->make(Search::class);
48 1
            $search($searchBuilder);
49
            
50 1
            $searchForNested = $searchBuilder->getSearch();
51
        }
52
        
53 1
        $this->search->addInnerHit(new ParentInnerHit($name, $path, $searchForNested));
54 1
        return $this;
55
    }
56
}
57