Completed
Push — master ( 1b53d6...5badca )
by GBProd
02:44
created

DataProvider::count()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace GBProd\ElasticsearchDataProviderBundle\DataProvider;
4
5
use Elasticsearch\Client;
6
use GBProd\ElasticsearchDataProviderBundle\Event\HasIndexedDocument;
7
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
8
9
/**
10
 * Abstract class for data providing
11
 *
12
 * @author gbprod <[email protected]>
13
 */
14
abstract class DataProvider implements DataProviderInterface
15
{
16
    /**
17
     * @var Client
18
     */
19
    private $client;
20
21
    /**
22
     * @var string
23
     */
24
    private $index;
25
26
    /**
27
     * @var string
28
     */
29
    private $type;
30
    
31
    /**
32
     * @var EventDispatcherInterface
33
     */
34
    private $dispatcher;
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 2
    public function run(
40
        Client $client, 
41
        $index, 
42
        $type, 
43
        EventDispatcherInterface $dispatcher
44
    ) {
45 2
        $this->client     = $client;
46 2
        $this->index      = $index;
47 2
        $this->type       = $type;
48 2
        $this->dispatcher = $dispatcher;
49
        
50 2
        $this->populate();
51 2
    }
52
53
    /**
54
     * Populate
55
     *
56
     * @return null
57
     */
58
    abstract protected function populate();
59
60
    /**
61
     * Index document
62
     *
63
     * @param string $id
64
     * @param array  $body
65
     */
66 1
    public function index($id, array $body)
67
    {
68 1
        $this->client->index([
69 1
            'index' => $this->index,
70 1
            'type'  => $this->type,
71 1
            'id'    => $id,
72 1
            'body'  => $body,
73 1
        ]);
74
        
75 1
        $this->dispatcher->dispatch(
76 1
            'elasticsearch.has_indexed_document',
77 1
            new HasIndexedDocument($id)
78 1
        );
79 1
    }
80
    
81
    /**
82
     * {@inheritdoc}
83
     */
84
    public function count()
85
    {
86
        return null;
87
    }
88
}    
89