Completed
Push — master ( f92c24...681df7 )
by Adam
02:52
created

Delete   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A delete() 0 14 3
1
<?php
2
3
namespace BestServedCold\LaravelZendSearch\Lucene\Store;
4
5
use BestServedCold\LaravelZendSearch\Lucene\Index;
6
use BestServedCold\LaravelZendSearch\Lucene\Search;
7
8
/**
9
 * Class Delete
10
 *
11
 * @package BestServedCold\LaravelZendSearch\Lucene\Store
12
 */
13
class Delete
14
{
15
    /**
16
     * @var Search
17
     */
18
    private $search;
19
20
    /**
21
     * @var
22
     */
23
    private $index;
24
25
    /**
26
     * Delete constructor.
27
     *
28
     * @param Search $search
29
     * @param Index  $index
30
     */
31 4
    public function __construct(Search $search, Index $index)
32
    {
33 4
        $this->search = $search;
34 4
        $this->search->path(config('search.index.path'));
35 4
        $this->index  = $index;
36 4
    }
37
38
    /**
39
     * Delete
40
     *
41
     * @param  $id
42
     * @param  bool $uid
43
     * @return $this
44
     */
45 1
    public function delete($id, $uid = false)
46
    {
47 1
        $this->search->where($id, 'xref_id');
48
49 1
        if ($uid) {
50 1
            $this->search->where($uid, 'uid');
51 1
        }
52
53 1
        foreach ($this->search->hits() as $hit) {
54 1
            $this->index->get()->delete($hit);
55 1
        }
56
57 1
        return $this;
58
    }
59
}
60